Python uses third-party modules to send SMS verification codes (test cases)

Source: Internet
Author: User

Today learned to use Python third-party, send SMS CAPTCHA code, Speed realization once, SMS immediately received, decisive record!

Environment: Virtual machine on CENTOS7 platform, python2.7 version;

第三方服务提供商是:云通讯官网:www.yuntongxun.com/只需要注册账号即可,利用其免费测试api实现python调用接口,免费发送短信验证码,可达到实践效果;

First, the registration section is omitted, before the Python code, the environment of the third-party service is set up first:
1. Add a test number

添加的号码为接收短信验证码的电话号码;

2. Download the necessary documents:

下载必要的文件后,上传到centos7上的目录下,主要是demo模板代码和必要的库文件等;

Click to download:

The second is to operate on the CENTOS7:
1. Upload the necessary files and unzip:

    ]# rz     #选择CCP_REST_DEMO_Python_v2.7r.zip上传;    ]# unzip CCP_REST_DEMO_Python_v2.7r.zip    #解压

2. Create a catalog of test cases and copy the necessary files:

]# mkdir -p ~/libs/yuntongxun]# vim ~/CCP_REST_DEMO_Python_v2.7r1/SDK/* ~/libs/yuntongxun#复制sdk下的文件

3. Reference code template file for SMS Verification code

 ]# cat  ~/CCP_REST_DEMO_Python_v2.7r1/DEMO/SendTemplateSMS.py     查看登陆云通讯主页的关键参数:

The following test code will use these parameters to remember; According to the file, rewrite the test code:]# vim ccp.py from ccprestsdk import REST import Configparser        _accountsid= ' 8a216da********a9029a ';        #云通讯主页的参数ACCOUNT ID _accounttoken= ' 801fcd********d ';        #云通讯主页参数ATUH TOKEN _appid= ' 8a216da********a0 ';        #云通讯主页参数App ID _serverip= ' app.cloopen.com ';        #云通讯主页参数Rest URL (production) #其它参数, referring to the parameters in the template code above; _serverport= ' 8883 ';        _softversion= ' 2013-12-26 '; Class _CCP (object): Def __init__ (self): Self.rest = Rest (_serverip, _serverport, _so ftversion) Self.rest.setAccount (_accountsid, _accounttoken) self.rest.setApp Id (_appid) @classmethod def instance (CLS): If not hasattr (CLS, ' _inst Ance '): Cls._instance = CLS () return cls._instance de F sendtemplatesms (self, to, datas, TEMPID): Return Self.rest.sendTemplateSMS (To, Datas, tempid) CCP = _ccp.instance () If _ _name__ = = ' __main__ ': ccp.sendtemplatesms (' 1*********3 ', [' 1234 ', 5],1) #参数顺序是接收短信验证码的手机号; 12 34 for SMS Verification Code, 5 for the effective minutes, 1 for the required test, see the official website for details;

4. Run:

    

Conforming a moment, receive SMS;

Python uses third-party modules to send SMS verification codes (test cases)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.