登录失败问题修复
This commit is contained in:
@@ -136,6 +136,45 @@ export function parseIdCardLoginParams(url) {
|
||||
* @param {string} base64Str base64编码的字符串
|
||||
* @returns {string} 解码后的身份证号码
|
||||
*/
|
||||
/** 预取的 wx.login code,须在 getPhoneNumber 之前获取,授权后勿再 login */
|
||||
let cachedWxLoginCode = '';
|
||||
|
||||
/**
|
||||
* 预取 wx.login 的 code(与后续 getPhoneNumber 的 encryptedData 使用同一 session)
|
||||
*/
|
||||
export function refreshWxLoginCode() {
|
||||
return new Promise((resolve, reject) => {
|
||||
// #ifdef MP-WEIXIN
|
||||
uni.login({
|
||||
provider: 'weixin',
|
||||
success: (res) => {
|
||||
if (res.code) {
|
||||
cachedWxLoginCode = res.code;
|
||||
resolve(res.code);
|
||||
} else {
|
||||
reject(new Error('未获取到微信登录凭证'));
|
||||
}
|
||||
},
|
||||
fail: (err) => reject(err),
|
||||
});
|
||||
// #endif
|
||||
// #ifndef MP-WEIXIN
|
||||
resolve('');
|
||||
// #endif
|
||||
});
|
||||
}
|
||||
|
||||
export function getWxLoginCode() {
|
||||
return cachedWxLoginCode;
|
||||
}
|
||||
|
||||
/** 取出并清空缓存(微信 code 仅能使用一次) */
|
||||
export function takeWxLoginCode() {
|
||||
const code = cachedWxLoginCode;
|
||||
cachedWxLoginCode = '';
|
||||
return code;
|
||||
}
|
||||
|
||||
export function decodeIdCardBase64(base64Str) {
|
||||
try {
|
||||
// #ifdef H5
|
||||
@@ -164,5 +203,8 @@ export default {
|
||||
navigateToLoginPage,
|
||||
checkLoginAndNavigate,
|
||||
parseIdCardLoginParams,
|
||||
decodeIdCardBase64
|
||||
decodeIdCardBase64,
|
||||
refreshWxLoginCode,
|
||||
getWxLoginCode,
|
||||
takeWxLoginCode,
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user