Since wechat small program provides cloud development support, developers do not need to build a background server, using the core API provided by wechat can achieve application functions, at this time you need small program to be able to send SMS, such as SMS verification code, Hazelnut cloud SMS (http://smsow.zhenzikj.com) has developed a dedicated to town for this SDK, details refer to: http://smsow.zhenzikj.com/doc/sdk.html


The following small series will explain how to use it in detail:


1. The SDK after installation and download only contains one zhenzisms. Js file, which can be directly placed in the utils folder and imported via require, as follows:

var zhenzisms = require('.. /.. /utils/zhenzisms.js');Copy the code

2. Configure the domain name

In WeChat public platform – small program management configuration domain name https://smsdeveloper.zhenzikj.com, the diagram below:

3. Usage

Initialize with the pre-obtained AppId, AppSecret:

zhenzisms.client.init(apiUrl, appId, appSecret);Copy the code

ApiUrl is the request address, https://sms_developer.zhenzikj.com for individual developers and https://sms.zhenzikj.com for enterprise developers

1) Send text messages

zhenzisms.client.send(function(res){ console.log(res.data); })},'15811111111'.'Your verification code is 2323');
Copy the code

The send method is used to send a single SMS message. Parameter 1: callback function for receiving the returned result after the request. Parameter 2: mobile phone number of the receiver. If the message is not 0, the message fails to be sent and error information can be viewed from data. Note: Do not use the full digital format of “Hello” or “12132” to test the message content. Such message content has no specific meaning and may be blocked by the carrier

{
			    "code": 0."data":"Sent successfully"
			}
Copy the code


2) Send SMS (return status report)

zhenzisms.client.send(function(res){ console.log(res.data); })},'15811111111'.'Your verification code is 2323'.'dfee_dfdw_xdfd_dfdfd');
Copy the code

The send method is used to send a single SMS message, and developers can accept the SMS sending status report. For details about how to use the method, see :API Description Parameter 1: callback function used to receive the returned result after a request. Parameter 2: mobile phone number of the receiver. Parameter 3: message content. Parameter 4:messageId is the unique identifier of the message, which cannot be repeated. The returned result is a string in JSON format, code: indicates that the message is sent successfully. If the message is not 0, the message fails to be sent. You can view error information in data. Error code Table Error Code Cause Solution 100 Parameter format is incorrect check whether the request parameters are empty or the mobile phone number format is incorrect. 105 The appId is incorrect or the application does not exist. Contact huawei technical support to apply for an application or check whether the appId is incorrect. 106 The application is prohibited. 108 The balance of SMS messages is insufficient. You need to recharge the SMS messages in the user center. 109 Send messages today Exceeds the quota. 111 The account does not exist. Please contact the staff to apply for an account. 1000 The system location is incorrect


3) Check your balance

Use this interface to view the number of remaining short creeds

Copy the code

zhenzisms.client.balance(function(res){
               console.log(res.data)
            });
Copy the code

The result is a string in JSON format, code: query status, 0 for success, and data for the number of remaining short credos. Non-0 indicates that the query failed. Error code table Error Code Cause Solution 100 Parameter format is incorrect Check whether the request parameter is empty 105 The appId is incorrect or the application does not exist contact the technical support to apply for an application or check the appId. 106 The application is prohibited Contact the technical support to check the cause 107 IP address error If the IP address whitelist is set, the system checks the IP address of the request server to determine whether it is accessed from a secure source. 110 Application secret error Check whether AppSecret is incorrectly entered. 1000 The location of the system is incorrect. Contact the technical support personnel or technical support personnel. Cause 4) Query SMS message Interface Description Send SMS messages according to messageId


Request Parameters Parameter Name Mandatory Type Description messageId Is a string information ID corresponding to the messageId field of the INTERFACE for sending SMS messages. Result The returned result is a string in JSON format, with code: query status. 0 indicates that the query is successful. Non-0 indicates failure. You can view error information in data

{
			    "code": 0."data":{}
			}
Copy the code

The result is a JSON string in which code indicates the query status, 0 indicates the success, and data indicates the SMS message


Original: http://smsow.zhenzikj.com/news/detail/284.html