Python Send SMS Verification code

Source: Internet
Author: User

Business:

Mobile phone-side Click Send Verification code, request sent to Python side, by Python call third party platform (we use the hazelnut cloud SMS http://smsow.zhenzikj.com) SMS interface, generate verification code and send.

SDK Download: http://smsow.zhenzikj.com/doc/sdk.html

API Document: Http://smsow.zhenzikj.com/doc/python_sdk_doc.html

Code:

1) Generate 4-bit random number as verification code

Import Randomcode = ";//verification code for NUM in range (1,5):    code = code + str (random.randint (0, 9));

  

2) Import SDK

Import Zhenzismsclient as Smsclient

  

3) Call the SMS platform to send the verification code

Client = Smsclient. Zhenzismsclient (' 100000 ', ' nmabsdfdkkdfmzzdffknjcwndc1mmz '); result = Client.send (' 12411111111 ', ' Your Verification code is ' +code ')

  

Zhenzismsclient requires AppID, Appsecret initialization with pre-applied

The returned result is a JSON-formatted string, code: Send status, 0 for success. Non-0 fails to send, can view error message from data

{    "code": 0,    "data": "Sent Successfully"}
Error code table tr> td>110
error code reason solution
parameter format error Check if request parameter is empty or phone number format error
101 SMS content more than 1000 words SMS content is too long, please screen or send multiple times
appid error or app does not exist please contact a worker to apply or check if AppID is entered Error
106 app Forbidden please contact staff for reasons
107 IP Error Error If an IP whitelist is set, the system checks the IP address of the requesting server, determines whether to access the security source
108 Short message balance requires a user Center to Recharge
109 send over limit today if the number of days sent is set, then each receive number must not exceed this quantity
Application key (Appsecret) error Check if Appsecret entered an error, or if a key reset has been made in User Center
111 account does not exist Please contact the staff to request an account
System location error Please contact a worker or technician to check the cause

Full code:

#-*-Coding:utf-8-*-import zhenzismsclient as Smsclientimport randomcode = '; for num in range (1,5):    code = code + STR (random.randint (0, 9));p rint (code); client = Smsclient. Zhenzismsclient (' 100000 ', ' Nmmzzdfmnjfknjcwndc1mmz ');p rint (' client.send ' (' 12411111111 ', ' Your Verification code is ' +code ')

  

Python Send SMS Verification code

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.