How to use Java + Maven project environment to send SMS verification code, this article uses hazelnut cloud SMS interface.

1. Install the SDK

Download address: smsow.zhenzikj.com/doc/sdk.htm…

To download the jar file, you need to publish the jar to the local Maven repository.

MVN install: install-file-dgroupid = com.zhenzi-dartifactid = sms-dversion = 1.0.0-dpackaging =jar -Dfile=/Users/Downloads/ZhenziSmsSDK.jarCopy the code

Note: -dfile is the path to the JAR file you downloaded locally, on the MAC system used in this example

Next, introduce the project in POM.xml:

< the dependency > < groupId > com. Zhenzi < / groupId > < artifactId > SMS < / artifactId > < version > 1.0.0 < / version > < / dependency >Copy the code

Ok, the SDK is installed, in fact, also quite simple

2. Apply for a test account and obtain the appId and appSecret

Test account needs manual application, can apply for a few minutes generally.

Use the test account login management background to obtain appId and appSecret, address: sms.zhenzikj.com/zhenzisms_u…



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



3. Usage

Initialize ZhenziSmsClient with the pre-applied AppId and AppSecret:

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

AppId and AppSecret are assigned by SMS platforms

1) Send text messages

String result = client.send("15811111111"."Your verification code is 4534, valid for 5 minutes");
Copy the code

The send method is used to send a single short message

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

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

Error code table

Error code why The solution
100 Parameter format error Check whether the request parameters are empty or the mobile number is incorrectly formatted
101 The text message contains more than 1,000 words If the short message is too long, check it or send it multiple times
105 The appId is incorrect or the application does not exist Please contact the staff to apply for the application or check whether the input of appId is incorrect
106 The application is prohibited. Please contact the staff to find out the cause
107 IP error If an IP address whitelist is set, the system checks the IP address of the request server to determine whether it is a secure source for access
108 Short message balance insufficient Need to go to the user center to recharge
109 Delivery exceeds quota today If the number of daily notifications is set, each recipient number cannot exceed this number
110 Error applying AppSecret Check whether AppSecret was typed incorrectly or whether the secret key has been reset in the user center
111 Account does not exist. Please contact the staff to apply for an account
1000 System position error Please contact staff or technical personnel to check the cause