方法一:跟服务器开发沟通给一个接口:

import requests, json
r = requests.get(url='http://test-capha.singer.com/c/13524273413

')  # 带参数的GET请求
verifycode = eval(r.text)[1]['verifycode']
print(verifycode)

方法二,在网上找到的方法记录下:
参考链接:  http://www.jb51.net/article/89747.htm,之前试的发现只保存短信的后面一部分,后来才发现是前面一排字被挡住了。。。。。。。
分两步:第一步在手机端安装一个apk,保存手机的短信到txt文档里面:
public class SMSReceiver extends BroadcastReceiver {public static final String SMS_RECEIVED_ACTION = "android.provider.Telephony.SMS_RECEIVED";@Override public void onReceive(Context context, Intent intent){if (intent.getAction().equals(SMS_RECEIVED_ACTION)){ SmsMessage[] messages = getMessagesFromIntent(intent); String verifyCode="";for (SmsMessage message : messages){ verifyCode += message.getDisplayMessageBody(); } writeFile(verifyCode);//将短信内容写入SD卡 } }

public final SmsMessage[] getMessagesFromIntent(Intent intent){ Object[] messages = (Object[]) intent.getExtras().get("pdus");byte[][] pduObjs = new byte[messages.length][];for (int i = 0; i < messages.length; i++) { pduObjs[i] = (byte[]) messages[i]; }byte[][] pdus = new byte[pduObjs.length][];int pduCount = pdus.length; SmsMessage[] msgs = new SmsMessage[pduCount];for (int i = 0; i < pduCount; i++) { pdus[i] = pduObjs[i]; msgs[i] = SmsMessage.createFromPdu(pdus[i]); }return msgs;

 }//将短信内容写到SD卡上的文件里,便于将文件pull到PC,这样可方便其它如WWW/WAP平台的自动化 @SuppressLint("SdCardPath")public void writeFile(String str){ String filePath="/mnt/sdcard/verifyCode.txt";byte [] bytes = str.getBytes();try{ File file=new File(filePath); file.createNewFile(); FileOutputStream fos=new FileOutputStream(file); fos.write(bytes); fos.close(); }catch(IOException e){ e.printStackTrace(); } }}

注册:
receiver android:name=".SMSReceiver">    <intent-filter>        <action android:name="android.provider.Telephony.SMS_RECEIVED" /> </intent-filter></receiver>

权限:
<uses-permission android:name="android.permission.RECEIVE_SMS"/><uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/><uses-permission android:name="android.permission.READ_SMS"/>

打包apk后安装第二步:使用adb 命令读取txt文档内容,再从中获取短信 C#//从手机文件中获取短信        public String getSmsText()        {            Process process = new Process();            String command = "adb shell cat /mnt/sdcard/verifyCode.txt";            string outtr = "";            process.StartInfo.FileName = "cmd.exe";            process.StartInfo.Arguments = "/C" + command;            process.StartInfo.RedirectStandardInput = true; //重定向输入(一定是true)            process.StartInfo.RedirectStandardOutput = true; //重定向输出            process.StartInfo.RedirectStandardError = true;            process.StartInfo.UseShellExecute = false;            try            {                process.Start();                outtr = process.StandardOutput.ReadToEnd();                process.WaitForExit(5000);

            }catch(Exception e)            {                Console.WriteLine(e.Message);            }finally            {                if(process != null)                    process.Close();            }                    Console.WriteLine("开始读取内容" + outtr);

            return outtr;        }

 //从短信中提取验证码                    public String getVerificationCode(String s)        {            MatchCollection mc = Regex.Matches(s, @"\d{6}");            String str = "";            int k = 0;                        foreach (Match item in mc)            {                if (k == 1)                                    break;                                Console.WriteLine(item.Value);                str = item.Value;                k++;                      }            return str;        }

转载于:https://www.cnblogs.com/zjxyz2008zhangjuan/p/7279337.html

自动化测试 短信验证登录相关推荐

  1. 七丶青龙nvjdc部署教程+短信验证登录对接傻妞

    青龙nvjdc部署教程+短信验证登录对接傻妞Nolanjdc 没有服务器的先自行购买,这里推荐腾讯云2H4G8M首年70–点击购买 青龙面板安装教程 傻妞机器人安装教程 XDD安装教程 QQ交流:10 ...

  2. 工厂如何实现无线wifi短信验证登录?工厂上网实名认证系统

    工厂如何实现无线wifi短信验证登录?工厂上网实名认证系统 工厂提供公共的无线wifi上网服务,需对用户进行实名认证.手机短信实名认证以其用户体验.综合成本等优势,成为工厂无线上网认证的首选方案. 一 ...

  3. Vue与Node.js实现手机短信验证登录

    手机短信使用的第三方平台是联容云,注册就送8块钱体验费,足够自己用用了,注册完自己建一个应用就能拿到需要使用的配置了,如图 注册完之后1就可以使用了. Node.js后端使用了Express框架 &q ...

  4. Spring boot短信验证登录

    一.短信验证码业务 我用的是第三平台的短信服务,当用户点击发送验证码,会调用短信平台接口,从而给手机发验证码.流程如下: c 首先需要工具类,来发送验证码 public class DXMessage ...

  5. 秒滴云短信验证登录小demo

    短信验证登录demo <a class="click_login_head" data-href="/member" data-method=" ...

  6. Android实现第三方Mob短信验证登录以及手机号显示和修改用户名(简易新闻 五)

    Android实现第三方Mob短信验证登录以及手机号显示和修改用户名(简易新闻 五) 关于之前的功能实现可以从制作简易新闻App导航篇中查看 因为这篇是写了有一段时间的博客,所以这篇(包括后面的简易新 ...

  7. Springboot实现短信验证登录

    一.介绍 使用短信验证登录也是现在实际项目中普遍使用的一种登录, 二.实际的操作流程 1.用户在前端页面输入手机号码之后,点击发送验证码 2.前端将手机号传给后端 3.后端生成一个6为的随机数通过短信 ...

  8. java WEB调用秒嘀科技短信验证接口(实现短信验证登录)

    java WEB调用秒嘀科技短信验证接口(实现短信验证登录) 前言 注册秒嘀云账号 登录秒嘀云官网 代码 前言 短信验证登咱就不多说了,为什么推荐用秒嘀的呢,应为他会送你10元钱,对于新手来说10元钱 ...

  9. 014_关于session实现短信验证登录的前端启动

    014_关于session实现短信验证登录的前端启动 1.进入到nginx相对应的文件夹,shfit+右键,进入PowerShell并且执行nginx 2.启动我们的nginx,嘿嘿,可以访问我们的前 ...

  10. 短信验证登录淘宝web页面(selenium+Chromedriver)

    短信验证登录淘宝web页面 自动化模拟登录(chromedriver存在python环境里) 第一步进行导包 第二步定位获取页面的web源代码 第三步构造是以chrome浏览器登录而不是以seleni ...

最新文章

  1. Linux 环境下umount, 报 device is busy 的问题分析与解决方法
  2. php 7.2 安装 mcrypt 扩展(亲测)
  3. C#中break,continue,return,,goto,throw的区别(转)
  4. Parasoft C++test使用教程:执行测试用例(上)
  5. 步进电机的加速时间是怎么样的?
  6. 用Navicat for MySQL往数据表中添加数据时汉字出现乱码
  7. Mysql--mysqldump命令 备份数据库
  8. macOS BigSur下根目录下无法创建文件
  9. windows环境安装elasticsearch
  10. 为了对电脑进行保护,已经阻止此应用
  11. 计算机网络 --- IP地址的详细分类
  12. 老徐WEB:js入门学习 - javascript变量的数据类型
  13. 翡翠手链华丽多彩而不庸俗
  14. 红米note9pro和华为Nova8哪个好 红米note9pro和华为Nova8哪个更加值得入手
  15. 关于EMC DAE、DPE、SPE、SPS的解释
  16. 重拾Java基础知识:枚举
  17. 手机计算机怎么玩24点游戏,计算器游戏怎么玩 新手前期玩法介绍
  18. 小丸子学MongoDB系列之——部署MongoDB副本集
  19. OpenCV实战5 车牌号识别
  20. linux内核去掉pty,Linux tty pty pts观念区别

热门文章

  1. 如何在Mac上使用时间机器和“聚焦”恢复文件
  2. [MAC] 6 个好用小技巧
  3. [windows10系统]mysql8.0最详细的安装指南
  4. 复制class文件到as中出现非法字符,须要class,interface货enum
  5. Material Design学习之 Dialog(顺便把前两天AppBarLayout没讲的部分提一提)
  6. 沫沫金::struts下载文档[解决方案]
  7. 解決win7打开EXE文件总是出现安全警告
  8. 三、定义主从实体基类
  9. mybatis源码学习方式
  10. eclipse运行java程序出现多个问题:内部错误IOConsole Updater