生成4位数字验证码
位数字验证码
defcreatePhoneCode(session):
chars=[‘0’,‘1’,‘2’,‘3’,‘4’,‘5’,‘6’,‘7’,‘8’,‘9’]
x=random.choice(chars),random.choice(chars),random.choice(chars),random.choice(chars)
verifyCode="".join(x)
session[“phoneVerifyCode”]={“time”:int(time.time()),“code”:verifyCode}
returnverifyCode
2、发送给外部短信接口(
、发送给外部短信接口(post方式)
方式)
defsendTelMsg(msg,phoneID):
SendTelMsgUrl=“http://www.810086.com.cn/jk.aspx”
params={“zh”:“china”,“mm”:“china@10086”,
“hm”:phoneID,“nr”:msg,“sms_type”:88}
postData=urllib.urlencode(params)
req=urllib2.Request(SendTelMsgUrl,postData)
req.add_header(‘Content-Type’,“application/x-www-form-urlencoded”)
respone=urllib2.urlopen(req)
res=respone.read()
returnres
其中session参数是djangourls.py后台方法以request.session传入
3、前端
、前端js
KaTeX parse error: Expected '}', got 'EOF' at end of input: …varuserPhoneEl=(“input[name=phoneNum]”);
varuserPhone=$.trim(userPhoneEl.val());
if(userPhone==""){
alert(“请填写号码!”);
return;
}
KaTeX parse error: Expected '}', got 'EOF' at end of input: …(msg); varddEl=(self).siblings(“dd.showTag”);
if(msg==“ok”){
ddEl.find(“span”).hide();
ddEl.find(“span[name=success]”).show();
}else{
ddEl.find(“span”).hide();
ddEl.find(“span[name=error]”).show();
}
})
.error(function(msg){
console.info(msg);
});
varstep=60;
$(this).attr(“disabled”,true);
$(this).html(“重新发送”+step);
varinterThread=setInterval(function(){
step-=1;
$(self).html(“重新发送”+step);
if(step<=0){
$(self).removeAttr(“disabled”);
$(self).html(“获取验证码”);
clearInterval(interThread);
}
},1000);
});
Android在收到短信后会发送一个Action为android.provider.Telephony.SMS_RECEIVED的广播,所以我们只需要写个类继承
BroadcastReceiver就可以很容易地监听到短信。
packagecom.example.getsms;
importandroid.content.BroadcastReceiver;
importandroid.content.ContentResolver;
importandroid.content.Context;
importandroid.content.Intent;
importandroid.os.Bundle;
importandroid.telephony.SmsMessage;
importandroid.text.TextUtils;
importandroid.util.Log;
publicclassSmsInterceptReceiverextendsBroadcastReceiver{
privatefinalStringTAG=“SmsRec”;
privatestaticfinalStringSMS_EXTRA_NAME=“pdus”;
@Override
publicvoidonReceive(Contextcontext,Intentintent){
//TODOAuto-generatedmethodstub
Stringmessage="";
Log.e(TAG,“freemessage”);
Bundleextras=intent.getExtras();
if(extras!=null){
try{
Object[]smsExtra=(Object[])extras.get(SMS_EXTRA_NAME);
ContentResolvercontentResolver=context.getContentResolver();
Log.e(TAG,“freemessage”);
for(inti=0;i
SmsMessagesms=SmsMessage.createFromPdu((byte[])smsExtra[i]);
Stringbody=sms.getMessageBody().toString();
message+=body;
}
Log.e(TAG,“freemessage:”+message);
}catch(Exceptione){
//TODO:handleexception
Log.e(TAG,e.getMessage());
}
}
}
}
AndroidManifest.xml里注册一下接收器:
receiverandroid:name=".SmsInterceptReceiver"
actionandroid:name=“android.provider.Telephony.SMS_RECEIVED”/
添加权限:
uses-permissionandroid:name=“android.permission.RECEIVE_SMS”/
python代码,主要通过adblog来获取apk包所截取的短信信息,然后进行分析后既可使用。
author=‘guozhenhua’
#coding=utf-8
importurllib2
importos,time
#解析短信验证码
os.system(“adblogcat-c”)
cmd=“adblogcat-d|findstrE/SmsRec”
#time.sleep(30);
while(1):
smscode=os.popen(cmd).read()
#printsmscode
if(smscode!=""):
smscode=smscode.split(“验证码:”)[1].split(",")[0]
break;
print"验证码是:"+smscode
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)