人人商城修改小程式授權為新版介面
阿新 • • 發佈:2021-07-26
人人商城小程式使用者授權登入失敗,getUserProfile小程式登入介面升級
怎麼修改呢?
1,修改pages\auth\index.wxml
立即登入按鈕改為
?1 2 3 |
< button bindtap = "getUserProfile" class = "authBtn" lang = "zh_CN" >
立即登入
</ button >
|
2,修改pages\auth\index.js
第62行新增程式碼
?1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
getUserProfile(){
wx.getUserProfile({
desc: '用於完善會員資料' , // 宣告獲取使用者個人資訊後的用途,後續會展示在彈窗中,請謹慎填寫
success: (res) => {
// console.log("獲取使用者資訊成功", res);
// return;
wx.showLoading({
title: "載入中"
}), wx.login({
success: function (t) {
// console.log(t);
// return;
n.post( "wxapp/login" , {
code: t.code
}, function (t) {
// console.log(t.openid);
// return;
t.error ? n.alert( "獲取使用者登入態失敗:" + t.message) : n.get( "wxapp/auth" , {
data: res.encryptedData,
iv: res.iv,
sessionKey: t.session_key,
openId:t.openid
}, function (n) {
1 == n.isblack && wx.showModal({
title: "無法訪問" ,
content: "您在商城的黑名單中,無權訪問!" ,
success: function (n) {
n.confirm && e.close(), n.cancel && e.close();
}
}), res.userInfo.openid = n.openId, res.userInfo.id = n.id, res.userInfo.uniacid = n.uniacid,
e.setCache( "userinfo" , res.userInfo), e.setCache( "userinfo_openid" , res.userInfo.openid),
e.setCache( "userinfo_id" , n.id), e.getSet(), wx.navigateBack({
changed: !0
});
});
});
},
fail: function () {
n.alert( "獲取使用者資訊失敗!" );
},
complete: function () {
wx.hideLoading();
}
});
},
fail: res => {
// console.log("獲取使用者資訊失敗", res)
n.alert( "獲取使用者資訊失敗!" );
}
})
},
|
如圖,新舊程式碼對比
3,修改登入介面檔案addons\ewei_shopv2\plugin\app\core\mobile\wxapp.php
由於getUserProfile本身就是不返回openid的,需要openid用login介面
對應上面js的程式碼就是
介面檔案第93行加上程式碼
$data['openId'] = $_GPC['openId'];
如圖