首页 > 其他分享 >阿里云短信

阿里云短信

时间:2023-02-06 10:44:33浏览次数:27  
标签:aliyuncs 短信 String request param 阿里 import com

阿里云短信

需要创建Accesskey

 

需要创建签名 发送模板

 

 

调用api发送短信相关代码

package com.po.reggie.utils;

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;

/**
 * 短信发送工具类
 */
public class SMSUtils {

	/**
	 * 发送短信
	 * @param signName 签名
	 * @param templateCode 模板
	 * @param phoneNumbers 手机号
	 * @param param 参数
	 */
	public static void sendMessage(String signName, String templateCode,String phoneNumbers,String param){
		DefaultProfile profile = DefaultProfile.getProfile("cn-hangzhou", "LTAI5tM6p--------MScq1gq", "4fhp0t8j0y2-----UIlbgfH1GU");
		IAcsClient client = new DefaultAcsClient(profile);

		SendSmsRequest request = new SendSmsRequest();
		request.setSysRegionId("cn-hangzhou");
		request.setPhoneNumbers(phoneNumbers);
		request.setSignName(signName);
		request.setTemplateCode(templateCode);
		request.setTemplateParam("{\"code\":\""+param+"\"}");
		try {
			SendSmsResponse response = client.getAcsResponse(request);
			System.out.println("短信发送成功");
		}catch (ClientException e) {
			e.printStackTrace();
		}
	}


	public static void main(String[] args) {
		sendMessage("破土重生科技股份有限公司","SMS_154950909","13522715896","12345678");
	}

}

  

 

标签:aliyuncs,短信,String,request,param,阿里,import,com
From: https://www.cnblogs.com/popopopopo/p/17094690.html

相关文章