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
error code |
reason |
solution |
tr>
|
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 |
td>110
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