my.getAuthCode 使用静默授权方法(令 scopes 为 auth_base)即可实现只出现一个授权弹框
my.getAuthCode({
scopes: ['auth_base'],
success: (res) => {
my.alert({
content: res.authCode,
});
},
});
之后将 authCode 传递给后台,后台调用 alipay.system.oauth.token 解析出来user_id
这里通过user_id后台能关联到用户是否是新用户,是否已经绑定手机号,优化后边的手机号登录流程。
其他用户的基础信息调用
<!-- .axml -->
<button a:if="{{canIUseAuthButton}}" open-type="getAuthorize"
onGetAuthorize="onGetAuthorize" onError="onAuthError"
scope='userInfo'>
会员基础信息授权
</button>
// .js
onGetAuthorize(res) {
my.getOpenUserInfo({
fail: (res) => {
},
success: (res) => {
let userInfo = JSON.parse(res.response).response // 以下方的报文格式解析两层 response
console.log(userInfo);
my.alert({
content: userInfo});
},
});
},
不要再让后台调用截屏2021-04-14 下午4.49.20.png
这块废弃了= = 郁闷了很久,还以为之前或取得token和user_id也都白获取了,气的发抖。。好在user_id和用户基础信息是分开的