Skip to content

Commit 775e3d3

Browse files
Merge pull request #205 from Authing/feat/wechat-sdk
Feat/wechat sdk
2 parents b926b08 + 7ca678e commit 775e3d3

File tree

33 files changed

+9495
-23764
lines changed

33 files changed

+9495
-23764
lines changed

examples/miniapp-taro/package-lock.json

Lines changed: 6691 additions & 7208 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/miniapp-taro/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@
3737
"dependencies": {
3838
"@authing/miniapp-jsencrypt": "^5.1.0",
3939
"@authing/miniapp-sm2encrypt": "^5.1.0",
40-
"@authing/miniapp-taro": "^5.1.4-alpha.3",
41-
"@authing/miniapp-wx": "^5.0.4-alpha.2",
40+
"@authing/miniapp-taro": "^5.1.5-alpha.2",
41+
"@authing/miniapp-wx": "^5.1.5-alpha.2",
4242
"@babel/runtime": "^7.7.7",
4343
"@tarojs/components": "3.5.4",
4444
"@tarojs/helper": "3.5.4",

examples/miniapp-taro/project.config.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,5 @@
1111
"postcss": false,
1212
"minified": false
1313
},
14-
"compileType": "miniapp"
14+
"compileType": "miniprogram"
1515
}

examples/miniapp-taro/src/pages/index/index.tsx

