Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
DCloud
hello_uni-id-pages
提交
5fb0de72
H
hello_uni-id-pages
项目概览
DCloud
/
hello_uni-id-pages
通知
1040
Star
30
Fork
42
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
3
列表
看板
标记
里程碑
合并请求
1
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
H
hello_uni-id-pages
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
3
Issue
3
列表
看板
标记
里程碑
合并请求
1
合并请求
1
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
5fb0de72
编写于
7月 27, 2022
作者:
雪洛
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
feat: save user key with bridge
上级
40bfc7e0
变更
11
隐藏空白更改
内联
并排
Showing
11 changed file
with
242 addition
and
43 deletion
+242
-43
uni_modules/uni-id-pages/uniCloud/cloudfunctions/uni-id-co/index.obj.js
...i-id-pages/uniCloud/cloudfunctions/uni-id-co/index.obj.js
+4
-1
uni_modules/uni-id-pages/uniCloud/cloudfunctions/uni-id-co/lib/third-party/weixin/account/index.js
...nctions/uni-id-co/lib/third-party/weixin/account/index.js
+1
-1
uni_modules/uni-id-pages/uniCloud/cloudfunctions/uni-id-co/lib/utils/qq.js
...d-pages/uniCloud/cloudfunctions/uni-id-co/lib/utils/qq.js
+77
-13
uni_modules/uni-id-pages/uniCloud/cloudfunctions/uni-id-co/lib/utils/register.js
...s/uniCloud/cloudfunctions/uni-id-co/lib/utils/register.js
+2
-1
uni_modules/uni-id-pages/uniCloud/cloudfunctions/uni-id-co/lib/utils/relate.js
...ges/uniCloud/cloudfunctions/uni-id-co/lib/utils/relate.js
+2
-4
uni_modules/uni-id-pages/uniCloud/cloudfunctions/uni-id-co/lib/utils/weixin.js
...ges/uniCloud/cloudfunctions/uni-id-co/lib/utils/weixin.js
+80
-13
uni_modules/uni-id-pages/uniCloud/cloudfunctions/uni-id-co/module/login/login-by-qq.js
...loud/cloudfunctions/uni-id-co/module/login/login-by-qq.js
+17
-3
uni_modules/uni-id-pages/uniCloud/cloudfunctions/uni-id-co/module/login/login-by-weixin.js
.../cloudfunctions/uni-id-co/module/login/login-by-weixin.js
+17
-2
uni_modules/uni-id-pages/uniCloud/cloudfunctions/uni-id-co/module/relate/bind-qq.js
...niCloud/cloudfunctions/uni-id-co/module/relate/bind-qq.js
+21
-2
uni_modules/uni-id-pages/uniCloud/cloudfunctions/uni-id-co/module/relate/bind-weixin.js
...oud/cloudfunctions/uni-id-co/module/relate/bind-weixin.js
+16
-1
uni_modules/uni-id-pages/uniCloud/cloudfunctions/uni-id-co/module/utils/get-h5-weixin-config.js
...dfunctions/uni-id-co/module/utils/get-h5-weixin-config.js
+5
-2
未找到文件。
uni_modules/uni-id-pages/uniCloud/cloudfunctions/uni-id-co/index.obj.js
浏览文件 @
5fb0de72
...
...
@@ -12,6 +12,7 @@ const {
isUniIdError
}
=
require
(
'
./common/error
'
)
const
middleware
=
require
(
'
./middleware/index
'
)
const
uniOpenBridge
=
require
(
'
uni-open-bridge-common
'
)
const
{
registerAdmin
,
...
...
@@ -150,6 +151,7 @@ module.exports = {
// 挂载uni-captcha到this上,方便后续调用
this
.
uniCaptcha
=
uniCaptcha
this
.
uniOpenBridge
=
uniOpenBridge
// 挂载中间件
this
.
middleware
=
{}
...
...
@@ -305,7 +307,7 @@ module.exports = {
* @param {Object} params
* @param {String} params.code QQ小程序登录返回的code参数
* @param {String} params.accessToken App端QQ登录返回的accessToken参数
* @param {String} params.accessTokenExpired
由App端QQ登录返回的expires_in参数计算而来
* @param {String} params.accessTokenExpired
accessToken过期时间,由App端QQ登录返回的expires_in参数计算而来,单位:毫秒
* @param {String} params.inviteCode 邀请码
* @returns
*/
...
...
@@ -368,6 +370,7 @@ module.exports = {
* @param {Object} params
* @param {String} params.code 小程序端QQ登录返回的code
* @param {String} params.accessToken APP端QQ登录返回的accessToken
* @param {String} params.accessTokenExpired accessToken过期时间,由App端QQ登录返回的expires_in参数计算而来,单位:毫秒
* @returns
*/
bindQQ
,
...
...
uni_modules/uni-id-pages/uniCloud/cloudfunctions/uni-id-co/lib/third-party/weixin/account/index.js
浏览文件 @
5fb0de72
...
...
@@ -56,7 +56,7 @@ module.exports = class Auth {
}
})
if
(
result
.
expiresIn
)
{
result
.
expired
=
Date
.
now
()
+
result
.
expiresIn
result
.
expired
=
Date
.
now
()
+
result
.
expiresIn
*
1000
// delete result.expiresIn
}
return
result
...
...
uni_modules/uni-id-pages/uniCloud/cloudfunctions/uni-id-co/lib/utils/qq.js
浏览文件 @
5fb0de72
...
...
@@ -18,26 +18,56 @@ function getQQPlatform () {
}
}
function
generateQQCache
({
async
function
saveQQUserKey
({
openid
,
sessionKey
,
// QQ小程序用户sessionKey
accessToken
,
// App端QQ用户accessToken
accessTokenExpired
// App端QQ用户accessToken过期时间
}
=
{})
{
const
platform
=
getQQPlatform
.
call
(
this
)
// 微信公众平台、开放平台refreshToken有效期均为30天(微信没有在网络请求里面返回30天这个值,务必注意未来可能出现调整,需及时更新此处逻辑)。
// 此前QQ开放平台有调整过accessToken的过期时间:[access_token有效期由90天缩短至30天](https://wiki.connect.qq.com/%E3%80%90qq%E4%BA%92%E8%81%94%E3%80%91access_token%E6%9C%89%E6%95%88%E6%9C%9F%E8%B0%83%E6%95%B4)
const
appId
=
this
.
getClientInfo
().
appId
const
qqPlatform
=
getQQPlatform
.
call
(
this
)
const
keyObj
=
{
dcloudAppid
:
appId
,
openid
,
platform
:
qqPlatform
+
'
-weixin
'
}
switch
(
qqPlatform
)
{
case
'
mp
'
:
await
this
.
uniOpenBridge
.
setUserKey
(
keyObj
,
{
session_key
:
sessionKey
})
break
case
'
app
'
:
case
'
h5
'
:
case
'
web
'
:
await
this
.
uniOpenBridge
.
setUserKey
(
keyObj
,
{
access_token
:
accessToken
,
access_token_expired
:
accessTokenExpired
},
Math
.
floor
((
accessTokenExpired
-
Date
.
now
())
/
1000
))
break
default
:
break
}
}
function
generateQQCache
({
sessionKey
,
// QQ小程序用户sessionKey
accessToken
,
// App端QQ用户accessToken
accessTokenExpired
// App端QQ用户accessToken过期时间
}
=
{})
{
const
platform
=
getQQPlatform
.
call
(
this
)
let
cache
switch
(
platform
)
{
case
'
app
'
:
cache
=
{
openid
,
access_token
:
accessToken
,
access_token_expired
:
accessTokenExpired
}
break
case
'
mp
'
:
cache
=
{
openid
,
session_key
:
sessionKey
}
break
...
...
@@ -46,19 +76,44 @@ function generateQQCache ({
}
return
{
third_party
:
{
[
`
${
appId
}
_
${
platform
}
_qq`
]:
cache
,
[
`
${
platform
}
_qq`
]:
cache
}
}
}
function
getQQOpenid
({
userRecord
}
=
{})
{
const
qqPlatform
=
getQQPlatform
.
call
(
this
)
const
appId
=
this
.
getClientInfo
().
appId
const
qqOpenidObj
=
userRecord
.
qq_openid
if
(
!
qqOpenidObj
)
{
return
}
return
qqOpenidObj
[
`
${
qqPlatform
}
_
${
appId
}
`
]
||
qqOpenidObj
[
qqPlatform
]
}
async
function
getQQCacheFallback
({
userRecord
,
key
}
=
{})
{
const
platform
=
getQQPlatform
.
call
(
this
)
const
thirdParty
=
userRecord
&&
userRecord
.
third_party
if
(
!
thirdParty
)
{
return
}
const
qqCache
=
thirdParty
[
`
${
platform
}
_qq`
]
return
qqCache
&&
qqCache
[
key
]
}
async
function
getQQCache
({
uid
,
userRecord
,
key
}
=
{})
{
const
p
latform
=
getQQPlatform
.
call
(
this
)
const
qqP
latform
=
getQQPlatform
.
call
(
this
)
const
appId
=
this
.
getClientInfo
().
appId
if
(
!
userRecord
)
{
const
getUserRes
=
await
userCollection
.
doc
(
uid
).
get
()
userRecord
=
getUserRes
.
data
[
0
]
...
...
@@ -68,17 +123,26 @@ async function getQQCache ({
errCode
:
ERROR
.
ACCOUNT_NOT_EXISTS
}
}
const
thirdParty
=
userRecord
&&
userRecord
.
third_party
if
(
!
thirdParty
)
{
return
const
openid
=
getQQOpenid
.
call
(
this
,
{
userRecord
})
const
userKey
=
await
this
.
uniOpenBridge
.
getUserKey
({
dcloudAppid
:
appId
,
platform
:
qqPlatform
+
'
-qq
'
,
openid
})
if
(
userKey
)
{
return
userKey
[
key
]
}
const
qqCacheOld
=
thirdParty
[
`
${
platform
}
_qq`
]
const
qqCache
=
thirdParty
[
`
${
appId
}
_
${
platform
}
_qq`
]
return
(
qqCache
&&
qqCache
[
key
])
||
(
qqCacheOld
&&
qqCacheOld
[
key
])
return
getQQCacheFallback
({
userRecord
,
key
})
}
module
.
exports
=
{
getQQPlatform
,
generateQQCache
,
getQQCache
getQQCache
,
saveQQUserKey
}
uni_modules/uni-id-pages/uniCloud/cloudfunctions/uni-id-co/lib/utils/register.js
浏览文件 @
5fb0de72
...
...
@@ -13,6 +13,7 @@ const {
generateInviteInfo
}
=
require
(
'
./fission
'
)
const
PasswordUtils
=
require
(
'
./password
'
)
const
merge
=
require
(
'
lodash.merge
'
)
async
function
realPreRegister
(
params
=
{})
{
const
{
...
...
@@ -93,7 +94,7 @@ async function postRegister (params = {}) {
osName
}
=
this
.
getClientInfo
()
Object
.
assign
(
user
,
extraData
)
merge
(
user
,
extraData
)
const
registerChannel
=
channel
||
scene
user
.
register_env
=
{
...
...
uni_modules/uni-id-pages/uniCloud/cloudfunctions/uni-id-co/lib/utils/relate.js
浏览文件 @
5fb0de72
...
...
@@ -7,6 +7,7 @@ const {
const
{
userCollection
}
=
require
(
'
../../common/constants
'
)
const
merge
=
require
(
'
lodash.merge
'
)
/**
*
...
...
@@ -43,10 +44,7 @@ async function postBind ({
bindAccount
,
logType
}
=
{})
{
await
userCollection
.
doc
(
uid
).
update
({
...
bindAccount
,
...
extraData
})
await
userCollection
.
doc
(
uid
).
update
(
merge
(
bindAccount
,
extraData
))
await
this
.
middleware
.
uniIdLog
({
data
:
{
user_id
:
uid
...
...
uni_modules/uni-id-pages/uniCloud/cloudfunctions/uni-id-co/lib/utils/weixin.js
浏览文件 @
5fb0de72
...
...
@@ -5,6 +5,7 @@ const {
const
{
ERROR
}
=
require
(
'
../../common/error
'
)
function
decryptWeixinData
({
encryptedData
,
sessionKey
,
...
...
@@ -47,22 +48,56 @@ function getWeixinPlatform () {
}
}
function
generateWeixinCache
({
async
function
saveWeixinUserKey
({
openid
,
sessionKey
,
// 微信小程序用户sessionKey
accessToken
,
// App端微信用户accessToken
refreshToken
,
// App端微信用户refreshToken
accessTokenExpired
// App端微信用户accessToken过期时间
}
=
{})
{
const
platform
=
getWeixinPlatform
.
call
(
this
)
// 微信公众平台、开放平台refreshToken有效期均为30天(微信没有在网络请求里面返回30天这个值,务必注意未来可能出现调整,需及时更新此处逻辑)。
// 此前QQ开放平台有调整过accessToken的过期时间:[access_token有效期由90天缩短至30天](https://wiki.connect.qq.com/%E3%80%90qq%E4%BA%92%E8%81%94%E3%80%91access_token%E6%9C%89%E6%95%88%E6%9C%9F%E8%B0%83%E6%95%B4)
const
appId
=
this
.
getClientInfo
().
appId
const
weixinPlatform
=
getWeixinPlatform
.
call
(
this
)
const
keyObj
=
{
dcloudAppid
:
appId
,
openid
,
platform
:
weixinPlatform
+
'
-weixin
'
}
switch
(
weixinPlatform
)
{
case
'
mp
'
:
await
this
.
uniOpenBridge
.
setUserKey
(
keyObj
,
{
session_key
:
sessionKey
})
break
case
'
app
'
:
case
'
h5
'
:
case
'
web
'
:
await
this
.
uniOpenBridge
.
setUserKey
(
keyObj
,
{
access_token
:
accessToken
,
refresh_token
:
refreshToken
,
access_token_expired
:
accessTokenExpired
},
30
*
24
*
3600
)
break
default
:
break
}
}
function
generateWeixinCache
({
sessionKey
,
// 微信小程序用户sessionKey
accessToken
,
// App端微信用户accessToken
refreshToken
,
// App端微信用户refreshToken
accessTokenExpired
// App端微信用户accessToken过期时间
}
=
{})
{
const
platform
=
getWeixinPlatform
.
call
(
this
)
let
cache
switch
(
platform
)
{
case
'
app
'
:
case
'
h5
'
:
case
'
web
'
:
cache
=
{
openid
,
access_token
:
accessToken
,
refresh_token
:
refreshToken
,
access_token_expired
:
accessTokenExpired
...
...
@@ -70,7 +105,6 @@ function generateWeixinCache ({
break
case
'
mp
'
:
cache
=
{
openid
,
session_key
:
sessionKey
}
break
...
...
@@ -79,18 +113,42 @@ function generateWeixinCache ({
}
return
{
third_party
:
{
[
`
${
appId
}
_
${
platform
}
_weixin`
]:
cache
,
[
`
${
platform
}
_weixin`
]:
cache
}
}
}
function
getWeixinOpenid
({
userRecord
}
=
{})
{
const
weixinPlatform
=
getWeixinPlatform
.
call
(
this
)
const
appId
=
this
.
getClientInfo
().
appId
const
wxOpenidObj
=
userRecord
.
wx_openid
if
(
!
wxOpenidObj
)
{
return
}
return
wxOpenidObj
[
`
${
weixinPlatform
}
_
${
appId
}
`
]
||
wxOpenidObj
[
weixinPlatform
]
}
async
function
getWeixinCacheFallback
({
userRecord
,
key
}
=
{})
{
const
platform
=
getWeixinPlatform
.
call
(
this
)
const
thirdParty
=
userRecord
&&
userRecord
.
third_party
if
(
!
thirdParty
)
{
return
}
const
weixinCache
=
thirdParty
[
`
${
platform
}
_weixin`
]
return
weixinCache
&&
weixinCache
[
key
]
}
async
function
getWeixinCache
({
uid
,
userRecord
,
key
}
=
{})
{
const
p
latform
=
getWeixinPlatform
.
call
(
this
)
const
weixinP
latform
=
getWeixinPlatform
.
call
(
this
)
const
appId
=
this
.
getClientInfo
().
appId
if
(
!
userRecord
)
{
const
getUserRes
=
await
userCollection
.
doc
(
uid
).
get
()
...
...
@@ -101,18 +159,27 @@ async function getWeixinCache ({
errCode
:
ERROR
.
ACCOUNT_NOT_EXISTS
}
}
const
thirdParty
=
userRecord
&&
userRecord
.
third_party
if
(
!
thirdParty
)
{
return
const
openid
=
getWeixinOpenid
.
call
(
this
,
{
userRecord
})
const
userKey
=
await
this
.
uniOpenBridge
.
getUserKey
({
dcloudAppid
:
appId
,
platform
:
weixinPlatform
+
'
-weixin
'
,
openid
})
if
(
userKey
)
{
return
userKey
[
key
]
}
const
weixinCacheOld
=
thirdParty
[
`
${
platform
}
_weixin`
]
const
weixinCache
=
thirdParty
[
`
${
appId
}
_
${
platform
}
_weixin`
]
return
(
weixinCache
&&
weixinCache
[
key
])
||
(
weixinCacheOld
&&
weixinCacheOld
[
key
])
return
getWeixinCacheFallback
({
userRecord
,
key
})
}
module
.
exports
=
{
decryptWeixinData
,
getWeixinPlatform
,
generateWeixinCache
,
getWeixinCache
getWeixinCache
,
saveWeixinUserKey
}
uni_modules/uni-id-pages/uniCloud/cloudfunctions/uni-id-co/module/login/login-by-qq.js
浏览文件 @
5fb0de72
...
...
@@ -13,7 +13,8 @@ const {
}
=
require
(
'
../../common/constants
'
)
const
{
getQQPlatform
,
generateQQCache
generateQQCache
,
saveQQUserKey
}
=
require
(
'
../../lib/utils/qq
'
)
const
url
=
require
(
'
url
'
)
...
...
@@ -23,7 +24,7 @@ const url = require('url')
* @param {Object} params
* @param {String} params.code QQ小程序登录返回的code参数
* @param {String} params.accessToken App端QQ登录返回的accessToken参数
* @param {String} params.accessTokenExpired
由App端QQ登录返回的expires_in参数计算而来
* @param {String} params.accessTokenExpired
accessToken过期时间,由App端QQ登录返回的expires_in参数计算而来,单位:毫秒
* @param {String} params.inviteCode 邀请码
* @returns
*/
...
...
@@ -53,6 +54,9 @@ module.exports = async function (params = {}) {
accessTokenExpired
,
inviteCode
}
=
params
const
{
appId
}
=
this
.
getClientInfo
()
const
qqApi
=
initQQ
.
call
(
this
)
const
qqPlatform
=
getQQPlatform
.
call
(
this
)
let
apiName
...
...
@@ -101,7 +105,11 @@ module.exports = async function (params = {}) {
qq_unionid
:
unionid
}
})
const
extraData
=
{}
const
extraData
=
{
qq_openid
:
{
[
`
${
qqPlatform
}
_
${
appId
}
`
]:
openid
}
}
if
(
type
===
'
register
'
&&
qqPlatform
!==
'
mp
'
)
{
const
{
nickname
,
...
...
@@ -132,6 +140,12 @@ module.exports = async function (params = {}) {
url
:
fileID
}
}
await
saveQQUserKey
.
call
(
this
,
{
openid
,
sessionKey
,
accessToken
,
accessTokenExpired
})
return
postUnifiedLogin
.
call
(
this
,
{
user
,
extraData
:
{
...
...
uni_modules/uni-id-pages/uniCloud/cloudfunctions/uni-id-co/module/login/login-by-weixin.js
浏览文件 @
5fb0de72
...
...
@@ -10,7 +10,8 @@ const {
}
=
require
(
'
../../lib/utils/unified-login
'
)
const
{
generateWeixinCache
,
getWeixinPlatform
getWeixinPlatform
,
saveWeixinUserKey
}
=
require
(
'
../../lib/utils/weixin
'
)
const
{
LOG_TYPE
...
...
@@ -38,6 +39,9 @@ module.exports = async function (params = {}) {
code
,
inviteCode
}
=
params
const
{
appId
}
=
this
.
getClientInfo
()
const
weixinApi
=
initWeixin
.
call
(
this
)
const
weixinPlatform
=
getWeixinPlatform
.
call
(
this
)
let
apiName
...
...
@@ -88,7 +92,11 @@ module.exports = async function (params = {}) {
wx_unionid
:
unionid
}
})
const
extraData
=
{
}
const
extraData
=
{
wx_openid
:
{
[
`
${
weixinPlatform
}
_
${
appId
}
`
]:
openid
}
}
if
(
type
===
'
register
'
&&
weixinPlatform
!==
'
mp
'
)
{
const
{
nickname
,
...
...
@@ -119,6 +127,13 @@ module.exports = async function (params = {}) {
url
:
fileID
}
}
await
saveWeixinUserKey
.
call
(
this
,
{
openid
,
sessionKey
,
accessToken
,
refreshToken
,
accessTokenExpired
})
return
postUnifiedLogin
.
call
(
this
,
{
user
,
extraData
:
{
...
...
uni_modules/uni-id-pages/uniCloud/cloudfunctions/uni-id-co/module/relate/bind-qq.js
浏览文件 @
5fb0de72
...
...
@@ -12,7 +12,9 @@ const {
initQQ
}
=
require
(
'
../../lib/third-party/index
'
)
const
{
generateQQCache
generateQQCache
,
getQQPlatform
,
saveQQUserKey
}
=
require
(
'
../../lib/utils/qq
'
)
/**
...
...
@@ -21,6 +23,7 @@ const {
* @param {Object} params
* @param {String} params.code 小程序端QQ登录返回的code
* @param {String} params.accessToken APP端QQ登录返回的accessToken
* @param {String} params.accessTokenExpired accessToken过期时间,由App端QQ登录返回的expires_in参数计算而来,单位:毫秒
* @returns
*/
module
.
exports
=
async
function
(
params
=
{})
{
...
...
@@ -32,14 +35,21 @@ module.exports = async function (params = {}) {
accessToken
:
{
type
:
'
string
'
,
required
:
false
},
accessTokenExpired
:
{
type
:
'
number
'
,
required
:
false
}
}
this
.
middleware
.
validate
(
params
,
schema
)
const
uid
=
this
.
authInfo
.
uid
const
{
code
,
accessToken
accessToken
,
accessTokenExpired
}
=
params
const
qqPlatform
=
getQQPlatform
.
call
(
this
)
const
appId
=
this
.
getClientInfo
().
appId
const
qqApi
=
initQQ
.
call
(
this
)
const
clientPlatform
=
this
.
clientPlatform
const
apiName
=
clientPlatform
===
'
mp-qq
'
?
'
code2Session
'
:
'
getOpenidByToken
'
...
...
@@ -77,10 +87,19 @@ module.exports = async function (params = {}) {
bindAccount
,
logType
:
LOG_TYPE
.
BIND_QQ
})
await
saveQQUserKey
.
call
(
this
,
{
openid
,
sessionKey
,
accessToken
,
accessTokenExpired
})
return
postBind
.
call
(
this
,
{
uid
,
bindAccount
,
extraData
:
{
qq_openid
:
{
[
`
${
qqPlatform
}
_
${
appId
}
`
]:
openid
},
...
generateQQCache
.
call
(
this
,
{
openid
,
sessionKey
...
...
uni_modules/uni-id-pages/uniCloud/cloudfunctions/uni-id-co/module/relate/bind-weixin.js
浏览文件 @
5fb0de72
...
...
@@ -6,7 +6,9 @@ const {
LOG_TYPE
}
=
require
(
'
../../common/constants
'
)
const
{
generateWeixinCache
generateWeixinCache
,
saveWeixinUserKey
,
getWeixinPlatform
}
=
require
(
'
../../lib/utils/weixin
'
)
const
{
initWeixin
...
...
@@ -31,6 +33,9 @@ module.exports = async function (params = {}) {
const
{
code
}
=
params
const
weixinPlatform
=
getWeixinPlatform
.
call
(
this
)
const
appId
=
this
.
getClientInfo
().
appId
const
weixinApi
=
initWeixin
.
call
(
this
)
const
clientPlatform
=
this
.
clientPlatform
const
apiName
=
clientPlatform
===
'
mp-weixin
'
?
'
code2Session
'
:
'
getOauthAccessToken
'
...
...
@@ -68,10 +73,20 @@ module.exports = async function (params = {}) {
bindAccount
,
logType
:
LOG_TYPE
.
BIND_WEIXIN
})
await
saveWeixinUserKey
.
call
(
this
,
{
openid
,
sessionKey
,
accessToken
,
refreshToken
,
accessTokenExpired
})
return
postBind
.
call
(
this
,
{
uid
,
bindAccount
,
extraData
:
{
wx_openid
:
{
[
`
${
weixinPlatform
}
_
${
appId
}
`
]:
openid
},
...
generateWeixinCache
.
call
(
this
,
{
openid
,
sessionKey
,
// 微信小程序用户sessionKey
...
...
uni_modules/uni-id-pages/uniCloud/cloudfunctions/uni-id-co/module/utils/get-h5-weixin-config.js
浏览文件 @
5fb0de72
...
...
@@ -24,15 +24,18 @@ module.exports = async function (params) {
const
oauthConfig
=
this
.
configUtils
.
getOauthConfig
({
provider
:
'
weixin
'
})
const
bridge
=
require
(
'
uni-open-bridge-common
'
)
const
{
appId
}
=
this
.
getClientInfo
()
const
weixinPlatform
=
getWeixinPlatform
.
call
(
this
)
const
ticket
=
await
b
ridge
.
getWeixinTicket
({
const
getTicketRes
=
await
this
.
uniOpenB
ridge
.
getWeixinTicket
({
appId
,
platform
:
weixinPlatform
})
if
(
!
getTicketRes
)
{
throw
new
Error
(
'
Wechat official account ticket not found, please referer to: https://uniapp.dcloud.net.cn/uniCloud/uni-id-pages.html#login-by-weixin-h5
'
)
}
const
ticket
=
getTicketRes
.
ticket
const
signContent
=
{
jsapi_ticket
:
ticket
,
noncestr
:
getNonceStr
(),
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录