binding_info.js
7.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
var e = getApp(),app=e, a = e.request, t = e.globalData.setting,os=t, i = require("../../../utils/common.js");
Page({
data: {
url: t.url,
iurl: t.imghost,
nickName: "",
userHeadPic: "",
isRegist: !1,
bindMobile: "",
bindCode: "",
regMobile: "",
regCode: "",
regPwd: "",
isAgree: !1,
canGetCode: !1,
config:null,
store: null,
imghots: os.imghost,
gettime:0,
},
onLoad: function(e) {
var th=this;
app.getConfig(function (e) {
th.setData({ store: e });
})
app.getConfig2(function (e) {
var cf = JSON.parse(e.sms_send_type);
th.setData({ config: cf });
console.log(th.data.config);
})
},
account: function() {
this.setData({
isRegist: !1
});
},
regist: function() {
this.setData({
isRegist: !0
});
},
setMobile: function(e) {
this.data.bindMobile = e.detail.value;
},
setCode: function(e) {
this.data.bindCode = e.detail.value;
},
//---获取短信验证码---
getCode: function(t) {
var th=this;
if ("" != this.data.bindMobile) {
var s = this;
a.post("/api/weshop/smslog/sendsms", {
data: {
mobile: this.data.bindMobile,
store_id: os.stoid,
wxopenid: app.globalData.openid,
},
success: function(e) {
if(e.data.code==0){
th.setData({ gettime: th.data.config.time_out, canGetCode:1});
th.setInt();
}else{
e.showWarning(e.data.msg);
}
}
});
} else e.showWarning("请输入手机号码");
},
//----发送验证码的推送时间倒计时---
setInt:function(){
var th=this;
var it=setInterval(function(){
var ti = th.data.gettime-1;
if (ti<=0){
th.setData({ gettime:0, canGetCode: !1 });
clearInterval(it);
}
else{
th.setData({ gettime: ti,});
}
},1000);
},
setRegMobile: function(e) {
this.data.regMobile = e.detail.value;
},
setRegPwd: function(e) {
this.data.regPwd = e.detail.value;
},
setRegCode: function(e) {
this.data.regCode = e.detail.value;
},
getRegCode: function(t) {
if ("" != this.data.regMobile) {
var s = this;
a.post("/Home/Api/checkRegMobile", {
data: {
mobile: this.data.regMobile
},
success: function(e) {
i.sendBindSmsCode(s.data.regMobile);
}
});
} else e.showWarning("请输入手机号码");
},
check: function() {
this.setData({
isAgree: !this.data.isAgree
});
},
bindAccount: function() {
var t = this;
var r = getApp().globalData.getu;
var openid = getApp().globalData.openid;
"" != this.data.bindMobile ? "" != this.data.bindCode ? a.get("/api/weshop/users/thirdLogin", {
data: {
mobile: t.data.bindMobile,
code: t.data.bindCode,
openid: openid,
nickname: r.nickName,
head_pic: r.avatarUrl,
sex: r.gender,
store_id:os.stoid,
},
success: function(a) {
if(a.data.code==0){
wx.setStorageSync("isAuth", !0),
e.globalData.userInfo = a.data.data,
e.globalData.user_id = e.globalData.userInfo.user_id, e.globalData.userInfo.head_pic = i.getFullUrl(e.globalData.userInfo.head_pic),
"function" == typeof cb && cb(e.globalData.userInfo, e.globalData.wechatUser);
e.showWarning("绑定成功");
setTimeout(function(){
wx.navigateTo({
url: '/pages/user/index/index',
})
},1000);
}else{
e.showWarning("请输入验证码")
}
}
}) : e.showWarning("请输入验证码") : e.showWarning("请输入手机号码");
},
bindReg: function() {
var t = this;
if( "" != this.data.regMobile ){
e.showWarning("请输入手机号码"); return false;
}else if( "" != this.data.regCode){
e.showWarning("请输入验证码"); return false;
}else {
var openid = getApp().globalData.openid;
var r = getApp().globalData.getu;
a.post("/api/weshop/users/thirdLogin", {
data: {
mobile: t.data.regMobile,
verify_code: t.data.regCode,
openid: openid,
nickname: r.nickName,
head_pic: r.avatarUrl,
sex: r.gender,
},
success: function(a) {
console.log("thirdLogin");
console.log(e);
if (e.data.code == 0) {
app.globalData.user_id = e.data.data.user_id;
} else {
return app.showWarning("授权登入失败!");
}
wx.setStorageSync("isAuth", !0), a.globalData.userInfo = e.data.data, a.globalData.userInfo.head_pic = t.getFullUrl(a.globalData.userInfo.head_pic);
wx.navigateBack({ delta: 1 })
}
})
}
}
});
function randomNum(min, max) {
return Math.floor(Math.random() * (max - min) + min);
}
/**生成一个随机色**/
function randomColor(min, max) {
var r = randomNum(min, max);
var g = randomNum(min, max);
var b = randomNum(min, max);
return "rgb(" + r + "," + g + "," + b + ")";
}
/**绘制验证码图片**/
function drawPic(that) {
ctx = wx.createCanvasContext('canvas');
/**绘制背景色**/
ctx.fillStyle = randomColor(180, 240); //颜色若太深可能导致看不清
ctx.fillRect(0, 0, 90, 28)
/**绘制文字**/
var arr;
var text = '';
var str = 'ABCEFGHJKLMNPQRSTWXY123456789';
for (var i = 0; i < 4; i++) {
var txt = str[randomNum(0, str.length)];
ctx.fillStyle = randomColor(50, 160); //随机生成字体颜色
ctx.font = randomNum(20, 26) + 'px SimHei'; //随机生成字体大小
var x = 5 + i * 20;
var y = randomNum(20, 25);
var deg = randomNum(-20, 20);
//修改坐标原点和旋转角度
ctx.translate(x, y);
ctx.rotate(deg * Math.PI / 180);
ctx.fillText(txt, 5, 0);
text = text + txt;
//恢复坐标原点和旋转角度
ctx.rotate(-deg * Math.PI / 180);
ctx.translate(-x, -y);
}
/**绘制干扰线**/
for (var i = 0; i < 4; i++) {
ctx.strokeStyle = randomColor(40, 180);
ctx.beginPath();
ctx.moveTo(randomNum(0, 90), randomNum(0, 28));
ctx.lineTo(randomNum(0, 90), randomNum(0, 28));
ctx.stroke();
}
/**绘制干扰点**/
for (var i = 0; i < 20; i++) {
ctx.fillStyle = randomColor(0, 255);
ctx.beginPath();
ctx.arc(randomNum(0, 90), randomNum(0, 28), 1, 0, 2 * Math.PI);
ctx.fill();
}
ctx.draw(false, function () {
that.setData({
text: text
})
});
}