94c1e6a3
liuqimichale
微信公众号 个人页面集合
|
1
2
3
4
5
6
7
8
9
10
|
<template>
<div>
<mt-field label="手机号" placeholder="请输入正确的手机号" type="tel" v-model="phone" :attr="{ maxlength: 13 }"></mt-field>
<mt-field label="验证码" v-model="codeText">
<div class="getCode" @click="getCode">{{timeNum}}</div>
</mt-field>
<div style="margin-top: 34px" class="leftRightPadding">
|
6ea1f7ef
刘淇
个人中心
|
11
|
<van-button type="info" block @click="bindPhoneHandle">绑定</van-button>
|
94c1e6a3
liuqimichale
微信公众号 个人页面集合
|
12
13
14
15
16
|
</div>
</div>
</template>
<script>
|
6ea1f7ef
刘淇
个人中心
|
17
18
|
import { sendverificode, bindCustByOpenId, getOpenIdByCode, getTokenByOpenId } from "@/api/getUserIfo";
|
94c1e6a3
liuqimichale
微信公众号 个人页面集合
|
19
|
export default {
|
6ea1f7ef
刘淇
个人中心
|
20
|
name: "binDing",
|
94c1e6a3
liuqimichale
微信公众号 个人页面集合
|
21
22
|
data() {
return {
|
6ea1f7ef
刘淇
个人中心
|
23
24
25
|
codeText: "",
phone: "",
timeText: "获取验证码",
|
94c1e6a3
liuqimichale
微信公众号 个人页面集合
|
26
|
timeNum: 60,
|
6ea1f7ef
刘淇
个人中心
|
27
28
|
webAppCode: ""
};
|
94c1e6a3
liuqimichale
微信公众号 个人页面集合
|
29
|
},
|
6ea1f7ef
刘淇
个人中心
|
30
31
|
created() {
this.timeNum = this.timeText;
|
0849334c
刘淇
宣化聚合支付
|
32
|
// this.webAppCode = this.getWxCode(); // 正式打开注释
|
94c1e6a3
liuqimichale
微信公众号 个人页面集合
|
33
34
|
},
methods: {
|
6ea1f7ef
刘淇
个人中心
|
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
|
getWxCode() {
var appID = this.$utils.myVxAppId;
var code = this.getUrlParam("code");
var local = window.location.href;
if (code == null || code === "") {
window.location.href = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=" + appID + "&redirect_uri=" + encodeURIComponent(local) + "&response_type=code&scope=snsapi_userinfo&state=1#wechat_redirect";
} else {
return code;
}
},
getUrlParam(name) { // 获取url里面的参数
var reg = new RegExp('(^|&)' + name + '=([^&]*)(&|$)');
var r = window.location.search.substr(1).match(reg)
if (r != null) return unescape(r[2])
return null
},
getCode: function() {
var _this = this;
|
94c1e6a3
liuqimichale
微信公众号 个人页面集合
|
53
|
// this.timeText = this.timeNum+'S'
|
6ea1f7ef
刘淇
个人中心
|
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
|
const reg = /^1[3-9]\d{9}$/;
if (reg.test(this.phone)) {
_this.sendverificode();
let Num = 60;
var timer = setInterval(function() {
_this.timeNum = Num-- + "s";
if (Num == -1) {
_this.timeNum = "获取验证码";
clearInterval(timer);
}
}, 1000);
} else {
this.$toast("请输入正确手机号");
}
},
sendverificode() {
let jsondata = {
phone: this.phone
};
jsondata.sign = this.$utils.signObject(jsondata);
|
6ea1f7ef
刘淇
个人中心
|
74
75
76
77
78
79
80
81
|
sendverificode(jsondata).then(response => {
console.log(response);
this.$toast("获取验证码成功");
});
},
bindPhoneHandle() {
const reg = /^1[3-9]\d{9}$/;
if (reg.test(this.phone)) {
|
0849334c
刘淇
宣化聚合支付
|
82
83
84
|
// this.getOpenIdByCode(); // 获取openid
this.bindCustByOpenId(this.$route.query.openid)
|
6ea1f7ef
刘淇
个人中心
|
85
86
87
88
89
90
91
|
} else {
this.$toast("请输入正确手机号");
}
},
getOpenIdByCode() { // 获取openid
|
94a4ee91
刘淇
宣化 聚合支付
|
92
|
// this.bindCustByOpenId() // 正式注释
|
6ea1f7ef
刘淇
个人中心
|
93
94
95
96
97
|
// 正式打开注释
|
94a4ee91
刘淇
宣化 聚合支付
|
98
99
100
101
102
103
104
105
106
107
108
109
|
let jsondata = {
appId: this.$utils.myVxAppId,
code: this.webAppCode
};
jsondata.sign = this.$utils.signObject(jsondata);
console.log("停车记录传参 " + JSON.stringify(jsondata));
getOpenIdByCode(jsondata).then(response => {
if(response.code=='0'){
let openId = response.data
this.bindCustByOpenId(openId) // 获取token和用户手机号
}
});
|
6ea1f7ef
刘淇
个人中心
|
110
|
},
|
94a4ee91
刘淇
宣化 聚合支付
|
111
|
bindCustByOpenId(openId){ //
|
6ea1f7ef
刘淇
个人中心
|
112
113
114
|
let jsondata = {
phoneNum: this.phone,
verifyCode: this.codeText,
|
94a4ee91
刘淇
宣化 聚合支付
|
115
116
|
openid: openId // 正式打开注释
// openid:'oWw3o5rY_bFsiT_nFd2CEQWGZfhs' // 正式注释
|
6ea1f7ef
刘淇
个人中心
|
117
118
|
};
jsondata.sign = this.$utils.signObject(jsondata);
|
6ea1f7ef
刘淇
个人中心
|
119
120
|
bindCustByOpenId(jsondata).then(response => {
if(response.code=='0'){
|
94a4ee91
刘淇
宣化 聚合支付
|
121
|
this.getTokenByOpenId(openId) // 获取token和用户手机号
|
6ea1f7ef
刘淇
个人中心
|
122
123
124
125
126
127
128
129
|
}else if(response.code=='1017'||response.code==1017){
this.$toast("已经绑定过");
}else{
this.$toast("绑定失败");
}
});
},
|
94a4ee91
刘淇
宣化 聚合支付
|
130
|
getTokenByOpenId(openId){ // 获取token和用户手机号
|
6ea1f7ef
刘淇
个人中心
|
131
|
let jsondata = {
|
94a4ee91
刘淇
宣化 聚合支付
|
132
133
|
openid:openId // 正式打开注释
// openid:'oWw3o5rY_bFsiT_nFd2CEQWGZfhs' // 正式注释
|
6ea1f7ef
刘淇
个人中心
|
134
135
|
};
jsondata.sign = this.$utils.signObject(jsondata);
|
6ea1f7ef
刘淇
个人中心
|
136
137
138
139
140
141
|
getTokenByOpenId(jsondata).then(response => {
if(response.code=='0'){
this.$toast("亲,您已绑定成功!");
localStorage.setItem('userToken',response.data.token)
localStorage.setItem('userPhoneNum',response.data.phoneNum)
this.$router.push({
|
0849334c
刘淇
宣化聚合支付
|
142
143
144
145
|
name: "selfNav",
query:{
openId:openId
}
|
6ea1f7ef
刘淇
个人中心
|
146
147
|
}
);
|
94c1e6a3
liuqimichale
微信公众号 个人页面集合
|
148
|
}
|
6ea1f7ef
刘淇
个人中心
|
149
|
});
|
94c1e6a3
liuqimichale
微信公众号 个人页面集合
|
150
151
|
}
}
|
6ea1f7ef
刘淇
个人中心
|
152
|
};
|
94c1e6a3
liuqimichale
微信公众号 个人页面集合
|
153
154
155
156
157
158
159
160
161
162
163
164
|
</script>
<style scoped lang="scss">
.getCode {
width: 100px;
height: 48px;
line-height: 48px;
background: #ef4f4f;
color: #fff;
text-align: center;
}
</style>
|