[Java] Tencent cloud send SMS verification code -Struts2

Tencent cloud has a free package, then there are 100 registered monthly free SMS packages, easy to test.

appid, appkey, templateId, smsSign need to get back to the surface of the application package. Application can handle about half an hour.

package com.hj.action;

import com.github.qcloudsms.SmsSingleSender;
import com.github.qcloudsms.SmsSingleSenderResult;
import com.github.qcloudsms.httpclient.HTTPException;
import org.json.JSONException;
import java.io.IOException;

public class TelCodeAction {
    private String telephone;
    // 短信应用 SDK AppID
    private int appid = 140031241; // SDK AppID 以1400开头
    // 短信应用 SDK AppKey
    private String appkey = "aaaa";
    int templateId = 7839; //NOTE: Here's an example of just ID`7839` template, template ID real need to apply in the SMS console
     // signature 
    String smsSign = "xx website" ; 

    public String the Execute () {
         // int code = (int) (the Math. Random () * 8999 + 1000); 
        int code = 3838438 ; 
        String msg = "[xx website] your verification code is" + code + ", effective within one minute if not himself operations, please ignore this message.." ; 
        System .out.println (MSG); 

        the try { 
            SmsSingleSender ssender = new new SmsSingleSender ( the this .appid, the this .appkey); 
            SmsSingleSenderResult Result = ssender.send (0, "86" "", "" , Telephone,
                    MSG, ); 
            System.out.println (Result); 
        } the catch (HTTPException E) {
             // the HTTP error response code 
            e.printStackTrace (); 
        } the catch (JSONException E) {
             // the JSON parsing error 
            e.printStackTrace (); 
        } the catch (IOException E) {
             // network IO error 
            e.printStackTrace (); 
        } 

        return "Success" ; 
    } 

    public String getTelephone () {
         return Telephone; 
    }

     public  void setTelephone(String telephone) {
        this.telephone = telephone;
    }
}

 

Guess you like

Origin www.cnblogs.com/to-red/p/11314649.html