Skip to content

Authing/wechat-eco-solution

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Authing x 微信解决方案

License

了解微信生态解决方案

运行项目

yarn
yarn start
查看项目运行截图

接入示例

接入 PC 扫码登录

什么是 PC 扫码登录

你需要用到 authing-js-sdk,详细接入配置请见:接入微信 PC 扫码登录

代码示例:

import { AuthenticationClient } from "authing-js-sdk";

const authing = new AuthenticationClient({
  userPoolId: "YOUR_USERPOOL_ID",
});
authing.social.authorize('wechat:pc', {
  popup: false,
  onSuccess: (user) => {
    console.log(user)
  },
  onError: (code, message) => {
    console.error(code, message)
  }
})

接入微信网页授权登录

什么是微信网页授权登录

你需要用到 authing-js-sdk,详细接入配置请见:接入微信网页授权登录

代码示例:

import { AuthenticationClient } from "authing-js-sdk";

const authing = new AuthenticationClient({
  userPoolId: "YOUR_USERPOOL_ID",
});
authing.social.authorize('wechat:webpage-authorization', {
  popup: false,
  onSuccess: (user) => {
    console.log(user)
  },
  onError: (code, message) => {
    console.error(code, message)
  }
})

接入移动端拉起微信登录

什么是移动端拉起微信登录

你需要用到 authing-swift-sdk,详细接入配置请见:接入移动端拉起微信登录

代码示例:

import SwiftyAuthing
let userPoolId = "YOUR_USERPOOL_ID"
self.client = AuthenticationClient(userPoolId: userPoolId)

func loginByWeChatCode() {
    //通过微信SDK返回的认证码登陆 https://docs.authing.cn/social-login/mobile/wechat.html
    let code = "xxxxxxx"
    self.client?.loginByWeChatCode(code: code, completion: { status in
        print(status)
    })
}

接入小程序登录

什么是小程序登录

你需要用到 authing-wxapp-sdk,详细接入配置请见:接入移动端拉起微信登录

代码示例:

  1. 使用 code 登录,无需用户授权
const { AuthenticationClient } = require("authing-wxapp-sdk")
const { code } = await wx.login()
const data = await authing.loginByCode(code)
  1. 用户首次手动授权昵称头像
// index.wxml
<button open-type="getUserInfo" bindgetuserinfo="getUserInfo"> 获取头像昵称 </button>

// index.js
const { AuthenticationClient } = require("authing-wxapp-sdk")

// 使用 code 登录,无需用户授权
const { code } = await wx.login()
const { iv, encryptedData } = e.detail
const user = await authing.loginByCode(code, { iv, encryptedData })         
  1. 使用用户授权的手机号登录
// index.wxml
<button open-type="getPhoneNumber" bindgetphonenumber="getPhone"> 获取手机号 </button>

// index.js
const { AuthenticationClient } = require("authing-wxapp-sdk")

const { code } = await wx.login()
const { iv, encryptedData } = e.detail
const user = await authing.loginByPhone(code, iv, encryptedData)

接入小程序扫码登录

什么是小程序扫码登录

你需要用到 authing-js-sdk,详细接入配置请见:接入小程序扫码登录

代码示例:

import { AuthenticationClient } from "authing-js-sdk";

const authing = new AuthenticationClient({
  userPoolId: "YOUR_USERPOOL_ID",
});
const onScanningSuccess = async (userInfo: any, ticket: string) => {
  const { token } = userInfo;
  if (!token) {
    userInfo = await authing.wxqrcode.exchangeUserInfo(ticket);
  }
  console.log(userInfo)
};

authing.wxqrcode.startScanning("qrcode", {
  onSuccess: onScanningSuccess,
  onError: (message) => {
    alert(message)
  }
});

移动端拉起小程序登录

什么是移动到拉起小程序登录

你需要用到 authing-swift-sdk,详细接入配置请见:移动到拉起小程序登录

代码示例:

import SwiftyAuthing
let userPoolId = "YOUR_USERPOOL_ID"
self.client = AuthenticationClient(userPoolId: userPoolId)

func loginByWeChatMiniprogram() {
    self.client?.loginByWeChatMiniprogram(completion: { status in
        print(status)
    })
}

常见问题

如果需要在线技术支持,可访问官方论坛. 此仓库的 issue 仅用于上报 Bug 和提交新功能特性。

开源共建

  • Fork 此仓库
  • 创建自己的 git 分支 (git checkout -b my-new-feature)
  • 提交你的修改 (git commit -am 'Add some feature')
  • 将修改内容推送到远程分支 (git push -u origin my-new-feature)
  • 创建一个 Pull Request

贡献

https://github.com/Authing/.github/blob/main/CONTRIBUTING.md

开源许可

MIT

Copyright (c) 2019-present, Authing

Releases

No releases published

Packages

No packages published