For beginners, how to use third-party Python development package to send SMS verification code, the following is the specific implementation and recording process!

Environment: vm centos7 platform, python3.7;

Third-party SMS platform: Hazelcloud SMS (smsow.zhenzikj.com)

The SDK download address: smsow.zhenzikj.com/sdkdownload… Note to download python3

The API documentation: smsow.zhenzikj.com/doc/python_…

First, the part about applying for an account is omitted

1. Get appID and appSecret

Used to apply for account, login user center sms.zhenzikj.com/zhenzisms_u…

Open in “My Application “->” Details” :

2. Download the development package

download

The downloaded SDK contains only one zhenzismsclient.py file, which can be directly imported into the project.

3. Introduce modules

import zhenzismsclient as smsclient
Copy the code

Initialize ZhenziSmsClient with the pre-applied AppId and AppSecret:

client = smsclient.ZhenziSmsClient(appId, appSecret);Copy the code

4. Generate a verification code

import random
 
code = ' '; / / verification codefor num inRange (1,5): code = code + STR (random. Randint (0, 9));Copy the code

5. Send text messages

result = client.send('15811111111'.'Your verification code is 2323');
Copy the code

Parameter 1: mobile phone number of the receiver. Parameter 2: SMS content

The result is a string in JSON format, with code: sent status and 0 indicating success. If the value is not 0, the sending fails. You can view error information in data

6. Send SMS (with return report)

result = client.send('15811111111'.'Your verification code is 2323'.'dfee_dfdw_xdfd_dfdfd');Copy the code

Parameter 3: messageId is a unique identifier which message, that is, cannot repeat, the specific use please reference: smsow.zhenzikj.com/doc/api_doc…