| package com.doumee.core.utils.aliyun; | 
|   | 
| import com.alibaba.fastjson.JSONObject; | 
| import com.aliyuncs.CommonRequest; | 
| import com.aliyuncs.CommonResponse; | 
| import com.aliyuncs.DefaultAcsClient; | 
| import com.aliyuncs.IAcsClient; | 
| import com.aliyuncs.http.MethodType; | 
| import com.aliyuncs.profile.DefaultProfile; | 
| import com.doumee.core.constants.ResponseStatus; | 
| import com.doumee.core.exception.BusinessException; | 
| import com.doumee.core.utils.Constants; | 
|   | 
| import java.security.SecureRandom; | 
| import java.util.Map; | 
|   | 
| /** | 
|  * 阿里云 SMS 短信工具类 | 
|  * @author RenKang | 
|  */ | 
| public class ALiYunSmSUtil { | 
|   | 
|     public static CommonResponse sendMessage(String phone, Map<String, Object> codeMap) { | 
|         /** | 
|          * 连接阿里云: | 
|          * | 
|          * 三个参数: | 
|          * regionId 不要动,默认使用官方的 | 
|          * accessKeyId 自己的用户accessKeyId | 
|          * accessSecret 自己的用户accessSecret | 
|          */ | 
|         DefaultProfile profile = DefaultProfile.getProfile( | 
|                 "cn-hangzhou", "LTAI5tP56bE38bWvqqfSRkCQ", "lXcIyDrc9K01x3FjSgZqcKlrHwsE8b"); | 
|         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("PhoneNumbers", phone); | 
|         // 短信签名 | 
|         request.putQueryParameter("SignName", "豆米科技"); | 
|         // 短信模版CODE | 
|         request.putQueryParameter("TemplateCode", "SMS_243960729"); | 
|         // 构建短信验证码 | 
|         request.putQueryParameter("TemplateParam", JSONObject.toJSONString(codeMap)); | 
|         try { | 
|             CommonResponse response = client.getCommonResponse(request); | 
|             return response; | 
|         }catch (Exception e) { | 
|             e.printStackTrace(); | 
|         } | 
|         throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"发送失败,请联系管理员"); | 
|     } | 
|   | 
|   | 
|   | 
| } |