Ali big fish text message send hand to handle church

Ali big fish SMS sending

1. Register an account on the
Insert picture description here
Alibaba Cloud platform and log in. After clicking the official website, there is a text message at the bottom left of the page:
SMS service , click

Insert picture description here

In this way, you can add a sending template:
Insert picture description here
here you can imitate the SMS template of xxx:

Insert picture description here
In this way, the template is compiled, and you will get a template CODE, such as SMS_18xxxxxxx

here to get: AccessKey ID and Access Key Secret used
in the project:

 public static String messageSDK(String messageSDK,
                                    String adminmobile,
                                    String username,
                                    String exchangepassword,
                                    HttpServletRequest httpServletRequest) throws Exception {
        String Msg = "";
        // ip判断恶意访问
        String ip = httpServletRequest.getRemoteAddr();

        // 设置超时时间-可自行调整
        System.setProperty("sun.net.client.defaultConnectTimeout", "10000");
        System.setProperty("sun.net.client.defaultReadTimeout", "10000");
        // 初始化ascClient需要的几个参数
        final String product = "Dysmsapi";// 短信API产品名称(短信产品名固定,无需修改)
        final String domain = "dysmsapi.aliyuncs.com";// 短信API产品域名(接口地址固定,无需修改)
        // 替换成你的AK
        final String accessKeyId = "xxxxx";// 你的accessKeyId,参考本文档步骤2
        final String accessKeySecret = "xxxxx";// 你的accessKeySecret,参考本文档步骤2
        // 初始化ascClient,暂时不支持多region(请勿修改)
        IClientProfile profile = DefaultProfile.getProfile("cn-hangzhou", accessKeyId, accessKeySecret);
        DefaultProfile.addEndpoint("cn-hangzhou", "cn-hangzhou", product, domain);
        IAcsClient acsClient = new DefaultAcsClient(profile);
        // 组装请求对象
        SendSmsRequest request = new SendSmsRequest();
        // 使用post提交
        request.setMethod(MethodType.POST);
        // 必填:待发送手机号。支持以逗号分隔的形式进行批量调用,批量上限为1000个手机号码,批量调用相对于单条调用及时性稍有延迟,验证码类型的短信推荐使用单条调用的方式;发送国际/港澳台消息时,接收号码格式为00+国际区号+号码,如“0085200000000”
        request.setPhoneNumbers(messageSDK);
        // 必填:短信签名-可在短信控制台中找到
        request.setSignName("中国xxx");
        // 必填:短信模板-可在短信控制台中找到,发送国际/港澳台消息时,请使用国际/港澳台短信模版
       
        request.setTemplateCode("SMS_18xxx");
       
        String msg = "{\"username\":\"" + username +
                "\",\"exchangepassword\":\""+exchangepassword+
                "\",\"adminmobile\":\""+adminmobile+"\""+"}";
        request.setTemplateParam(msg);

        SendSmsResponse sendSmsResponse = acsClient.getAcsResponse(request);
        if (sendSmsResponse.getCode() != null) {
            Msg = sendSmsResponse.getMessage();
        }
        return Msg;
    }

What I want to emphasize here is the configuration of msg in request.setTemplateParam (msg) ;.
There is only one parameter for sending the verification code: request.setTemplateParam ("{" code ":" + mycode + "}");
with multiple parameters:

 String msg = "{\"username\":\"" + username +
                "\",\"exchangepassword\":\""+exchangepassword+
                "\",\"adminmobile\":\""+adminmobile+"\""+"}";

Note that the parameters are also in quotes after precompilation .

Published 67 original articles · Liked12 · Visitors 10,000+

Guess you like

Origin blog.csdn.net/m0_37635053/article/details/104632607