ShopWind多商户电商系统支持QQ、微信、支付宝、新浪微博等第三方账号外部登陆。第三方登录省略了平台的注册流程,用户可以直接通过支付宝、微信等账号登录或扫码登录,免于记录和输入众多的会员账号及密码等信息,一键登录平台,方便快捷。
微信官方近期更新了微信登录接口,获取会员的头像和昵称等都发生了改变,ShopWind及时跟进微信官方做出了代码的更新。
修改代码如下:
1、打开pages/login/login.js 文件 整体替换function unilogin(that, params) 函数
/**
* UniAPP统一登录接口
* 兼容APP微信登录/小程序登录/QQ登录
* @param {Object} that
* @param {Object} params
*/
function unilogin(that, params) {
// 操作系统版本
let system = Math.floor(parseFloat(uni.getSystemInfoSync().system))
if (params.logintype == 'apple' && system < 13) {
uni.showModal({
title: '提示',
content: 'iOS13及以上系统版本才支持苹果登录',
showCancel: false
})
return
}
// #ifdef MP-WEIXIN
uni.login({
success(res) {
params.code = res.code
}
})
uni.getUserProfile({
desc: '同步您的头像和昵称',
success(res) {
if (res.errMsg.indexOf("getUserProfile:ok") > -1) {
Object.assign(params, {
portrait: res.userInfo.avatarUrl,
nickname: res.userInfo.nickName,
scene: 'weixinmp'
})
login(params)
} else if (res.errMsg) {
uni.showModal({
title: '提示',
content: res.errMsg,
showCancel: false
})
}
}
})
// #endif
// # ifndef MP-WEIXIN
uni.login({
provider: params.logintype,
success() {
uni.getUserInfo({
provider: params.logintype,
lang: 'zh_CN',
success(res) {
let userInfo = res.userInfo
Object.assign(params, {
unionid: userInfo.unionId ? userInfo.unionId : (userInfo.openId ? userInfo.openId : ''),
openid: userInfo.openId ? userInfo.openId : '',
portrait: userInfo.avatarUrl,
nickname: userInfo.fullName ? (userInfo.fullName.familyName + userInfo.fullName
.givenName) : userInfo.nickName
})
login(params)
},
fail(res) {
uni.showModal({
title: '提示',
content: res.errMsg,
showCancel: false
})
}
})
}
})
// #endif
}
2、打开服务端common\plugins\connect\weixinmp\weixinmp.plugin.php 文件, 修改 public function getUserInfo($response = null) 函数
public function getUserInfo($response = null)
{
return $response;
}
修改为:
public function getUserInfo($response = null)
{
// 头像和昵称已在小程序端[getUserProfile]获取到
if($this->params->portrait) {
$response->portrait = $this->params->portrait;
}
if($this->params->nickname) {
$response->nickname = $this->params->nickname;
}
return $response;
}