Commit f2a0ac00 by 程默

第三方跳转 sso

parent 5babe6db
...@@ -15,6 +15,10 @@ console.log(process.env,'-----------------config------') ...@@ -15,6 +15,10 @@ console.log(process.env,'-----------------config------')
//check unionid //check unionid
checkUnionid(options){ checkUnionid(options){
return requestGET(`${process.env.OLSHOP_URL}/wx/mini_check_union_id`,options) return requestGET(`${process.env.OLSHOP_URL}/wx/mini_check_union_id`,options)
},
// sso登录
getSsoBcakUrl(options) {
return requestPOST(`${process.env.OLSHOP_URL}/common/getSsoCallbackUrl`,options)
} }
} }
\ No newline at end of file
...@@ -2,19 +2,27 @@ ...@@ -2,19 +2,27 @@
<div class="domain"> <div class="domain">
<div class="toCLogin"> <div class="toCLogin">
<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" @click="getUserProfile">微信一键登录</button> <button class="btn" lang="zh_CN" @click="getUserProfile">
微信一键登录
</button>
</div> </div>
</div> </div>
<div class="toCLogin1" v-if="isShowPhone"> <div class="toCLogin1" v-if="isShowPhone">
<div class="btn_info1"> <div class="btn_info1">
<h1>绑定手机号</h1> <h1>绑定手机号</h1>
<span class="hint">检测到您的账号还未绑定手机号,请绑定手机号</span> <span class="hint">检测到您的账号还未绑定手机号,请绑定手机号</span>
<button class="btn" open-type="getPhoneNumber" @getphonenumber="getPhoneNumber">绑定手机号一键绑定</button> <button
class="btn"
open-type="getPhoneNumber"
@getphonenumber="getPhoneNumber"
>
绑定手机号一键绑定
</button>
<div class="btn2" @click="handbindHandle">手动绑定手机号</div> <div class="btn2" @click="handbindHandle">手动绑定手机号</div>
</div> </div>
<div class="layer" @click="isShowPhone=false"></div> <div class="layer" @click="isShowPhone = false"></div>
</div> </div>
</div> </div>
</template> </template>
...@@ -54,44 +62,44 @@ export default { ...@@ -54,44 +62,44 @@ export default {
test_sessionId: "", test_sessionId: "",
test_isHaveUnion: "", test_isHaveUnion: "",
test_unionId: "", test_unionId: "",
fromType:'',//来源类型 mini:小程序跳转到当前登录页 fromType: "", //来源类型 mini:小程序跳转到当前登录页
scene:''//场景 scene: "", //场景
}; };
}, },
onShow() { onShow() {
wx.checkSession({ wx.checkSession({
success : () => { success: () => {
//session_key 未过期,并且在本生命周期一直有效 //session_key 未过期,并且在本生命周期一直有效
wx.login({ wx.login({
success: res => { success: (res) => {
this.code = res.code; this.code = res.code;
}, },
fail: err => { fail: (err) => {
reject(err); reject(err);
}
}) //重新登录
}, },
fail : () => { }); //重新登录
},
fail: () => {
// session_key 已经失效,需要重新执行登录流程 // session_key 已经失效,需要重新执行登录流程
wx.login({ wx.login({
success: res => { success: (res) => {
this.code = res.code; this.code = res.code;
}, },
fail: err => { fail: (err) => {
reject(err); reject(err);
} },
}) //重新登录 }); //重新登录
} },
}) });
}, },
onLoad(options) { onLoad(options) {
Object.assign(this.$data, this.$options.data()); //mpvue 的混合周期 使用小程序生命周期数据未初始化 Object.assign(this.$data, this.$options.data()); //mpvue 的混合周期 使用小程序生命周期数据未初始化
options.scene && (this.scene=options.scene) options.scene && (this.scene = options.scene);
if (options.back) { if (options.back) {
this.backPath = options.back; this.backPath = options.back;
} }
if (options.params) { if (options.params) {
this.defalutBackParams= serialize(options.params); this.defalutBackParams = serialize(options.params);
this.backParams = this.defalutBackParams; this.backParams = this.defalutBackParams;
let params = JSON.parse(options.params); let params = JSON.parse(options.params);
this.fromType = params.fromType; this.fromType = params.fromType;
...@@ -103,18 +111,18 @@ export default { ...@@ -103,18 +111,18 @@ export default {
this.shopName = wx.getStorageSync("shopName"); this.shopName = wx.getStorageSync("shopName");
this.logoUrl = wx.getStorageSync("logoUrl"); this.logoUrl = wx.getStorageSync("logoUrl");
if (!(this.shopName && this.logoUrl)) { if (!(this.shopName && this.logoUrl)) {
shop.getShopInfo().then(res => { shop.getShopInfo().then((res) => {
if (res.data.code == 200) { if (res.data.code == 200) {
this.shopName = res.data.data.shopName; this.shopName = res.data.data.shopName;
this.logoUrl = process.env.IMG_DOMAIN + res.data.data.logoUrl; this.logoUrl = process.env.IMG_DOMAIN + res.data.data.logoUrl;
wx.setStorage({ wx.setStorage({
key: "shopName", key: "shopName",
data: res.data.data.shopName data: res.data.data.shopName,
}); });
wx.setStorage({ wx.setStorage({
key: "logoUrl", key: "logoUrl",
data: process.env.IMG_DOMAIN + res.data.data.logoUrl data: process.env.IMG_DOMAIN + res.data.data.logoUrl,
}); });
} }
}); });
...@@ -123,65 +131,65 @@ export default { ...@@ -123,65 +131,65 @@ export default {
init() { init() {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
login login
.miniLogin({ code: this.code, .miniLogin({
spokesmanRelId : '', code: this.code,
spokesmanGroupId : '', spokesmanRelId: "",
spokesmanShopId : '' spokesmanGroupId: "",
spokesmanShopId: "",
}) })
.then(res => { .then((res) => {
if (res.data.code == 200) { if (res.data.code == 200) {
resolve(res); resolve(res);
} else { } else {
reject(res.data.msg); reject(res.data.msg);
} }
}) })
.catch(err => { .catch((err) => {
reject(err); reject(err);
}); });
}); });
}, },
addRecord(flag) { addRecord(flag) {
console.log(wx.getStorageSync('attractingCustomerChannelId')) console.log(wx.getStorageSync("attractingCustomerChannelId"));
console.log(this.openid) console.log(this.openid);
console.log(99999) console.log(99999);
//埋点引客渠道 //埋点引客渠道
if(wx.getStorageSync('attractingCustomerChannelId')) { if (wx.getStorageSync("attractingCustomerChannelId")) {
indexApi.addRecord( indexApi
{ .addRecord({
attractingCustomersChannelId: wx.getStorageSync('attractingCustomerChannelId'), attractingCustomersChannelId: wx.getStorageSync(
"attractingCustomerChannelId"
),
miniOpenId: this.openid, miniOpenId: this.openid,
registerFlag: 1, registerFlag: 1,
newRegisterFlag: flag?1:0,//1是新注册用户 newRegisterFlag: flag ? 1 : 0, //1是新注册用户
}
).then(ele=>{
wx.setStorageSync('attractingCustomerChannelId','')
}) })
.then((ele) => {
wx.setStorageSync("attractingCustomerChannelId", "");
});
} }
}, },
getUserProfile() { getUserProfile() {
// 推荐使用wx.getUserProfile获取用户信息,开发者每次通过该接口获取用户个人信息均需用户确认 // 推荐使用wx.getUserProfile获取用户信息,开发者每次通过该接口获取用户个人信息均需用户确认
// 开发者妥善保管用户快速填写的头像昵称,避免重复弹窗 // 开发者妥善保管用户快速填写的头像昵称,避免重复弹窗
wx.getUserProfile({ wx.getUserProfile({
desc: '用于完善会员资料', // 声明获取用户个人信息后的用途,后续会展示在弹窗中,请谨慎填写 desc: "用于完善会员资料", // 声明获取用户个人信息后的用途,后续会展示在弹窗中,请谨慎填写
success: (e) => { success: (e) => {
this.init() this.init()
.then(res => { .then((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);
} }
if (res.data.data.isHaveUnion == "true") { if (res.data.data.isHaveUnion == "true") {
//有账号 //有账号
this.backParams += `&sessionid=${ this.backParams += `&sessionid=${res.data.data.sessionId}&needCertified=${res.data.data.NEED_CERTIFIED}`;
res.data.data.sessionId
}&needCertified=${res.data.data.NEED_CERTIFIED}`;
this.NEED_CERTIFIED = res.data.data.NEED_CERTIFIED; this.NEED_CERTIFIED = res.data.data.NEED_CERTIFIED;
wx.setStorage({ wx.setStorage({
key: "sessionid", key: "sessionid",
data: res.data.data.sessionId data: res.data.data.sessionId,
}); });
this.isHaveUnion = true; this.isHaveUnion = true;
...@@ -193,23 +201,23 @@ export default { ...@@ -193,23 +201,23 @@ 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.unionId = res.data.data.unionId || "";
this.isShow = true; this.isShow = true;
//checkLogind //checkLogind
this.checkLogin(e); this.checkLogin(e);
}) })
.catch(err => { .catch((err) => {
console.log("err", err); console.log("err", err);
wx.hideLoading(); wx.hideLoading();
wx.showToast({ title: err, icon: "none" }); wx.showToast({ title: err, icon: "none" });
}); });
} },
}) });
}, },
checkLogin(e) { checkLogin(e) {
this.userInfo = e.userInfo; this.userInfo = e.userInfo;
this.$store.commit('setUserInfo',this.userInfo) this.$store.commit("setUserInfo", this.userInfo);
if (this.isHaveUnion) { if (this.isHaveUnion) {
wx.hideLoading(); wx.hideLoading();
//是会员 直接登录 //是会员 直接登录
...@@ -220,19 +228,17 @@ export default { ...@@ -220,19 +228,17 @@ export default {
if (this.unionId) { if (this.unionId) {
login login
.checkUnionid({ unionId: this.unionId, openId: this.openid }) .checkUnionid({ unionId: this.unionId, openId: this.openid })
.then(res => { .then((res) => {
wx.hideLoading(); wx.hideLoading();
if (res.data.code == 200) { if (res.data.code == 200) {
if (res.data.data.isHaveUnion == "true") { if (res.data.data.isHaveUnion == "true") {
this.NEED_CERTIFIED = res.data.data.NEED_CERTIFIED; this.NEED_CERTIFIED = res.data.data.NEED_CERTIFIED;
this.backParams += `&sessionid=${ this.backParams += `&sessionid=${res.data.data.sessionId}&needCertified=${res.data.data.NEED_CERTIFIED}`;
res.data.data.sessionId
}&needCertified=${res.data.data.NEED_CERTIFIED}`;
wx.setStorage({ wx.setStorage({
key: "sessionid", key: "sessionid",
data: res.data.data.sessionId data: res.data.data.sessionId,
}); });
this.addRecord(false) this.addRecord(false);
// 跳转回小程序页面 // 跳转回小程序页面
this.pushPageType(); this.pushPageType();
// wx.reLaunch({ // wx.reLaunch({
...@@ -243,11 +249,11 @@ export default { ...@@ -243,11 +249,11 @@ export default {
} else { } else {
//不是会员需要绑定手机号 //不是会员需要绑定手机号
this.isShowPhone = true; this.isShowPhone = true;
this.addRecord(true) this.addRecord(true);
} }
} }
}) })
.catch(err => { .catch((err) => {
wx.hideLoading(); wx.hideLoading();
wx.showToast({ title: err, icon: "none" }); wx.showToast({ title: err, icon: "none" });
}); });
...@@ -255,26 +261,36 @@ export default { ...@@ -255,26 +261,36 @@ export default {
wx.hideLoading(); wx.hideLoading();
//不是会员需要绑定手机号 //不是会员需要绑定手机号
this.isShowPhone = true; this.isShowPhone = true;
this.addRecord(true) this.addRecord(true);
} }
} }
}, },
// 是否跳转h5或小程序 // 是否跳转h5或小程序
pushPageType(){ pushPageType() {
if(this.fromType=='mini'){ console.log('2700000',this.backPath)
if (this.fromType == "mini") {
wx.navigateBack({ wx.navigateBack({
delta: 1 delta: 1,
}); });
}else if (this.scene=='sso') { } else if (this.scene == "sso") {
let op = {
callbackUrl: this.backPath,
email: "",
fromAppid: "VsEOuDJqBnGNyXZJWCQS",
mobilephone: '15821335747',
toAppid: "hgFTLLhgnBmeOyCkcbyv",//道可
wxAvatarUrl: this.userInfo.avatarUrl,
};
login.getSsoBcakUrl(op).then((res) => {
wx.redirectTo({ wx.redirectTo({
url: `../wxArticle/main?link=${this.backPath}`, url: `../wxArticle/main?link=${res.data.data}`,
});
}); });
}else{ } else {
wx.reLaunch({ wx.reLaunch({
url: `../index/main?from=login&backpath=${ url: `../index/main?from=login&backpath=${
this.backPath this.backPath
}&params=${encodeURIComponent(this.backParams)}` }&params=${encodeURIComponent(this.backParams)}`,
}); });
} }
}, },
...@@ -297,7 +313,7 @@ export default { ...@@ -297,7 +313,7 @@ export default {
fail: () => { fail: () => {
// session_key 已经失效,需要重新执行登录流程 // session_key 已经失效,需要重新执行登录流程
// wx.login() //重新登录 // wx.login() //重新登录
} },
}); });
}, },
bindUser() { bindUser() {
...@@ -312,7 +328,8 @@ export default { ...@@ -312,7 +328,8 @@ export default {
province: this.userInfo.province, province: this.userInfo.province,
city: this.userInfo.city, city: this.userInfo.city,
otherPhone: 0, otherPhone: 0,
articleId: wx.getStorageSync(this.$store.state.mixid+"articleId") || '' articleId:
wx.getStorageSync(this.$store.state.mixid + "articleId") || "",
}; };
if (this.$store.state.spokesmanGroupId != "") { if (this.$store.state.spokesmanGroupId != "") {
query.spokesmanRelId = this.$store.state.spokesmanRelId; query.spokesmanRelId = this.$store.state.spokesmanRelId;
...@@ -323,17 +340,15 @@ export default { ...@@ -323,17 +340,15 @@ export default {
console.log(query, "query"); console.log(query, "query");
login login
.bindUser(query) .bindUser(query)
.then(res => { .then((res) => {
//绑定成功 //绑定成功
if (res.data.code == 200) { if (res.data.code == 200) {
wx.setStorageSync(this.$store.state.mixid+'articleId',false) wx.setStorageSync(this.$store.state.mixid + "articleId", false);
this.NEED_CERTIFIED = res.data.data.NEED_CERTIFIED; this.NEED_CERTIFIED = res.data.data.NEED_CERTIFIED;
this.backParams += `&sessionid=${ this.backParams += `&sessionid=${res.data.data.sessionId}&needCertified=${res.data.data.NEED_CERTIFIED}`;
res.data.data.sessionId
}&needCertified=${res.data.data.NEED_CERTIFIED}`;
wx.setStorage({ wx.setStorage({
key: "sessionid", key: "sessionid",
data: res.data.data.sessionId data: res.data.data.sessionId,
}); });
// 跳转回小程序页面 // 跳转回小程序页面
this.pushPageType(); this.pushPageType();
...@@ -344,7 +359,7 @@ export default { ...@@ -344,7 +359,7 @@ export default {
// }); // });
} }
}) })
.catch(err => { .catch((err) => {
console.log(err, "bindusererr"); console.log(err, "bindusererr");
}); });
}, },
...@@ -360,7 +375,7 @@ export default { ...@@ -360,7 +375,7 @@ export default {
eLogin() { eLogin() {
//企业员工登录 //企业员工登录
wx.redirectTo({ wx.redirectTo({
url: `../index/main?from=login&backpath=/login/accountLogin` url: `../index/main?from=login&backpath=/login/accountLogin`,
}); });
}, },
handbindHandle() { handbindHandle() {
...@@ -372,16 +387,16 @@ export default { ...@@ -372,16 +387,16 @@ export default {
nickname: this.userInfo.nickName, nickname: this.userInfo.nickName,
country: this.userInfo.country, country: this.userInfo.country,
province: this.userInfo.province, province: this.userInfo.province,
city: this.userInfo.city city: this.userInfo.city,
}; };
//绑定手机号 //绑定手机号
wx.navigateTo({ wx.navigateTo({
url: `../index/main?from=login&backpath=/login/wxRegister&params=${encodeURIComponent( url: `../index/main?from=login&backpath=/login/wxRegister&params=${encodeURIComponent(
serialize(query) serialize(query)
)}` )}`,
}); });
} }
} },
}; };
</script> </script>
...@@ -449,7 +464,7 @@ export default { ...@@ -449,7 +464,7 @@ export default {
margin: 10px 15px; margin: 10px 15px;
font-weight: normal; font-weight: normal;
} }
.hint{ .hint {
color: #888; color: #888;
font-size: 15px; font-size: 15px;
text-align: center; text-align: center;
...@@ -458,8 +473,8 @@ export default { ...@@ -458,8 +473,8 @@ export default {
} }
.btn { .btn {
margin-top: 25px; margin-top: 25px;
background-color: #5CB83B; background-color: #5cb83b;
color: #FFFAFA; color: #fffafa;
height: 45px; height: 45px;
border-radius: 22.5px; border-radius: 22.5px;
font-size: 15px; font-size: 15px;
......
...@@ -26,38 +26,42 @@ export default { ...@@ -26,38 +26,42 @@ export default {
}; };
}, },
async onLoad(options) { async onLoad(options) {
console.log('wxarticle',options)
// options.scene="64a77cd6aeac4c1db46e3f7d53596fe6"
if (options.link) { if (options.link) {
this.link = decodeURIComponent(options.link); this.link = decodeURIComponent(options.link);
} else if (options.scene) { } else if (options.scene) {
//扫码 //扫码
let data = await this.getParams( let data = await this.getParams(options.scene);
options.scene || "959ce6ac97cf4f43a1759eb41ec12798" if (data.sso) {
); if (!wx.getStorageSync("sessionid")) {
if (data.sso == "sso" && !wx.getStorageSync("sessionid")) { wx.redirectTo({
url: `../login/main?scene=sso&back=${data.link}`,
});
}else{
let link = decodeURIComponent(data.link).replace( let link = decodeURIComponent(data.link).replace(
"${token}", "${token}",
wx.getStorageSync("sessionid") wx.getStorageSync("sessionid")
); );
wx.redirectTo({ this.link = decodeURIComponent(link);
url: `../login/main?scene=sso&back=${link}`, }
});
} else {
this.link = data.link;
} }
} }
}, },
methods: { methods: {
getParams(options) { getParams(options) {
return indexApi return new Promise((resolve, reject) => {
indexApi
.getShareSceneRecord(options) .getShareSceneRecord(options)
.then((res) => { .then((res) => {
if (res.data.code == "200") { if (res.data.code == "200") {
console.log("5666666", res);
let scene = JSON.parse(res.data.data.scene); let scene = JSON.parse(res.data.data.scene);
resolve(scene.link); resolve(scene);
} }
}) })
.catch((err) => {}); .catch((err) => {});
});
}, },
//加载成功 //加载成功
handleLoad() { handleLoad() {
......
{ {
"navigationBarTitleText": "文章"
} }
\ No newline at end of file
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