SMS notification on Alibaba Cloud platform (java)

RAM account: 

 

What is a RAM user

A RAM user is an entity identity type of RAM, which has a certain identity ID and identity credentials, and it usually corresponds to a certain person or application one by one. RAM users have the following characteristics:

  • A RAM user is created by an Alibaba Cloud account (primary account) or other RAM users or RAM roles with administrator privileges. After the creation is successful, it belongs to the Alibaba Cloud account, and it is not an independent Alibaba Cloud account.
  • RAM users do not own resources and cannot be billed independently, and are billed uniformly by their Alibaba Cloud accounts.
  • RAM users must be authorized to log in to the console or use the API to access resources under the Alibaba Cloud account.
  • RAM users have independent login passwords or access keys.
  • Multiple RAM users can be created under one Alibaba Cloud account, corresponding to employees, systems or applications within the enterprise.

You can create RAM users and authorize them so that different RAM users have different resource access rights. When your enterprise has multiple users accessing resources collaboratively, you can use RAM to assign minimum permissions to users as needed, preventing multiple users from sharing Alibaba Cloud account passwords or access keys, thereby reducing enterprise security risks.

 

Log in to Alibaba Cloud, register for real-name authentication, get the secret key and id, and then set signature management and template management in the SMS service  

 

package com.macro.mall.common.util;

import com.aliyuncs.CommonRequest;
import com.aliyuncs.CommonResponse;
import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.IAcsClient;
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.exceptions.ServerException;
import com.aliyuncs.http.MethodType;
import com.aliyuncs.profile.DefaultProfile;

public class SendSms {
    public static void main(String[] args) {
        // <accessKeyId>、<accessSecret>上面申请的秘钥
        DefaultProfile profile = DefaultProfile.getProfile("cn-hangzhou", "LTAI5tFtSbNxoSvjBNx8z9BL", "S0eA17aixIf2uz7yIqbHZoMvEEotkX");
        IAcsClient client = new DefaultAcsClient(profile);

        CommonRequest request = new CommonRequest();
        request.setMethod(MethodType.POST);
        request.setDomain("dysmsapi.aliyuncs.com");
        request.setVersion("2017-05-25");
        request.setAction("SendSms");
        request.putQueryParameter("RegionId", "cn-hangzhou");
        request.putQueryParameter("PhoneNumbers", "XX");
        request.putQueryParameter("SignName", "XXX");
        request.putQueryParameter("TemplateCode", "SMS_XXX");
        // 模板中的占位符
        request.putQueryParameter("TemplateParam","{\"code\":\""+"XXX"+"\"}");
        try {
            CommonResponse response = client.getCommonResponse(request);
            System.out.println(response.getData());
        } catch (ServerException e) {
            e.printStackTrace();
        } catch (ClientException e) {
            e.printStackTrace();
        }
    }
}

 

 

 

Guess you like

Origin blog.csdn.net/s_sos0/article/details/130844727