npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

ciam-miniapp-sdk

v1.1.0

Published

##### 1. SDK实例化 - 代码示例 ``` javascript import { WXAppletClient } from 'ciam-miniapp-sdk'; const authSDK = new WXAppletClient({ clientId: 'your-cliendId', authSourceId: 'your-authSourceId', userDomain: 'your-userDomain', agreement

Downloads

6

Readme

使用SDK完成集成开发

1. SDK实例化
  • 代码示例
import { WXAppletClient }  from 'ciam-miniapp-sdk';
const authSDK = new WXAppletClient({
      clientId: 'your-cliendId',
      authSourceId: 'your-authSourceId',
      userDomain: 'your-userDomain',
	       agreements: [
        {
            "name": "用户协议|隐私协议|附加协议|...", // 必传
            "url": "https://qq.com", // 必传,最大长度1024
            "version": "1.0" // 必传,最大长度10
        },
        {
            "name": "用户协议|隐私协议|附加协议|...", // 必传
            "url": "https://baidu.com", // 必传,最大长度1024
            "version": "2.0.0" // 必传,最大长度10
        }
      ]
    });
  • 初始化参数说明

| 参数名 | 类型 | 是否必填 | 长度限制 |描述 | | ------ | ------ | ------ | ------ | ------ | | clientId | string | 是 | - |管理端添加的小程序应用ID | | authSourceId | string | 是| - |管理端添加的小程序认证源ID | | userDomain | string | 是| - | 租户域名(自定义域名获取) | | agreements | array[Agreement] | 否 | - |如协议流程开启则开发者需要上传协议签署

  • Agreement参数说明

| 参数名 | 类型 | 是否必填 | 长度限制 |描述 | | ------ | ------ | ------ | ------ | ------ | | name | string | 是| 100 | 协议名称,如用户协议、隐私协议、附加协议 | | url | string | 是| 1024 |协议链接地址 | | version | string | 是| 10 | 协议版本号 |

2. 静默授权登录loginCode
  • 代码示例
async bindLoginBySlience() {
    try {
      await authSDK.loginCode();
    }
    catch(err) {
      console.log('bindLoginBySlience error', err)
    }
    const userInfo = authSDK.getUser();
    if (userInfo) {
	      ...
	   }
  },
  • 参数说明 无

  • 返回值: 类型为Promise[User|null],User结构如下

首次登录时,静默授权只可获取wechatOpenid和wechatUnionId的值,其他信息需要在用户信息完善后获取。

{
   sub: "69bc2a4d-e575-41cf-bbc6-996e0911e2ec",
   username: "xxx",
   name: "xxx",
   gender: "female",
   phoneNumber: "+86-13612345678",
   email: "[email protected]",
   nickname: "xxxx",
   wechatUnionId: "xxxxx",
   wechatOpenid: "xxxxx"
}
3. 用户信息授权登录 loginUser

首次登录时,用户信息授权只可获取下面在官网api中提供的部分信息,其他信息需要在用户信息完善后获取。

注意该方法需要页面产生点击事件(例如button上bindtap的回调中)后才可调用 官方说明见:获取用户信息

  • 代码示例
async bindLoginByUserInfo() {
    try {
      await authSDK.loginUser();
    }
    catch(err) {
      console.log('bindLoginByUserInfo error', err)
    }
    const userInfo = authSDK.getUser();
    if (userInfo) {
      ...
    }
  },
  • 参数说明 无

  • 返回值: 类型为Promise[User|null],User结构如下

{
   sub: "69bc2a4d-e575-41cf-bbc6-996e0911e2ec",
   username: "xxx",
   name: "xxx",
   gender: "female",
   phoneNumber: "+86-13612345678",
   email: "[email protected]",
   nickname: "xxxx",
   wechatUnionId: "xxxxx",
   wechatOpenid: "xxxxx"
}
4. 用户手机号授权登录loginPhone

首次登录时,手机号授权只可获取下面在官网api中提供的部分信息,其他信息需要在用户信息完善后获取。

注意该方法需要页面产生点击事件(例如button上bindtap的回调中)后才可调用 注意该方法已更新为官方最新版本的获取手机号接口,开发时请检查开发者工具是否更新以及小程序基础库版本是否在2.21.2以上,暂不支持旧版本调用。官方说明见:获取手机号

  • 代码示例
async bindLoginByPhone(e) {
   
    const {code} = e.detail;

    if (!code) {
      console.error('未获取到code,请检查开发者工具是否更新以及小程序基础库版本是否在2.21.2以上');
      return;
    }
    try { 
      await authSDK.loginPhone(code);
    }
    catch(err) {
      console.log('bindLoginByPhone error', err)
    }

    const userInfo = authSDK.getUser();
   
    if (userInfo) {
      ...
    }
   
  },
  • 参数说明 无

  • 返回值

{
   sub: "69bc2a4d-e575-41cf-bbc6-996e0911e2ec",
   username: "xxx",
   name: "xxx",
   gender: "female",
   phoneNumber: "+86-13612345678",
   email: "[email protected]",
   nickname: "xxxx",
   wechatUnionId: "xxxxx",
   wechatOpenid: "xxxxx"
}
5. 获取登录状态 checkLoginState
  • 代码示例
const isLogin = authSDK.checkLoginState();
    if (!isLogin) {
      return;
    }
  • 参数说明 无

-返回值

true/false
6. 退出登录logout
  • 代码示例
await authSDK.logout();
  • 参数说明 无

  • 返回值: 类型为Boolean,结果如下

true/false