SMS sending tools:

package com.xz.worker.util;


import com.github.qcloudsms.SmsSingleSender;
import com.github.qcloudsms.SmsSingleSenderResult;
import org.json.JSONException;

import javax.xml.ws.http.HTTPException;
import java.io.IOException;
import java.util.Random;

/ * * *@author zagwk
 * @version 1.0
 * @date2020/7/25 0025 PM * /
public class SMSUtil {

    // SMS application SDKAppId
    private int appid = 111111111;
    // SMS application SDKAppKey
    private String appkey = "ajdhfa546afe654fa";

    // ID of the SMS template, which needs to be applied for in the SMS application
    private int templateId = 456489;

    / / signature
    // NOTE:The actual signature needs to be applied in the SMS console. In addition, the signature parameter uses' signature content 'instead of' signature ID '
    private String smsSign = "xxxxx";


    /** ** Send SMS verification code ** **@paramtelThe number is * *@paramverifyCodeVerification code * *@return* * /
    public String sendCaptcha(String tel, String verifyCode) {
        try {
            // Mobile phone number to send SMS
            String phoneNumber = tel;

            // Single SMS
            // SmsSingleSender ssender = new SmsSingleSender(appid, appkey);
            // SmsSingleSenderResult result = ssender.send(0, "86", phoneNumber, "You are registering as a good school user, your verification code is: "+ verifyCode +", please complete verification within 10 minutes, thank you for your support! , ""," ");

            // Specify the template ID to send single SMS messages
            String[] params = {verifyCode};
            SmsSingleSender ssender = new SmsSingleSender(appid, appkey);
            SmsSingleSenderResult result = ssender.sendWithParam("86", phoneNumber, templateId, params, smsSign, ""."");
            // Return the verification code
            return verifyCode;
            // If the signature parameter is not provided or empty, the default signature is used to send SMS messages
            // System.out.print(result);

        } catch (HTTPException e) {
            // The HTTP response code is incorrect
            e.printStackTrace();
        } catch (JSONException e) {
            // JSON parsing error
            e.printStackTrace();
        } catch (IOException e) {
            // Network I/O error
            e.printStackTrace();
        }catch (com.github.qcloudsms.httpclient.HTTPException e){
            e.printStackTrace();
        }
        return null; }}Copy the code
Tencent cloud console: https://console.cloud.tencent.com/ SDKAppId SMS applicationCopy the code

Copy the code
SMS application SDKAppKeyCopy the code

Copy the code
ID of an SMS template, which must be applied for in the SMS applicationCopy the code

Copy the code
The signature parameter uses' signature content 'instead of' signature ID 'Copy the code

Copy the code