|
@@ -1,44 +1,31 @@
|
|
|
+import { getWxUserInfo, getWxConfig } from '../api/login'
|
|
|
export default {
|
|
|
install(Vue) {
|
|
|
- Vue.prototype.getOpenid = function (page) {
|
|
|
- var host = 'http://47.101.145.23/tianzong';
|
|
|
+ Vue.prototype.getOpenid = async function () {
|
|
|
if (localStorage.getItem("openid") != 'undefined' && localStorage.getItem("openid") != null)
|
|
|
return;
|
|
|
var code = this.getUrlParam("code");
|
|
|
if (code == 'undefined' || code == null || code == "") {
|
|
|
- //alert("参数异常,请返回首页重试");
|
|
|
- this.urlredirect(page);
|
|
|
+ this.urlredirect();
|
|
|
return;
|
|
|
}
|
|
|
- this.$http.post(host + "/weixin/getWxUserInfo", {
|
|
|
- code: code,
|
|
|
- userId: localStorage.getItem("userId")
|
|
|
- }, {
|
|
|
- emulateJSON: true
|
|
|
- })
|
|
|
- .then(res => {
|
|
|
- //发送成功
|
|
|
- console.log(res);
|
|
|
-
|
|
|
- if (res.body.code == '0') {
|
|
|
- localStorage.setItem("openid", res.body.openId);
|
|
|
- localStorage.setItem("headimgurl", res.body.headimgurl);
|
|
|
- //this.$store.commit("getId",res.body.data)
|
|
|
- } else {
|
|
|
- this.urlredirect(page);
|
|
|
- }
|
|
|
-
|
|
|
- //if()
|
|
|
- }, res => {
|
|
|
- //发送失败
|
|
|
- })
|
|
|
+ const res = await getWxUserInfo({ code: code, userId: localStorage.getItem("userId") })
|
|
|
+ console.log(res, '================================getWxUserInfo')
|
|
|
+ if (res.body.code == '0') {
|
|
|
+ console.log('直接走+======', res)
|
|
|
+ localStorage.setItem("openid", res.body.openId);
|
|
|
+ localStorage.setItem("headimgurl", res.body.headimgurl);
|
|
|
+ } else {
|
|
|
+ this.urlredirect();
|
|
|
+ }
|
|
|
|
|
|
}
|
|
|
|
|
|
- Vue.prototype.urlredirect = function (page) {
|
|
|
- var host = 'http://47.101.145.23/wuliu/ljy/';
|
|
|
+ Vue.prototype.urlredirect = async function (page) {
|
|
|
+ const res = await getWxConfig({})
|
|
|
+ const href = window.location.href
|
|
|
window.location.href =
|
|
|
- "https://open.weixin.qq.com/connect/oauth2/authorize?appid=wx3d3b98cc26425f40&redirect_uri=" + host + page + "&response_type=code&scope=snsapi_userinfo&state=STATE&connect_redirect=1#wechat_redirect";
|
|
|
+ `https://open.weixin.qq.com/connect/oauth2/authorize?appid=&redirect_uri=${res.wxConfig.appId}&redirect_uri=${encodeURIComponent(href)}` + "&response_type=code&scope=snsapi_userinfo&state=STATE&connect_redirect=1#wechat_redirect";
|
|
|
}
|
|
|
Vue.prototype.getUrlParam = function (name) {
|
|
|
var vars = [],
|