Commit cb11309b by 程默

修改getUserInfo接口

parent 02f99356
...@@ -4,14 +4,8 @@ ...@@ -4,14 +4,8 @@
<image class="img" mode="aspectFit" :src="logoUrl" /> <image class="img" mode="aspectFit" :src="logoUrl" />
<p class="shopName" v-if="shopName">{{shopName}}</p> <p class="shopName" v-if="shopName">{{shopName}}</p>
<div class="btn_info"> <div class="btn_info">
<button class="btn" lang="zh_CN" open-type="getUserInfo" @getuserinfo="getUserInfo">微信一键登录</button> <button class="btn" lang="zh_CN" @click="getUserProfile">微信一键登录</button>
</div> </div>
<!-- <div>{{testd}}</div>
<div>{{test_sessionId}}</div>--sessionId
<div>{{unionId}}</div>--unionId
<div>{{test_isHaveUnion}}</div>--isHaveUnion-->
<!-- <div class="enterpriseLogin" @click="eLogin">账号登录</div> -->
</div> </div>
<div class="toCLogin1" v-if="isShowPhone"> <div class="toCLogin1" v-if="isShowPhone">
<div class="btn_info1"> <div class="btn_info1">
...@@ -31,11 +25,7 @@ import { wx_decode } from "@/utils/wxIndex.js"; ...@@ -31,11 +25,7 @@ import { wx_decode } from "@/utils/wxIndex.js";
import login from "@/api/login"; import login from "@/api/login";
import shop from "@/api/shop"; import shop from "@/api/shop";
import indexApi from "@/api/index.js"; import indexApi from "@/api/index.js";
var WXBizDataCrypt = require("@/utils/WXBizDataCrypt");
export default { export default {
components: {
// card
},
data() { data() {
return { return {
code: "", code: "",
...@@ -68,7 +58,6 @@ export default { ...@@ -68,7 +58,6 @@ export default {
scene:''//场景 scene:''//场景
}; };
}, },
created() {},
onShow() { onShow() {
wx.checkSession({ wx.checkSession({
success : () => { success : () => {
...@@ -170,32 +159,20 @@ export default { ...@@ -170,32 +159,20 @@ export default {
}) })
} }
}, },
getUserInfo: function(e) { getUserProfile() {
this.backParams=this.defalutBackParams // 推荐使用wx.getUserProfile获取用户信息,开发者每次通过该接口获取用户个人信息均需用户确认
wx.showLoading({ // 开发者妥善保管用户快速填写的头像昵称,避免重复弹窗
title: "加载中" wx.getUserProfile({
}); desc: '用于完善会员资料', // 声明获取用户个人信息后的用途,后续会展示在弹窗中,请谨慎填写
if (e.target.errMsg == "getUserInfo:ok") { success: (e) => {
this.init() this.init()
.then(res => { .then(res => {
console.log("promise", res);
//存入openid //存入openid
try { try {
wx.setStorageSync('openid', res.data.data.openid) wx.setStorageSync('openid', res.data.data.openid)
} catch (e) { } catch (e) {
console.log('存入openid失败',e) console.log('存入openid失败',e)
} }
wx.getStorage({
key: "openid",
success (res) {
console.log("promise_openid1",res)
},
fail(err){
console.log("promise_openid2",err)
}
})
//
if (res.data.data.isHaveUnion == "true") { if (res.data.data.isHaveUnion == "true") {
//有账号 //有账号
this.backParams += `&sessionid=${ this.backParams += `&sessionid=${
...@@ -216,9 +193,10 @@ export default { ...@@ -216,9 +193,10 @@ export default {
this.appid = res.data.data.appid; this.appid = res.data.data.appid;
this.session_key = res.data.data.session_key; this.session_key = res.data.data.session_key;
this.openid = res.data.data.openid; this.openid = res.data.data.openid;
this.unionId = res.data.data.unionId || '';
this.isShow = true; this.isShow = true;
//checkLogin //checkLogind
this.checkLogin(e); this.checkLogin(e);
}) })
.catch(err => { .catch(err => {
...@@ -226,46 +204,19 @@ export default { ...@@ -226,46 +204,19 @@ export default {
wx.hideLoading(); wx.hideLoading();
wx.showToast({ title: err, icon: "none" }); wx.showToast({ title: err, icon: "none" });
}); });
} else {
wx.hideLoading();
wx.showToast({ title: "获取用户信息失败", icon: "none" });
} }
})
}, },
checkLogin(e) { checkLogin(e) {
console.log(this.isHaveUnion,e) this.userInfo = e.userInfo;
this.$store.commit('setUserInfo',this.userInfo)
if (this.isHaveUnion) { if (this.isHaveUnion) {
wx.hideLoading(); wx.hideLoading();
//是会员 直接登录 //是会员 直接登录
// 0318写直播改后面注释逻辑相同
// wx.reLaunch({
// url: `../index/main?from=login&backpath=${
// this.backPath
// }&params=${encodeURIComponent(this.backParams)}`
// });
// 跳转回小程序页面 // 跳转回小程序页面
var data = wx_decode(
this.appid,
this.session_key,
e.mp.detail.encryptedData,
e.mp.detail.iv
);
this.userInfo = JSON.parse(e.target.rawData);
this.$store.commit('setUserInfo',this.userInfo)
this.addRecord(false); this.addRecord(false);
this.pushPageType(); this.pushPageType();
} else { } else {
var data = wx_decode(
this.appid,
this.session_key,
e.mp.detail.encryptedData,
e.mp.detail.iv
);
this.unionId = data.unionId || "";
this.userInfo = JSON.parse(e.target.rawData);
console.log(this.userInfo, "this.userInfo");
this.$store.commit('setUserInfo',this.userInfo)
if (this.unionId) { if (this.unionId) {
login login
.checkUnionid({ unionId: this.unionId, openId: this.openid }) .checkUnionid({ unionId: this.unionId, openId: this.openid })
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment