binding.js
5.48 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
var hisurl = '';
var func = {
wait:60,
timeFlag:true,
statusFlag:true,
loginh:'',
openid:'',
token:'',
//1.获取验证码
getRandCode:function(){
$(document).on('click','#get_code',function(){
var mobileVal = $('#bind_mobile').val();
// if(/^1[34578]\d{9}$/.test(mobileVal)){
if(mobileVal.length == 11){
if(func.timeFlag){
func.time($(this));
}else{
return false;
}
//发送验证码
//alert('openid '+func.openid+" fs");
func.sendRandCode(mobileVal);
}else{
$.toptip('亲!手机号不正确', 3000, 'error'); //设置显示时间
}
});
},
//2.倒计时
time:function(o){
if (func.wait == 0) {
o.attr("disabled",false);
o.html("获取验证码");
func.timeFlag = true;
func.wait = 60;
} else {
func.wait--;
func.timeFlag = false;
o.attr("disabled", true);
o.html("已发送" + func.wait + "S");
setTimeout(function() {
func.time(o)
},1000)
}
},
//3.发送验证码
sendRandCode:function(phone){
//alert('openid '+func.openid);
var salt = jsajax.salt(32);
var sorts = [
{keyname:'phone',value:phone},
{keyname:'salt',value:salt},
{keyname:'app_id',value:'0eca8f5373ca4866aec2f8e9d9367104'},
{keyname:'deviceInfo',value:'BC0703A4-AFB0-4B51-9089-9B7487C0CC6E'},
{keyname:'sign_type',value:"md5"},
];
var md5sign = jsajax.getsign(sorts);
md5sign=md5sign.toUpperCase();
var jsondata = {
phone : phone,
salt : salt,
app_id : '0eca8f5373ca4866aec2f8e9d9367104',
sign : md5sign,
deviceInfo:'BC0703A4-AFB0-4B51-9089-9B7487C0CC6E',
sign_type : "md5"
}
jsondata = JSON.stringify(jsondata);
$.ajax({
url:mUrl.sendRandCode,
async:false,
type:'POST',
dataType:'json',
data:jsondata,
contentType:'application/json;charset=utf-8',
success:function(data){
console.log(JSON.stringify(data));
//var str = JSON.stringify(data);
// alert("success"+str);
},
error:function(data){
//var str = JSON.stringify(data);
//alert("err"+str);
}
});
},
//绑定用户手机号
bindingPhone:function(){
$(document).on('click','#binging_btn',function(){
var mobileVal = $('#bind_mobile').val();//用户手机号
var randCode = $('#verification_code').val();
var openid = mUrl.GetOpenid();
if(appid == null || appid == ""){
$.alert("亲!绑定失败,请重新尝试绑定");
return false;
}
if(mobileVal == null || mobileVal ==''){
$.toptip('亲!请输入手机号', 3000, 'error'); //设置显示时间
return false;
}
// if(!(/^1[34578]\d{9}$/.test(mobileVal))){
if(mobileVal.length != 11){
$.toptip('亲!手机号不正确', 3000, 'error'); //设置显示时间
return false;
}
if(randCode == null || randCode ==""){
$.toptip('亲!请输入验证码', 3000, 'error'); //设置显示时间
return false;
}
var jsondata = {
phoneNum:mobileVal,
verifyCode:randCode,
openid:openid
}
jsondata = JSON.stringify(jsondata);
console.log('请求数据 '+jsondata);
jsajax.defaultReq(
mUrl.bindphone,//mUrl.sendRandCode,
jsondata,
function(data){
//alert(JSON.stringify(data));
console.log(JSON.stringify(data));
if(data.code==0||data.code=='0'){
$.alert('亲,您已绑定成功!','成功', function() {
var datas = data.data;
var urll = document.referrer;
jsajax.gett(openid,function(n){
window.location.href = document.referrer;
});
});
}else{
if(data.code==1017||data.code=='1017'){
$.alert('已经绑定过', function() {
var urll = document.referrer;
jsajax.gett(openid,function(n){
window.location.href = document.referrer;
});
});
}else{
$.alert('亲,请重新绑定!','失败', function() {
return false;
});
}
}
}
);
});
},
//实时监听验证码输入框中的信息
vcode:function(){
$(document).on('keyup','#verification_code',function(){
var mobileVal = $('#bind_mobile').val();//用户手机号
var tval = this.value;
if(tval.length==6){
// if(/^1[34578]\d{9}$/.test(mobileVal)){
if(mobileVal.length == 11){
$('#binging_btn').removeClass('weui-btn_disabled');
$("#binging_btn").removeAttr('disabled');
}else{
$.toptip('亲!手机号不正确', 3000, 'error');//设置显示时间
}
}else{
$('#binging_btn').addClass('weui-btn_disabled');
}
});
},
};
//监听浏览器返回
$(function(){
func.getRandCode();
func.bindingPhone();
func.vcode();
window.addEventListener("popstate", function(e) {
//alert("我监听到了浏览器的返回按钮事件啦");//根据自己的需求实现自己的功能
window.location.back();
//window.location.href=mUrl.Uri+'/WEB-INF/pages/mylist.html?openid='+func.openid+"&token="+func.token+"&";
}, false);
});