Commit f2a0ac00 by 程默

第三方跳转 sso

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