20261008
This commit is contained in:
@@ -0,0 +1,55 @@
|
||||
module.exports = {
|
||||
/**
|
||||
* QQ授权登录
|
||||
* @url user/pub/loginByQQ 前端调用的url参数地址
|
||||
* data 请求参数 说明
|
||||
* @param {String} code QQ小程序登录返回的code
|
||||
* @param {String} accessToken QQ APP登录返回的access_token
|
||||
* @param {String} type login:登录 register:注册
|
||||
* res 返回参数说明
|
||||
* @param {Number} code 错误码,0表示成功
|
||||
* @param {String} msg 详细信息
|
||||
* @param {String} token 登录成功之后返回的token信息
|
||||
* @param {String} tokenExpired token过期时间
|
||||
*/
|
||||
main: async (event) => {
|
||||
let { data = {}, util, originalParam } = event;
|
||||
let { uniID, config, pubFun, vk, db, _ } = util;
|
||||
let { uid, accountType, code } = data;
|
||||
let res = {};
|
||||
// 业务逻辑开始-----------------------------------------------------------
|
||||
let custom = {
|
||||
accountType: parseInt(accountType),
|
||||
nickname: `QQ用户` + vk.pubfn.random(6)
|
||||
};
|
||||
|
||||
// res = await uniID.loginByQQ({
|
||||
// code,
|
||||
// accessToken,
|
||||
// type,
|
||||
// myInviteCode,
|
||||
// needPermission
|
||||
// });
|
||||
const redirect_uri = 'http://static-mp-0737e52b-fffa-4223-bcdf-d4ad3d9968a5.next.bspapp.com/#/pages/auth/login/qq'
|
||||
const qqRes = await vk.request({
|
||||
url: `https://graph.qq.com/oauth2.0/token?grant_type=authorization_code&client_id=101795826&client_secret=1a41633966fb97cefea512f6c8601638&code=${code}&redirect_uri=` + encodeURIComponent(redirect_uri),
|
||||
method: 'GET',
|
||||
})
|
||||
if (qqRes.access_token) {
|
||||
const qqUserRes = await vk.request({
|
||||
url: `https://graph.qq.com/oauth2.0/me?access_token=${qqRes.access_token}`,
|
||||
method: 'GET',
|
||||
})
|
||||
if (qqUserRes.openid) {
|
||||
const userByQQOpenid = await vk.baseDao.findByWhereJson({
|
||||
dbName: "uni-id-users",
|
||||
whereJson: {
|
||||
"qq.openid": qqUserRes.openid
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
// 业务逻辑结束-----------------------------------------------------------
|
||||
return res;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user