diff --git a/frontend/app-user/api/login.js b/frontend/app-user/api/login.js
index f4a1d3f..f272be0 100644
--- a/frontend/app-user/api/login.js
+++ b/frontend/app-user/api/login.js
@@ -83,7 +83,7 @@ export function getUserInfo(params) {
})
}
-
+// 微信获取openid
export function getWechatOpenId(code) {
return request({
'url': '/sso/weixinPublic?code=' + code,
@@ -91,7 +91,13 @@ export function getWechatOpenId(code) {
})
}
-
+// 绑定openid
+export function bindOpenId(params) {
+ return request({
+ 'url': `/api/user/v1/user/bindOpenId?account=${params.account}&openid=${params.openId}`,
+ 'method': 'get'
+ })
+}
// 获取短信验证码
@@ -149,5 +155,6 @@ export default {
getPublicKey,
changUserPsd,
forgotPassword,
- getWechatOpenId
+ getWechatOpenId,
+ bindOpenId
}
diff --git a/frontend/app-user/common/config.js b/frontend/app-user/common/config.js
index 479d058..7d45ead 100644
--- a/frontend/app-user/common/config.js
+++ b/frontend/app-user/common/config.js
@@ -1,13 +1,14 @@
module.exports = {
- baseUrl: 'http://192.168.0.48:60011/api', //lst本地
- // baseUrl: 'https://lpg.ip-server.cn/api', //会员端线上
+ // baseUrl: 'http://192.168.0.48:60011/api', //lst本地
// baseUrl: 'http://123.60.140.65:60011/api',// 会员端ip
+ baseUrl: 'https://lpg.ip-server.cn/api', //会员端线上
gaodeMapKey: "ec36eed040d5dad959e19711b83905d6", //高德逆地址解析key
// 超时
timeout: 30000,
// 禁用 Cookie 等信息
withCredentials: false,
isOpenTokenExpiration: false, //token过期弹窗
+ appid:'wxb619394476ca1888',
header: {
//租户ID
'tenant-id': 1
diff --git a/frontend/app-user/pages/jump/weChatOffAcc.vue b/frontend/app-user/pages/jump/weChatOffAcc.vue
index 7be45c3..0bb7191 100644
--- a/frontend/app-user/pages/jump/weChatOffAcc.vue
+++ b/frontend/app-user/pages/jump/weChatOffAcc.vue
@@ -1,125 +1,168 @@
-
- 微信公众号-授权认证中
-
+
+ 微信公众号-授权认证中
+
+ .container {
+ display: flex;
+ justify-content: center;
+ align-items: center;
+ height: 100vh;
+ }
+
\ No newline at end of file
diff --git a/frontend/app-user/pages/login.vue b/frontend/app-user/pages/login.vue
index 7922a23..dcf4e09 100644
--- a/frontend/app-user/pages/login.vue
+++ b/frontend/app-user/pages/login.vue
@@ -191,64 +191,56 @@
}, 1000)
}
// #endif
- console.log(this.appid);
- // 微信公众号自动登录(暂不做)
- // let isWechatBrowser = this.isWechatBrowser();
- // if (isWechatBrowser) {
- // // console.log("微信浏览器环境", process);
- // let openId = uni.getStorageSync("openId");
- // var that = this;
- // if (!openId) {
- // this.getWxCode();
- // } else {
- // this.openId = openId;
- // }
- // }
+ console.log("appid", this.appid);
+ let isWechatBrowser = this.isWechatBrowser();
+ this.openId = uni.getStorageSync("openId");
+ console.log("openId", this.openId);
+ if (isWechatBrowser) {
+ if (!this.openId) {
+ uni.reLaunch({
+ url: '/pages/jump/weChatOffAcc'
+ })
+ }
+ }
},
onReady() {
// 如果需要兼容微信小程序,并且校验规则中含有方法等,只能通过setRules方法设置规则
this.$refs.form.setRules(this.rules)
},
methods: {
- //获取code
- getWxCode() {
- this.code = "";
- let local = window.location.href;
- console.log(local);
- console.log(this.code);
- let scope = "snsapi_base"; //静默授权 用户无感知
- this.code = this.getUrlCode().code;
- if (this.code == null || this.code === "") {
- console.log(123);
- window.location.href =
- `https://open.weixin.qq.com/connect/oauth2/authorize?appid=${this.appid}&redirect_uri=${encodeURIComponent(local)}&response_type=code&scope=${scope}#wechat_redirect`;
- } else {
- this.getOpenId(this.code);
+ //是否有openid
+ hasOpenId() {
+ this.openId = uni.getStorageSync('openId');
+ console.log("有openid", this.openId);
+ if (this.openId) {
+ this.bindWxOffAcc(this.openId)
+ // 默认静默绑定
+ // this.$modal.confirm('是否绑定公众号,以便下次免登录', '温馨提示', )
+ // .then(() => {
+ // this.bindWxOffAcc(this.openId)
+ // })
+ // .catch(() => {
+ // console.log("不绑定");
+ // uni.removeStorageSync('openId');
+ // uni.switchTab({
+ // url: '/pages/home/home'
+ // });
+ // })
}
},
- getUrlCode() {
- let fullUrl = window.location.href;
- let theRequest = new Object();
- if (fullUrl.indexOf("?") != -1) {
- var temp = fullUrl.split("?");
- let str = temp[1];
- let strs = str.split("&");
- for (var i = 0; i < strs.length; i++) {
- theRequest[strs[i].split("=")[0]] = strs[i].split("=")[1];
- }
- }
- return theRequest;
- },
- getOpenId(code) {
- let that = this;
- this.$api.loginApi.getWechatOpenId(code).then(res => {
- if (res.status == 1000) {
- that.openId = res.data.openId;
- uni.setStorageSync("openId", that.openId);
- } else {
- Toast(res.message);
+ bindWxOffAcc(openId) {
+ this.$api.loginApi.bindOpenId({
+ account: this.formData.mobile,
+ openId
+ }).then((res) => {
+ if (res.state) {
+ // 绑定成功
+ uni.removeStorageSync('openId');
+ uni.switchTab({
+ url: '/pages/home/home'
+ });
}
- });
+ })
},
isWechatBrowser() {
return /MicroMessenger/i.test(navigator.userAgent);
@@ -413,15 +405,21 @@
this.$store.dispatch('Login', data).then(res => {
this.$modal.closeLoading();
setTimeout(() => {
- uni.$u.toast('登录成功');
+ // uni.$u.toast('登录成功');
uni.setStorageSync('myAvatorImg', '');
- uni.switchTab({
- url: '/pages/home/home'
- });
-
+ // 只在微信浏览器环境生效并去绑定openid
+ if (this.isWechatBrowser()) {
+ this.hasOpenId();
+ }else{
+ // 非微信环境登录直接进入主页
+ uni.switchTab({
+ url: '/pages/home/home'
+ });
+ }
}, 300)
}).catch(err => {
- // uni.$u.toast(err)
+ console.log("err", err);
+ uni.$u.toast(err.msg)
})
}
}
diff --git a/frontend/app-user/store/modules/user.js b/frontend/app-user/store/modules/user.js
index 2f77659..eaee65f 100644
--- a/frontend/app-user/store/modules/user.js
+++ b/frontend/app-user/store/modules/user.js
@@ -160,6 +160,20 @@ const user = {
})
})
},
+ wxAuthLogin({
+ commit
+ }, userInfo) {
+ return new Promise((resolve, reject) => {
+ console.log("微信userInfo",userInfo);
+ if(userInfo.token){
+ setToken(userInfo.token);
+ commit('SET_TOKEN', userInfo.token)
+ resolve()
+ }else{
+ reject('No Token')
+ }
+ })
+ },
SetAdsName({
commit
}, data) {
--
libgit2 0.21.2