调用阿里云短信服务平台API实现ERP系统短信发送功能
1,发送短信工具类 SendSMSUtil
package sms;
import java.util.List;
/**
* 应用策略模式,方便以后扩展短信发送功能
* @title SendSMSUtil
* @description 阿里云短信发送util
* @author RenYY
*/
public class SendSMSUtil {
/**
* @description 短信发送接口
* @param sendSMS
* @return
* @author RenYY
* @date 2016年12月29日
*/
public static boolean sendSMS(ISendSMS sendSMS){
return sendSMS.sendSMS();
}
}
2,发送短信接口 ISendSMS
package sms;
import java.util.List;
/**
* @title ISendSMS
* @description 阿里云短信服务平台 发送短信接口
* @author RenYY
*/
public interface ISendSMS {
public boolean sendSMS();
}
3,发送短信实现类 SendSMS
package sms;
import java.io.IOException;
import java.io.InputStream;
import java.util.Map;
import java.util.Properties;
import org.apache.log4j.Logger;
import com.alibaba.fastjson.JSON;
import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.IAcsClient;
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.profile.DefaultProfile;
import com.aliyuncs.profile.IClientProfile;
import com.aliyuncs.sms.model.v20160927.SingleSendSmsRequest;
import com.aliyuncs.sms.model.v20160927.SingleSendSmsResponse;
import com.pxjy.puxin.kernel.utils.LoadProperties;
/**
* @title SendSMS
* @description 短信发送实现类,完成短信发送动作
* @author RenYY
*/
public class SendSMS implements ISendSMS {
private final static Logger log = Logger.getLogger(SendSMS.class);
private static String aliyun_sms_region_id =