当前位置:网站首页>Integration of Alibaba cloud SMS services and reasons for illegal message signing

Integration of Alibaba cloud SMS services and reasons for illegal message signing

2022-06-24 04:37:00 Granger_ g

Integrated Alibaba cloud SMS service , The following is the code for me to successfully receive SMS messages by integrating Alibaba cloud SMS service :

Some of the contents need to be changed to your own Alibaba cloud configuration

public class TestSms {
    public static void main(String[] args) {
        DefaultProfile profile = DefaultProfile.getProfile("cn-hangzhou",
                "<accessKeyId>",
                "<accessSecret>");// Write your correspondence in these two places  Id  and Secret
        IAcsClient client = new DefaultAcsClient(profile);

        CommonRequest request = new CommonRequest();
        request.setSysMethod(MethodType.POST);
        request.setSysDomain("dysmsapi.aliyuncs.com");
        request.setSysVersion("2017-05-25"); 
        request.setSysAction("SendSms");
        request.putQueryParameter("RegionId", "cn-hangzhou");
        // Determine the phone number and   Verification Code 
        request.putQueryParameter("PhoneNumbers", "13100000000");
        request.putQueryParameter("TemplateParam", "{\"code\":\"" + "123456" + "\"}");
        // Confirm the template and signature of yes 
        request.putQueryParameter("SignName", " Fill in your SMS signature here ");
        request.putQueryParameter("TemplateCode", " Write your template here code");
        // RAM account number AccessKey Secret

        try {
            CommonResponse response = client.getCommonResponse(request);
            System.out.println(response.getData());
        } catch (ServerException e) {
            e.printStackTrace();
        } catch (ClientException e) {
            e.printStackTrace();
        }
    }
}

If everything is OK, the above code It's all done , You can receive SMS directly .

Problems encountered 1: The signature is illegal

terms of settlement :

1. Check your  accessKeyId and  accessSecret Are they all right

2. Check your SMS signature And templates code  Be careful : Template code It's a bunch of SMS_1995992 Numbers like this , Don't fill in the name of the template

3. Coding problem , If your SMS signature is in Chinese , Try changing the coding method .( That's my problem , I changed it to GBK Coding method ok 了 )

 

原网站

版权声明
本文为[Granger_ g]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/175/202206232358125581.html