gukai 1 year ago
parent 639a45ab29
commit b2b0c4c862

@ -144,6 +144,15 @@ export default {
}); });
}, },
wechatPageH5(data) {
return request({
url: "/common/wechatPageH5",
method: "GET",
data,
needLogin: true,
});
},
aliH5(data) { aliH5(data) {
return request({ return request({
url: "/common/aliH5", url: "/common/aliH5",

@ -33,7 +33,7 @@
created() { created() {
if (this.wcCode) { if (this.wcCode) {
this.actionLogin(this.wcCode, '', 1); this.actionLogin(this.wcCode, '', 1);
} } else {
// //
if (this.type == 2) { if (this.type == 2) {
this.isLogin() this.isLogin()
@ -41,11 +41,13 @@
// #ifdef H5 // #ifdef H5
// h5 // h5
if (this.type == 0) { if (this.type == 0) {
if (this.$utils.isInAliBrowser()) { if (this.$utils.isInAliBrowser() || this.$utils.isInWeChatBrowser()) {
this.login() this.login()
} }
} }
// #endif // #endif
}
}, },
methods: { methods: {
async login({ async login({
@ -90,7 +92,6 @@
const res = await this.$api.common.aliH5(); const res = await this.$api.common.aliH5();
// appid // appid
const appid = res.data.appid; const appid = res.data.appid;
ap.getAuthCode({ ap.getAuthCode({
appId: appid, appId: appid,
scopes: ['auth_base'], scopes: ['auth_base'],
@ -110,15 +111,18 @@
} else if (this.$utils.isInWeChatBrowser()) { } else if (this.$utils.isInWeChatBrowser()) {
// h5 // h5
// APIH5 // APIH5
const res = await this.$api.common.wechatH5(); const res = await this.$api.common.wechatPageH5();
// appid // appid
const appid = res.data.appid; const appid = res.data.appid;
const component_appid = res.data.component_appid
// //
let redirect_uri = window.location.href; let redirect_uri = window.location.href;
redirect_uri = encodeURIComponent(redirect_uri); var fruits = redirect_uri.split("?");
// console.log(fruits, 'fruits')
redirect_uri = encodeURIComponent(fruits[0]);
// appid // appid
const wxAuthUrl = // const wxAuthUrl = `https://open.weixin.qq.com/connect/oauth2/authorize?appid=${appid}&redirect_uri=${redirect_uri}&response_type=code&scope=snsapi_base&state=STATE#wechat_redirect`;
`https://open.weixin.qq.com/connect/oauth2/authorize?appid=${appid}&redirect_uri=${redirect_uri}&response_type=code&scope=snsapi_userinfo&state=STATE#wechat_redirect`; const wxAuthUrl = `https://open.weixin.qq.com/connect/oauth2/authorize?appid=${appid}&redirect_uri=${redirect_uri}&response_type=code&scope=snsapi_base&state=STATE&component_appid=${component_appid}#wechat_redirect`
// //
window.location.href = wxAuthUrl; window.location.href = wxAuthUrl;
return; return;
@ -153,7 +157,6 @@
user_info, user_info,
store_id store_id
} = res.data; } = res.data;
uni.setStorageSync("token_" + store_id, token); uni.setStorageSync("token_" + store_id, token);
uni.setStorageSync("user_info", user_info); uni.setStorageSync("user_info", user_info);
if (this.type != 0) { if (this.type != 0) {
@ -166,7 +169,6 @@
this.backPage() this.backPage()
return; return;
} }
uni.$u.toast(res.message); uni.$u.toast(res.message);
} catch (e) { } catch (e) {
uni.hideLoading(); uni.hideLoading();

@ -3,7 +3,8 @@ const env = {
NETWORK_TIME_OUT: 15000, NETWORK_TIME_OUT: 15000,
version: "0.1", version: "0.1",
store_id: 1, store_id: 1,
mini_id: 0 mini_id: 0,
is_page: 1
}; };
// #ifdef H5 // #ifdef H5
// 生产环境 // 生产环境

@ -73,10 +73,7 @@
</view> </view>
</template> </template>
<logins v-if="wcCode != -1" @isLogin="isLogin" :wcCode="wcCode" :type="$utils.isInAliBrowser() || $utils.isInWeChatBrowser() ? 0 : 2"></logins>
<logins @isLogin="isLogin" :type="$utils.isInAliBrowser() ? 0 : 2"></logins>
</view> </view>
</template> </template>
@ -108,7 +105,8 @@
payCurrent: false, payCurrent: false,
coupon: [], coupon: [],
activeCoupon: {}, activeCoupon: {},
mch_id: 0 mch_id: 0,
wcCode: -1
} }
}, },
computed: { computed: {
@ -122,43 +120,26 @@
} }
}, },
async onLoad(query) { async onLoad(query) {
if (query.wxcode) {
if (!this.$utils.isInAliBrowser()) { this.wcCode = query.wxcode
query.mch_id = uni.getStorageSync('pay_mch_id')
} else {
if (query.state) {
return uni.showModal({ return uni.showModal({
title: '提示', title: '提示',
content: '请使用支付宝扫码', content: '登录失败'
showCancel: false
}) })
} }
this.wcCode = ''
let qrCode = ''; if (query.mch_id > 0) {
uni.setStorageSync('pay_mch_id', query.mch_id)
// #ifdef MP-ALIPAY
let qrQuery = ''
if (query.query && query.query.qrCode) {
qrQuery = query.query.qrCode; //
} else {
qrQuery = uni.getStorageSync('qrcode')
} }
qrCode = decodeURIComponent(qrQuery || ''); // }
// #endif let qrCode = '';
// #ifdef MP-WEIXIN
qrCode = decodeURIComponent(query.q || '');
// #endif
// #ifdef MP
const params = this.$utils.oneValues(qrCode)
// #endif
// #ifdef H5
const params = query const params = query
// #endif
const { const {
mch_id mch_id
} = params; } = params;
this.mch_id = mch_id || 0 this.mch_id = mch_id || 0
this.$nextTick(() => { this.$nextTick(() => {
this.init() this.init()
@ -256,11 +237,11 @@
break; break;
case 2: case 2:
return uni.showModal({ // return uni.showModal({
title: '提示', // title: '',
content: '请使用支付宝扫码', // content: '使',
showCancel: false // showCancel: false
}) // })
// #ifndef MP // #ifndef MP
await this.wechatPayNow({ await this.wechatPayNow({
payType, payType,
@ -286,9 +267,7 @@
order_no, order_no,
order_type order_type
}) })
break; break;
default: default:
break; break;
} }

@ -15,9 +15,16 @@ export default {
wcCode: undefined wcCode: undefined
}; };
}, },
onLoad({ wxcode } = {}) { onLoad({ wxcode, state } = {}) {
if (wxcode) { if (wxcode) {
this.wcCode = wxcode this.wcCode = wxcode
} else {
if (state) {
return uni.showModal({
title: '提示',
content: '登录失败'
})
}
} }
}, },
methods: {}, methods: {},

Loading…
Cancel
Save