安卓app怎样获取短信验证码自动输入
拥有18年软件开发和IT教学经验。曾任多家上市公司技术总监、架构师、项目经理、高级软件工程师等职务。 网络人气名人讲师,...
监听短信数据库的变化,增加时获取到短信再提取相应的验证码。
这个你要自己写吗? 我建议你直接调用短信平台的接口不就可以了吗?
短信发送
//接口地址String url = "http://183.203.28.5:9000/HttpSmsMt";//下发时间String mttime = new SimpleDateFormat("yyyyMMddHHmmss").format(new Date());Map<String, String> param = new HashMap<String, String>();param.put("name", "用户帐号");param.put("pwd", Tools.MD5("用户密码"+mttime));param.put("content", URLEncoder.encode("【阅信短信验证码】验证码888888,打死也不能告诉别人哦。", "UTF-8"));param.put("phone", "13400000000");param.put("subid", "");param.put("mttime", mttime);HttpTool.sendPost(url, param);POST提交方法
public static String sendPost(String url, Map<String, String> params) {Log.i("POST提交:[url="+url+"]"+params.toString());URL u = null;HttpURLConnection con = null;// 构建请求参数StringBuffer sb = new StringBuffer();if (params != null) {for (Entry<String, String> e : params.entrySet()) {sb.append(e.getKey()).append("=").append(e.getValue()).append("&");}sb.substring(0, sb.length() - 1);}// 尝试发送请求try {u = new URL(url);con = (HttpURLConnection) u.openConnection();con.setRequestMethod("POST");con.setConnectTimeout(6000);con.setDoOutput(true);con.setDoInput(true);con.setUseCaches(false);con.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");OutputStreamWriter osw = new OutputStreamWriter(con.getOutputStream(), "UTF-8");osw.write(sb.toString());osw.flush();osw.close();} catch (Exception e) {Log.e(e);} finally {if (con != null) {con.disconnect();}}// 读取返回内容StringBuffer buffer = new StringBuffer();try {BufferedReader br = new BufferedReader(new InputStreamReader(con.getInputStream(), "UTF-8"));String temp;while ((temp = br.readLine()) != null) {buffer.append(temp).append("n");}} catch (Exception e) {Log.e(e);}Log.i("POST响应:"+buffer.toString());return buffer.toString();}MD5加密方法
public static String MD5(String str){MessageDigest md5 = null;
try{ md5 = MessageDigest.getInstance("MD5"); }catch (Exception e){ Log.i(e.getMessage()); return ""; } char[] charArray = str.toCharArray(); byte[] byteArray = new byte[charArray.length]; for (int i = 0; i < charArray.length; i++) byteArray[i] = (byte) charArray[i]; byte[] md5Bytes = md5.digest(byteArray); StringBuffer hexValue = new StringBuffer(); for (int i = 0; i < md5Bytes.length; i++){ int val = ((int) md5Bytes[i]) & 0xff; if (val < 16){ hexValue.append("0"); } hexValue.append(Integer.toHexString(val)); } return hexValue.toString();
}
读取短信,做判断,填入数值。
android收到短信应该会有一条广播,注册广播接收器来想办法读取短信6.0的机子好像要动态申请权限
监听短信数据库的变化,增加时获取到短信再提取相应的验证码。
这个你要自己写吗? 我建议你直接调用短信平台的接口不就可以了吗?
短信发送
//接口地址
String url = "http://183.203.28.5:9000/HttpSmsMt";
//下发时间
String mttime = new SimpleDateFormat("yyyyMMddHHmmss").format(new Date());
Map<String, String> param = new HashMap<String, String>();
param.put("name", "用户帐号");
param.put("pwd", Tools.MD5("用户密码"+mttime));
param.put("content", URLEncoder.encode("【阅信短信验证码】验证码888888,打死也不能告诉别人哦。", "UTF-8"));
param.put("phone", "13400000000");
param.put("subid", "");
param.put("mttime", mttime);
HttpTool.sendPost(url, param);
POST提交方法
public static String sendPost(String url, Map<String, String> params) {
Log.i("POST提交:[url="+url+"]"+params.toString());
URL u = null;
HttpURLConnection con = null;
// 构建请求参数
StringBuffer sb = new StringBuffer();
if (params != null) {
for (Entry<String, String> e : params.entrySet()) {
sb.append(e.getKey()).append("=").append(e.getValue()).append("&");
}
sb.substring(0, sb.length() - 1);
}
// 尝试发送请求
try {
u = new URL(url);
con = (HttpURLConnection) u.openConnection();
con.setRequestMethod("POST");
con.setConnectTimeout(6000);
con.setDoOutput(true);
con.setDoInput(true);
con.setUseCaches(false);
con.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
OutputStreamWriter osw = new OutputStreamWriter(con.getOutputStream(), "UTF-8");
osw.write(sb.toString());
osw.flush();
osw.close();
} catch (Exception e) {
Log.e(e);
} finally {
if (con != null) {
con.disconnect();
}
}
// 读取返回内容
StringBuffer buffer = new StringBuffer();
try {
BufferedReader br = new BufferedReader(new InputStreamReader(con.getInputStream(), "UTF-8"));
String temp;
while ((temp = br.readLine()) != null) {
buffer.append(temp).append("n");
}
} catch (Exception e) {
Log.e(e);
}
Log.i("POST响应:"+buffer.toString());
return buffer.toString();
}
MD5加密方法
public static String MD5(String str){
MessageDigest md5 = null;
}
读取短信,做判断,填入数值。
android收到短信应该会有一条广播,注册广播接收器来想办法读取短信
6.0的机子好像要动态申请权限