Commit 18ebed80 authored by leiqingsong's avatar leiqingsong

大转盘身份验证

parent 305c6a7e
<template>
<van-dialog v-if="showAuth" v-model="show" id="wx-auth" title="微信授权" show-cancel-button
@confirm="handleConfirm"
>
<img class="logo" src="/img/photo.png" alt="logo" />
<div class="small-tips">
<p>为您提供优质服务,亿百分需要获取以下信息</p>
<p>&middot; 您的公开信息(昵称、头像等)</p>
</div>
</van-dialog>
</template>
<script>
export default {
name: "wxAuth",
components: {},
props: {
showAuth: {
type: Boolean,
default: false
}
},
data() {
return {
show: true
};
},
methods: {
handleConfirm() {
this.$emit('confirm');
}
}
};
</script>
<style lang="scss">
#wx-auth {
.logo {
width: 20%;
margin: 15px auto;
display: block;
border-radius: 50%;
}
.small-tips {
margin-left: 15px;
p {
padding: 5px 10px;
}
p:first-child {
font-size: 14px;
color: #333;
}
p:last-child {
font-size: 12px;
color: #ccc;
}
}
}
</style>
......@@ -69,16 +69,23 @@
</div>
</template>
<div class="btn-share" :style="type === 'coupon'? 'bottom: 0': ''" @click="handleShare">立即分享</div>
<wx-auth :show-auth="showAuthDialog" @confirm="handleCheckAuth"></wx-auth>
</div>
</template>
<script>
import wxAuth from "@/components/wxAuth";
export default {
name: "active-detail",
components: {},
components: { wxAuth },
data() {
return {
code: '',
showAuthDialog: false,
nowUrl: "",
userId: "",
code: "",
active_id: "",
type: "coupon",
freeze: false,
rolling: false,
......@@ -119,10 +126,23 @@ export default {
};
},
created() {
console.log("活动详情1");
window.console.log("活动详情2");
console.log("url", location.href);
this.active_id = this.$route.query.id;
this.type = this.$route.query.type;
// 检测用户身份
// 获取code
this.zReadyUserId()
console.log("query", this.$route.query);
// 验证用户是否登录
if (!sessionStorage.getItem("userId")) {
// 1.获取code
if (this.$route.query.code === undefined) {
this.showAuthDialog = true;
} else {
console.log("code", this.$route.query.code);
// 拿code 换取access_token
this.getAccessToken();
}
}
},
watch: {
prizeNumber() {
......@@ -140,31 +160,35 @@ export default {
}
},
methods: {
zReadyUserId() {
if (this.$route.query.code === undefined) {
alert("没code");
console.log('code', this.$route.query.code);
this.zTestPreAuthCode();
} else {
alert("有code");
// this.zTestGetNowUrlInfo();
// this.zTestGetUserInfoByOldToken();
}
getAccessToken() {
const base = {
baseUrl: "https://api.weixin.qq.com/sns/oauth2/access_token?",
appId: "ww4df265003b43fa0d",
secret: "kF8_-TZE2qad9OMaE2wYAED5rKjOb3Y5IUhHFLHVQAo",
code: this.code,
grant_type: "authorization_code"
};
},
handleCheckAuth() {
this.showAuthDialog = false;
this.getAuthCode();
},
// 获取code
zTestPreAuthCode() {
getAuthCode() {
// alert('获取code')
const basicInfo = {
head: "https://open.weixin.qq.com/connect/oauth2/authorize?",
// appId: "wwd1cdbca7b8b2b6c4",
appId: "ww4df265003b43fa0d",
redirectUrI: encodeURIComponent("oysales.oywanhao.com:8087/activeDetail?id=2&type=wheel"),
redirectUrI: encodeURIComponent(
`oysales.oywanhao.com:8087/activeDetail?id=${this.active_id}&type=${this.type}`
),
responseType: "code",
scope: "snsapi_base",
state: "ztest",
tail: "#wechat_redirect"
};
console.log("redir_url", basicInfo.redirectUrI);
let url =
basicInfo.head +
"appid=" +
......@@ -180,6 +204,68 @@ export default {
basicInfo.tail;
window.location.href = url;
},
getUserInfo() {
let headerData = {
agentId: "1000033",
corpId: "ww4df265003b43fa0d"
};
axios({
url:
"http://139.155.48.151:8085/workWx/auth/user/get?userId=" +
this.userId,
method: "get",
headers: headerData
})
.then(res => {
window.console.log("用户信息", res);
})
.catch(err => {
console.log(err);
});
},
getUserId() {
if (this.$route.query.code === undefined) {
alert("没code");
this.zTestPreAuthCode();
} else {
alert("有code");
this.zTestGetNowUrlInfo();
this.zTestGetUserInfoByOldToken();
}
},
zTestGetNowUrlInfo() {
this.nowUrl = JSON.stringify(this.$route.query);
this.code = String(this.$route.query.code);
console.log("nowUrl", this.nowUrl);
console.log("code", this.code);
},
zTestGetUserInfoByOldToken() {
let postData = {
code: this.code
};
let headerData = {
agentId: "1000033",
corpId: "ww4df265003b43fa0d"
};
this.zcache.userInfoResOld = "PostData:" + JSON.stringify(postData);
axios({
url:
"http://139.155.48.151:8085/workWx/auth/oauth2/getUserInfo?code=" +
this.code,
method: "post",
headers: headerData
})
.then(res => {
alert("获取用户信息接口成功");
this.userId = String(res.data.data.userId);
this.getUserInfo();
})
.catch(err => {
console.log(err);
});
},
Start_Game() {
this.rolling = true;
const { wheelDeg, prizeList } = this;
......
......@@ -208,7 +208,7 @@ export default {
},
created() {
this.checkNowMenuBar();
// this.zReadyUserId()
this.zReadyUserId()
this.zTestGetNowUrlInfo();
// this.oyStallCode = sessionStorage.getItem('oyStallCode')
// this.userId = sessionStorage.getItem('userId')
......
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