'修复微信小程序登录openid参数名不一致导致支付报错问题'
parent
9f134ee5f0
commit
e84ad12c5b
|
@ -23,15 +23,15 @@
|
||||||
<!-- #ifdef MP -->
|
<!-- #ifdef MP -->
|
||||||
<button hover-class="none" @tap="getUserProfile" class="bg-green btn1">微信登录</button>
|
<button hover-class="none" @tap="getUserProfile" class="bg-green btn1">微信登录</button>
|
||||||
<!-- #endif -->
|
<!-- #endif -->
|
||||||
<!-- #ifdef MP-WEIXIN -->
|
<!-- #ifdef MP-WEIXIN -->
|
||||||
<button open-type="getPhoneNumber" type="primary" @getphonenumber="getPhoneNumber">一键登录</button>
|
<button open-type="getPhoneNumber" type="primary" @getphonenumber="getPhoneNumber">一键登录</button>
|
||||||
<!-- #endif -->
|
<!-- #endif -->
|
||||||
<!-- <button hover-class="none" @click="isUp = true" class="btn2">手机号登录</button> -->
|
<!-- <button hover-class="none" @click="isUp = true" class="btn2">手机号登录</button> -->
|
||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
<block v-if="isUp">
|
<block v-if="isUp">
|
||||||
<mobileLogin :isUp="isUp" @close="maskClose" @wechatPhone="wechatPhone"
|
<mobileLogin :isUp="isUp" @close="maskClose" @wechatPhone="wechatPhone" :social-code="socialCode"
|
||||||
:social-code="socialCode" :social-state="socialState" />
|
:social-state="socialState" />
|
||||||
</block>
|
</block>
|
||||||
<block v-if="isPhoneBox">
|
<block v-if="isPhoneBox">
|
||||||
<routinePhone :logoUrl="logoUrl" :isPhoneBox="isPhoneBox" @close="bindPhoneClose" :authKey="authKey">
|
<routinePhone :logoUrl="logoUrl" :isPhoneBox="isPhoneBox" @close="bindPhoneClose" :authKey="authKey">
|
||||||
|
@ -42,12 +42,14 @@
|
||||||
<script>
|
<script>
|
||||||
const app = getApp();
|
const app = getApp();
|
||||||
let statusBarHeight = uni.getSystemInfoSync().statusBarHeight + 'px';
|
let statusBarHeight = uni.getSystemInfoSync().statusBarHeight + 'px';
|
||||||
import * as UserApi from "@/api/member/user";
|
import * as UserApi from "@/api/member/user";
|
||||||
import * as AuthApi from "@/api/member/auth";
|
import * as AuthApi from "@/api/member/auth";
|
||||||
import mobileLogin from '@/components/login_mobile/index.vue'
|
import mobileLogin from '@/components/login_mobile/index.vue'
|
||||||
import routinePhone from '@/components/login_mobile/routine_phone.vue'
|
import routinePhone from '@/components/login_mobile/routine_phone.vue'
|
||||||
import * as BrokerageAPI from '@/api/trade/brokerage.js'
|
import * as BrokerageAPI from '@/api/trade/brokerage.js'
|
||||||
import { getUserPhone } from '@/api/public';
|
import {
|
||||||
|
getUserPhone
|
||||||
|
} from '@/api/public';
|
||||||
import Routine from '@/libs/routine';
|
import Routine from '@/libs/routine';
|
||||||
import wechat from "@/libs/wechat";
|
import wechat from "@/libs/wechat";
|
||||||
export default {
|
export default {
|
||||||
|
@ -65,8 +67,8 @@
|
||||||
userInfo: {},
|
userInfo: {},
|
||||||
codeNum: 0,
|
codeNum: 0,
|
||||||
|
|
||||||
socialCode: '',
|
socialCode: '',
|
||||||
socialState: '',
|
socialState: '',
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
components: {
|
components: {
|
||||||
|
@ -86,22 +88,25 @@
|
||||||
window.scrollTo(0, Math.max(scrollHeight - 1, 0));
|
window.scrollTo(0, Math.max(scrollHeight - 1, 0));
|
||||||
}, 100);
|
}, 100);
|
||||||
});
|
});
|
||||||
const { code, state } = options;
|
const {
|
||||||
|
code,
|
||||||
|
state
|
||||||
|
} = options;
|
||||||
this.options = options
|
this.options = options
|
||||||
// 获取确认授权code
|
// 获取确认授权code
|
||||||
this.code = code || ''
|
this.code = code || ''
|
||||||
if (code && this.options.scope !== 'snsapi_base') {
|
if (code && this.options.scope !== 'snsapi_base') {
|
||||||
let spread = app.globalData.spid ? app.globalData.spid : 0;
|
let spread = app.globalData.spid ? app.globalData.spid : 0;
|
||||||
// 公众号授权登录回调
|
// 公众号授权登录回调
|
||||||
wechat.auth(code, state, spread).then(res => {
|
wechat.auth(code, state, spread).then(res => {
|
||||||
this.getUserInfo();
|
this.getUserInfo();
|
||||||
this.wechatPhone();
|
this.wechatPhone();
|
||||||
}).catch(error => {
|
}).catch(error => {
|
||||||
// 异常的情况,说明可能是账号没登录,所以发起手机绑定
|
// 异常的情况,说明可能是账号没登录,所以发起手机绑定
|
||||||
this.socialCode = code;
|
this.socialCode = code;
|
||||||
this.socialState = state;
|
this.socialState = state;
|
||||||
this.isUp = true
|
this.isUp = true
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
// #endif
|
// #endif
|
||||||
},
|
},
|
||||||
|
@ -131,25 +136,25 @@
|
||||||
this.isPhoneBox = false
|
this.isPhoneBox = false
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
getUserInfo() {
|
getUserInfo() {
|
||||||
UserApi.getUserInfo().then(res => {
|
UserApi.getUserInfo().then(res => {
|
||||||
uni.hideLoading();
|
uni.hideLoading();
|
||||||
this.userInfo = res.data
|
this.userInfo = res.data
|
||||||
this.$store.commit("UPDATE_USERINFO", res.data);
|
this.$store.commit("UPDATE_USERINFO", res.data);
|
||||||
this.$util.Tips({
|
this.$util.Tips({
|
||||||
title: '登录成功',
|
title: '登录成功',
|
||||||
icon: 'success'
|
icon: 'success'
|
||||||
}, {
|
}, {
|
||||||
tab: 3
|
tab: 3
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
bindBrokerUser() {
|
bindBrokerUser() {
|
||||||
const spread = this.$Cache.get("spread");
|
const spread = this.$Cache.get("spread");
|
||||||
if (spread > 0) {
|
if (spread > 0) {
|
||||||
BrokerageAPI.bindBrokerageUser(spread)
|
BrokerageAPI.bindBrokerageUser(spread)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
// #ifdef MP
|
// #ifdef MP
|
||||||
getUserProfile() {
|
getUserProfile() {
|
||||||
let self = this;
|
let self = this;
|
||||||
|
@ -170,47 +175,47 @@
|
||||||
uni.hideLoading();
|
uni.hideLoading();
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
/**
|
/**
|
||||||
* 微信一键登录
|
* 微信一键登录
|
||||||
*/
|
*/
|
||||||
async getPhoneNumber(e) {
|
async getPhoneNumber(e) {
|
||||||
// 情况一:拒绝授权手机号码
|
// 情况一:拒绝授权手机号码
|
||||||
const phoneCode = e.detail.code
|
const phoneCode = e.detail.code
|
||||||
if (!e.detail.code) {
|
if (!e.detail.code) {
|
||||||
uni.showModal({
|
uni.showModal({
|
||||||
title: '授权失败',
|
title: '授权失败',
|
||||||
content: '您已拒绝获取绑定手机号登录授权,可以使用其他手机号验证登录',
|
content: '您已拒绝获取绑定手机号登录授权,可以使用其他手机号验证登录',
|
||||||
confirmText: '知道了',
|
confirmText: '知道了',
|
||||||
confirmColor: '#3C9CFFFF'
|
confirmColor: '#3C9CFFFF'
|
||||||
})
|
})
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// 情况二:允许授权手机号码
|
// 情况二:允许授权手机号码
|
||||||
const loginCode = await Routine.getCode()
|
const loginCode = await Routine.getCode()
|
||||||
AuthApi.weixinMiniAppLogin(phoneCode, loginCode,'default').then(res => {
|
AuthApi.weixinMiniAppLogin(phoneCode, loginCode, 'default').then(res => {
|
||||||
const data = res.data;
|
const data = res.data;
|
||||||
// TODO 芋艿:refreshToken 机制
|
// TODO 芋艿:refreshToken 机制
|
||||||
this.$store.commit("LOGIN", {
|
this.$store.commit("LOGIN", {
|
||||||
'token': data.accessToken
|
'token': data.accessToken
|
||||||
});
|
});
|
||||||
// 保存opendId用于支付
|
// 保存opendId用于支付
|
||||||
this.$store.commit("OPENID", data.openId);
|
this.$store.commit("OPENID", data.openid);
|
||||||
// 设置当前userId
|
// 设置当前userId
|
||||||
this.$store.commit("SETUID", data.userId);
|
this.$store.commit("SETUID", data.userId);
|
||||||
this.getUserInfo();
|
this.getUserInfo();
|
||||||
this.bindBrokerUser();
|
this.bindBrokerUser();
|
||||||
}).catch(e => {
|
}).catch(e => {
|
||||||
this.$util.Tips({
|
this.$util.Tips({
|
||||||
title: e
|
title: e
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
// #endif
|
// #endif
|
||||||
|
|
||||||
// #ifdef H5
|
// #ifdef H5
|
||||||
// 公众号登录
|
// 公众号登录
|
||||||
wechatLogin() {
|
wechatLogin() {
|
||||||
debugger
|
debugger
|
||||||
if (!this.code && this.options.scope !== 'snsapi_base') {
|
if (!this.code && this.options.scope !== 'snsapi_base') {
|
||||||
this.$wechat.oAuth('snsapi_userinfo', '/pages/users/wechat_login/index');
|
this.$wechat.oAuth('snsapi_userinfo', '/pages/users/wechat_login/index');
|
||||||
} else {
|
} else {
|
||||||
|
@ -219,7 +224,7 @@
|
||||||
},
|
},
|
||||||
// 输入手机号后的回调
|
// 输入手机号后的回调
|
||||||
wechatPhone() {
|
wechatPhone() {
|
||||||
debugger
|
debugger
|
||||||
this.$Cache.clear('snsapiKey');
|
this.$Cache.clear('snsapiKey');
|
||||||
if (this.options.back_url) {
|
if (this.options.back_url) {
|
||||||
let url = uni.getStorageSync('snRouter');
|
let url = uni.getStorageSync('snRouter');
|
||||||
|
@ -312,4 +317,4 @@
|
||||||
height: 50rpx;
|
height: 50rpx;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
Loading…
Reference in New Issue