提交 8bb3416f 编写于 作者: 雪洛's avatar 雪洛

feat: getH5WeixinConfig

上级 71dc39a3
......@@ -163,6 +163,14 @@ function coverMobile (mobile) {
return mobile.slice(0, 3) + '****' + mobile.slice(7)
}
function getNonceStr (length = 16) {
let str = ''
while (str.length < length) {
str += Math.random().toString(32).substring(2)
}
return str.substring(0, length)
}
module.exports = {
getType,
isValidString,
......@@ -177,5 +185,6 @@ module.exports = {
snake2camelJson,
getExtension,
getVerifyCode,
coverMobile
coverMobile,
getNonceStr
}
......@@ -54,7 +54,8 @@ const {
} = require('./module/verify/index')
const {
refreshToken,
setPushCid
setPushCid,
getH5WeixinConfig
} = require('./module/utils/index')
const {
getInvitedUser,
......@@ -480,5 +481,11 @@ module.exports = {
* @tutorial https://uniapp.dcloud.net.cn/uniCloud/uni-id-pages.html#get-supported-login-type
* @returns
*/
getSupportedLoginType
getSupportedLoginType,
/**
* 获取微信公众号config参数
* @tutorial https://uniapp.dcloud.net.cn/uniCloud/uni-id-pages.html#get-h5-weixin-config
* @returns
*/
getH5WeixinConfig
}
......@@ -50,7 +50,7 @@ const loginTypeTester = {
* @tutorial https://uniapp.dcloud.net.cn/uniCloud/uni-id-pages.html#get-supported-login-type
* @returns
*/
module.exports = function () {
module.exports = async function () {
const supportedLoginType = [
'username-password',
'mobile-password',
......
......@@ -88,7 +88,7 @@ module.exports = async function (params = {}) {
wx_unionid: unionid
}
})
const extraData = {}
const extraData = { }
if (type === 'register' && weixinPlatform !== 'mp') {
const {
nickname,
......
const {
getWeixinPlatform
} = require('../../lib/utils/weixin')
const {
getNonceStr
} = require('../../common/utils')
const {
createHash
} = require('crypto')
/**
* 获取微信公众号config参数
* @tutorial https://uniapp.dcloud.net.cn/uniCloud/uni-id-pages.html#get-h5-weixin-config
* @returns
*/
module.exports = async function (params) {
const schema = {
url: 'string'
}
this.middleware.validate(params, schema)
const {
url
} = 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 bridge.getWeixinTicket({
appId,
platform: weixinPlatform
})
const signContent = {
jsapi_ticket: ticket,
noncestr: getNonceStr(),
timestamp: Math.floor(Date.now() / 1000) + '',
url: url.split('#')[0]
}
const signStr = Object.keys(signContent).sort().reduce(function (str, key) {
return str + key + '=' + signContent[key] + '&'
}, '').replace(/&$/, '')
const signature = createHash('sha1').update(signStr, 'utf8').digest('hex')
return {
appId: oauthConfig.appid, // 公众号的唯一标识
timestamp: signContent.timestamp, // 生成签名的时间戳
nonceStr: signContent.noncestr, // 生成签名的随机串
signature // 签名
}
}
module.exports = {
refreshToken: require('./refresh-token'),
setPushCid: require('./set-push-cid')
setPushCid: require('./set-push-cid'),
getH5WeixinConfig: require('./get-h5-weixin-config')
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册