!33 修复微信小程序登录openid参数名不一致导致支付报错问题

Merge pull request !33 from 高靖/master
master-vue2
芋道源码 2023-12-27 11:57:49 +00:00 committed by Gitee
commit 27605c4cd1
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
1 changed files with 83 additions and 78 deletions

View File

@ -23,15 +23,15 @@
<!-- #ifdef MP -->
<button hover-class="none" @tap="getUserProfile" class="bg-green btn1">微信登录</button>
<!-- #endif -->
<!-- #ifdef MP-WEIXIN -->
<button open-type="getPhoneNumber" type="primary" @getphonenumber="getPhoneNumber"></button>
<!-- #endif -->
<!-- #ifdef MP-WEIXIN -->
<button open-type="getPhoneNumber" type="primary" @getphonenumber="getPhoneNumber"></button>
<!-- #endif -->
<!-- <button hover-class="none" @click="isUp = true" class="btn2">手机号登录</button> -->
</view>
</view>
<block v-if="isUp">
<mobileLogin :isUp="isUp" @close="maskClose" @wechatPhone="wechatPhone"
:social-code="socialCode" :social-state="socialState" />
<mobileLogin :isUp="isUp" @close="maskClose" @wechatPhone="wechatPhone" :social-code="socialCode"
:social-state="socialState" />
</block>
<block v-if="isPhoneBox">
<routinePhone :logoUrl="logoUrl" :isPhoneBox="isPhoneBox" @close="bindPhoneClose" :authKey="authKey">
@ -42,12 +42,14 @@
<script>
const app = getApp();
let statusBarHeight = uni.getSystemInfoSync().statusBarHeight + 'px';
import * as UserApi from "@/api/member/user";
import * as AuthApi from "@/api/member/auth";
import mobileLogin from '@/components/login_mobile/index.vue'
import * as UserApi from "@/api/member/user";
import * as AuthApi from "@/api/member/auth";
import mobileLogin from '@/components/login_mobile/index.vue'
import routinePhone from '@/components/login_mobile/routine_phone.vue'
import * as BrokerageAPI from '@/api/trade/brokerage.js'
import { getUserPhone } from '@/api/public';
import * as BrokerageAPI from '@/api/trade/brokerage.js'
import {
getUserPhone
} from '@/api/public';
import Routine from '@/libs/routine';
import wechat from "@/libs/wechat";
export default {
@ -65,8 +67,8 @@
userInfo: {},
codeNum: 0,
socialCode: '',
socialState: '',
socialCode: '',
socialState: '',
}
},
components: {
@ -86,22 +88,25 @@
window.scrollTo(0, Math.max(scrollHeight - 1, 0));
}, 100);
});
const { code, state } = options;
const {
code,
state
} = options;
this.options = options
// 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;
//
wechat.auth(code, state, spread).then(res => {
this.getUserInfo();
this.wechatPhone();
this.getUserInfo();
this.wechatPhone();
}).catch(error => {
//
this.socialCode = code;
this.socialState = state;
this.isUp = true
});
//
this.socialCode = code;
this.socialState = state;
this.isUp = true
});
}
// #endif
},
@ -131,25 +136,25 @@
this.isPhoneBox = false
}
},
getUserInfo() {
UserApi.getUserInfo().then(res => {
uni.hideLoading();
this.userInfo = res.data
this.$store.commit("UPDATE_USERINFO", res.data);
this.$util.Tips({
title: '登录成功',
icon: 'success'
}, {
tab: 3
})
});
},
bindBrokerUser() {
const spread = this.$Cache.get("spread");
if (spread > 0) {
BrokerageAPI.bindBrokerageUser(spread)
}
},
getUserInfo() {
UserApi.getUserInfo().then(res => {
uni.hideLoading();
this.userInfo = res.data
this.$store.commit("UPDATE_USERINFO", res.data);
this.$util.Tips({
title: '登录成功',
icon: 'success'
}, {
tab: 3
})
});
},
bindBrokerUser() {
const spread = this.$Cache.get("spread");
if (spread > 0) {
BrokerageAPI.bindBrokerageUser(spread)
}
},
// #ifdef MP
getUserProfile() {
let self = this;
@ -170,47 +175,47 @@
uni.hideLoading();
});
},
/**
* 微信一键登录
*/
async getPhoneNumber(e) {
//
const phoneCode = e.detail.code
if (!e.detail.code) {
uni.showModal({
title: '授权失败',
content: '您已拒绝获取绑定手机号登录授权,可以使用其他手机号验证登录',
confirmText: '知道了',
confirmColor: '#3C9CFFFF'
})
return;
}
//
const loginCode = await Routine.getCode()
AuthApi.weixinMiniAppLogin(phoneCode, loginCode,'default').then(res => {
const data = res.data;
// TODO refreshToken
this.$store.commit("LOGIN", {
'token': data.accessToken
});
// opendId
this.$store.commit("OPENID", data.openId);
// userId
this.$store.commit("SETUID", data.userId);
this.getUserInfo();
this.bindBrokerUser();
}).catch(e => {
this.$util.Tips({
title: e
});
});
},
/**
* 微信一键登录
*/
async getPhoneNumber(e) {
//
const phoneCode = e.detail.code
if (!e.detail.code) {
uni.showModal({
title: '授权失败',
content: '您已拒绝获取绑定手机号登录授权,可以使用其他手机号验证登录',
confirmText: '知道了',
confirmColor: '#3C9CFFFF'
})
return;
}
//
const loginCode = await Routine.getCode()
AuthApi.weixinMiniAppLogin(phoneCode, loginCode, 'default').then(res => {
const data = res.data;
// TODO refreshToken
this.$store.commit("LOGIN", {
'token': data.accessToken
});
// opendId
this.$store.commit("OPENID", data.openid);
// userId
this.$store.commit("SETUID", data.userId);
this.getUserInfo();
this.bindBrokerUser();
}).catch(e => {
this.$util.Tips({
title: e
});
});
},
// #endif
// #ifdef H5
//
wechatLogin() {
debugger
debugger
if (!this.code && this.options.scope !== 'snsapi_base') {
this.$wechat.oAuth('snsapi_userinfo', '/pages/users/wechat_login/index');
} else {
@ -219,7 +224,7 @@
},
//
wechatPhone() {
debugger
debugger
this.$Cache.clear('snsapiKey');
if (this.options.back_url) {
let url = uni.getStorageSync('snRouter');
@ -312,4 +317,4 @@
height: 50rpx;
}
}
</style>
</style>