Lines changed: 143 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,22 +33,35 @@ export default class Index extends Component<PropsWithChildren> {
3333
return (
3434
<View className='index'>
3535
<Button onClick={() => this.loginByCode()}>loginByCode</Button>
36-
<Button openType="getPhoneNumber" onGetPhoneNumber={(e) => this.loginByPhone(e)}>loginByPhone</Button>
36+
<Button openType='getPhoneNumber' onGetPhoneNumber={(e) => this.loginByPhone(e)}>loginByPhone</Button>
3737
<Button onClick={() => this.loginByPassword()}>loginByPassword</Button>
3838

3939
<View>发送手机短信验证码</View>
4040
<Button onClick={() => this.sendSms()}>sendSms</Button>
41+
<Button onClick={() => this.bindPhone()}>bindPhone</Button>
4142
<View>使用手机短信验证码登录</View>
4243
<Button onClick={() => this.loginByPassCode()}>loginByPassCode</Button>
4344

44-
<Button openType="getPhoneNumber" onGetPhoneNumber={(e) => this.getPhone(e)}>getPhone</Button>
45+
<View>发送邮箱验证码</View>
46+
<Button onClick={() => this.sendEmailCode()}>sendEmailCode</Button>
47+
<Button onClick={() => this.bindEmail()}>bindEmail</Button>
48+
<Button onClick={() => this.updateEmail()}>updateEmail</Button>
49+
50+
51+
<Button openType='getPhoneNumber' onGetPhoneNumber={(e) => this.getPhone(e)}>getPhone</Button>
4552
<Button onClick={() => this.refreshToken()}>refreshToken</Button>
4653
<Button onClick={() => this.updatePassword()}>updatePassword</Button>
4754
<Button onClick={() => this.getUserInfo()}>getUserInfo</Button>
4855
<Button onClick={() => this.updateAvatar()}>updateAvatar</Button>
4956
<Button onClick={() => this.updateUserInfo()}>updateUserInfo</Button>
5057

5158
<Button onClick={() => this.getLoginState()}>getLoginState</Button>
59+
<Button onClick={() => this.deleteAccount()}>deleteAccount</Button>
60+
61+
62+
<Button onClick={() => this.decryptData()}>decryptData</Button>
63+
<Button onClick={() => this.getAccessToken()}>getAccessToken</Button>
64+
5265
</View>
5366
)
5467
}
@@ -66,7 +79,7 @@ export default class Index extends Component<PropsWithChildren> {
6679

6780
/**
6881
* 需要在真机上测试,微信开发者工具不会返回 code
69-
* @param {*} e
82+
* @param {*} e
7083
*/
7184
async loginByPhone (e) {
7285
const { code } = e.detail
@@ -86,7 +99,7 @@ export default class Index extends Component<PropsWithChildren> {
8699

87100
/**
88101
* 需要在真机上测试,微信开发者工具不会返回 code
89-
* @param {*} e
102+
* @param {*} e
90103
*/
91104
async getPhone (e) {
92105
const { code } = e.detail
@@ -175,5 +188,130 @@ export default class Index extends Component<PropsWithChildren> {
175188
const res = await authing.getLoginState()
176189

177190
console.log('authing.getLoginState res: ', res)
178-
}
191+
}
192+
193+
async sendEmailCode () {
194+
const res = await authing.sendEmailCode({
195+
email: 'YOUR_EMAIL_ADDRESS',
196+
channel: 'CHANNEL_LOGIN'
197+
})
198+
199+
console.log('authing.sendEmailCode res: ', res)
200+
}
201+
202+
async bindEmail () {
203+
const res = await authing.bindEmail({
204+
email: 'YOUR_EMAIL_ADDRESS',
205+
passCode: ''
206+
})
207+
console.log('authing.bindEmail res: ', res)
208+
}
209+
210+
// 用于修改邮箱发送短信验证码
211+
async verifyOldEmail() {
212+
const res = await authing.sendEmailCode({
213+
email: 'YOUR_OLD_EMAIL_ADDRESS',
214+
channel: 'CHANNEL_UPDATE_EMAIL'
215+
})
216+
console.log('authing.sendEmailCode res: ', res)
217+
}
218+
219+
async verifyNewEmail() {
220+
const res = await authing.sendEmailCode({
221+
email: 'YOUR_NEW_EMAIL_ADDRESS',
222+
channel: 'CHANNEL_UPDATE_EMAIL'
223+
})
224+
console.log('authing.sendEmailCode res: ', res)
225+
}
226+
227+
async updateEmail () {
228+
// 前置调用 verifyOldEmail verifyNewEmail 获取新旧邮箱验证码
229+
// this.verifyOldEmail()
230+
// this.verifyNewEmail()
231+
const [_, res] = await authing.updateEmailRequest({
232+
verifyMethod: 'EMAIL_PASSCODE',
233+
emailPassCodePayload: {
234+
newEmail: 'YOUR_EMAIL_ADDRESS',
235+
newEmailPassCode: '',
236+
oldEmail: 'YOUR_EMAIL_ADDRESS',
237+
oldEmailPassCode: ''
238+
}
239+
})
240+
241+
console.log('authing.updateEmailRequest res: ', res)
242+
243+
const updateRes = await authing.updateEmail({
244+
updateEmailToken: res.updateEmailToken
245+
})
246+
console.log('authing.updateEmail res: ', updateRes)
247+
}
248+
249+
async bindPhone () {
250+
// 前置调用 sendSms 方法,channel: CHANNEL_BIND_PHONE
251+
const res = await authing.bindPhone({
252+
phoneNumber: 'YOUR_PHONE_NUMBER',
253+
passCode: '',
254+
})
255+
console.log('authing.bindPhone res: ', res)
256+
}
257+
258+
// TODO 修改手机号 channel
259+
async updatePhone () {
260+
const [_, res] = await authing.updatePhoneRequest({
261+
verifyMethod:'PHONE_PASSCODE',
262+
phonePassCodePayload: {
263+
newPhoneNumber: 'YOUR_PHONE_NUMBER',
264+
newPhonePassCode: ''
265+
}
266+
})
267+
console.log('authing.updatePhone res: ', res)
268+
269+
if (res?.updatePhoneToken) {
270+
await authing.updatePhone({
271+
updatePhoneToken: res.updatePhoneToken
272+
})
273+
}
274+
275+
}
276+
277+
async deleteAccount () {
278+
/**
279+
* 邮箱 EMAIL_PASSCODE: 前置调用发送邮件方法 channel: CHANNEL_DELETE_ACCOUNT
280+
* 手机号 PHONE_PASSCODE: 前置调用发送短信方法 channel: CHANNEL_DELETE_ACCOUNT
281+
* 密码 PASSWORD: 传入 password 参数
282+
*/
283+
const [_, res] = await authing.deleteAccountRequest({
284+
verifyMethod: 'EMAIL_PASSCODE',
285+
emailPassCodePayload: {
286+
email: 'YOUR_EMAIL_ADDRESS',
287+
passCode: ''
288+
}
289+
})
290+
console.log('authing.deleteAccount res: ', res)
291+
292+
await authing.deleteAccount({
293+
deleteAccountToken: res.deleteAccountToken
294+
})
295+
296+
}
297+
298+
async decryptData () {
299+
const res = await authing.decryptData({
300+
extIdpConnidentifier: 'EXT_IDP_CONNIDENTIFIER',
301+
encryptedData: '',
302+
iv: '',
303+
code: ''
304+
})
305+
306+
console.log('authing.decryptData res: ', res)
307+
}
308+
309+
async getAccessToken () {
310+
const res = await authing.getAccessToken({
311+
appId: 'WX_APP_ID',
312+
appSecret: 'WX_APP_SECRET'
313+
})
314+
315+
console.log('authing.getAccessToken res: ', res)
316+
}
179317
}

examples/miniapp-uniapp/jsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"compilerOptions": {
33
"types": [
44
"@dcloudio/types",
5-
"miniapp-api-typings",
5+
"miniprogram-api-typings",
66
"mini-types"
77
]
88
}

0 commit comments

Comments
 (0)