Ali cloud push messages.

import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.IAcsClient;
import com.aliyuncs.dysmsapi.model.v20170525.SendSmsRequest;
import com.aliyuncs.dysmsapi.model.v20170525.SendSmsResponse;
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.profile.DefaultProfile;
import com.aliyuncs.profile.IClientProfile;


public class ShortMsgUtils {

    static final String product = "Dysmsapi";
    //产品域名,开发者无需替换
    static final String domain = "dysmsapi.aliyuncs.com";

    //TODO here need to replace the developer's own AK (access Ali cloud console seeking) 
    static  Final String accessKeyId = "developer's own AK" ;
     static  Final String accessKeySecret = "developer's own AK" ; 

    public  static SendSmsResponse sendSms (Phone String, String name, String pronames, String templateCode) throws ClientException {
         // can be self-adjusted timeout 
        System.setProperty ( "sun.net.client.defaultConnectTimeout", "10000" ); 
        System.setProperty ( "sun.net .client.defaultReadTimeout "," 10000 " ); 

        // initialize acsClient, does not support the region of
        Profile = DefaultProfile.getProfile IClientProfile ( "CN-Hangzhou" , accessKeyId, accessKeySecret); 
        DefaultProfile.addEndpoint ( "CN-Hangzhou", "CN-Hangzhou" , Product, Domain); 
        IAcsClient acsClient = new new DefaultAcsClient (Profile); 

        // assembly request object - particularly described in the console - parts of the documentation 
        SendSmsRequest request = new new SendSmsRequest ();
         // required: phone number to be sent 
        request.setPhoneNumbers (phone);
         // required: SMS signature - can SMS console in find 
        request.setSignName ( "neighborhood farm fresh" );
         // required: SMS templates - can be found in the SMS console 
        request.setTemplateCode (templateCode);//SMS templates
         // Optional: template variable substitution JSON string, such as templates for the content "Dear $ {name}, your verification code is $ {code}", the value herein 
        request.setTemplateParam ( "{ \ "name \": \ " " + "" + name + "" + "\", \ "remark \": \ "" + " [" + pronames + "]" + "\"} " ); 

        // selected from fill - up message spreading code (no special needs of users ignore this field)
         // request.setSmsUpExtendCode ( "90 997"); 

        // optional: outId is provided to the business side extension field, eventually this value in a text message receipt message back to the caller 
        request.setOutId ( "yourOutId" ); 

        // hint here might throw an exception, note the catch 
        sendSmsResponse sendSmsResponse = acsClient.getAcsResponse (Request); 

        return sendSmsResponse; 
    }

 

 

 

 

Guess you like

Origin www.cnblogs.com/tomingto/p/11458267.html