一键登录,增加云函数
This commit is contained in:
37
uniCloud-aliyun/cloudfunctions/gl-key-login/index.js
Normal file
37
uniCloud-aliyun/cloudfunctions/gl-key-login/index.js
Normal file
@@ -0,0 +1,37 @@
|
||||
|
||||
'use strict';
|
||||
|
||||
const crypto = require('crypto')
|
||||
|
||||
exports.main = async (event) => {
|
||||
const secret = 'glDao2022.'
|
||||
const hmac = crypto.createHmac('sha256', secret);
|
||||
|
||||
let params = event.queryStringParameters
|
||||
const sign = params.sign
|
||||
delete params.sign
|
||||
|
||||
const signStr = Object.keys(params).sort().map(key => {
|
||||
return `${key}=${params[key]}`
|
||||
}).join('&')
|
||||
|
||||
hmac.update(signStr);
|
||||
|
||||
if (sign !== hmac.digest('hex')) {
|
||||
throw new Error('非法访问')
|
||||
}
|
||||
|
||||
const {
|
||||
access_token,
|
||||
openid
|
||||
} = params
|
||||
|
||||
return await uniCloud.getPhoneNumber({
|
||||
appid: '__UNI__DE7B0E6',
|
||||
provider: 'univerify',
|
||||
apiKey: '16fa20236696596869759d3a81541901',
|
||||
apiSecret: 'fca97287360c2e8f8259d8877a601887',
|
||||
access_token: access_token,
|
||||
openid: openid,
|
||||
})
|
||||
};
|
||||
Reference in New Issue
Block a user