赞
踩
- import cn.hutool.http.HttpRequest;
-
- import java.util.HashMap;
- import java.util.Map;
-
- /**
- * 短信发送工具类
- */
- public class SMSUtils {
-
- /**
- * *****************************
- 添加http请求工具类在pom.xml中
- <dependency>
- <groupId>cn.hutool</groupId>
- <artifactId>hutool-all</artifactId>
- <version>4.5.15</version>
- </dependency>
- * *****************************
- String mobile = "";
- //验证码
- String code = "5790";
- //签名ID。(联系客服申请。测试请用:2e65b1bb3d054466b82f0c9d125465e2)
- String smsSignId="2e65b1bb3d054466b82f0c9d125465e2";
- //模板ID。(联系客服申请。测试ID请用:908e94ccf08b4476ba6c876d13f084ad,短信内容为 { 验证码:**code**,**minute**分钟内有效,请勿泄漏于他人!})
- String templateId="908e94ccf08b4476ba6c876d13f084ad";
- //应用code https://market.console.aliyun.com/imageconsole/index.htm?#/bizlist?_k=r5f9m0 查找
- String appCode="";
- */
- public static void sendMessage(String smsSignId, String templateId,String mobile,String code,String appCode){
- //手机号码
-
-
- //请求连接
- String host = "https://gyytz.market.alicloudapi.com/sms/smsSend";
- //拼装请求体
- Map<String, Object> querys = new HashMap<String, Object>();
- querys.put("mobile", mobile);
- querys.put("param", "**code**:"+code+",**minute**:5");
- querys.put("smsSignId", smsSignId);
- querys.put("templateId", templateId);
-
- try {
- String result = HttpRequest.post(host)
- .header("Authorization", "APPCODE " + appCode)//头信息,多个头信息多次调用此方法即可
- .form(querys)//表单内容
- .timeout(20000)//超时,毫秒
- .execute().body();
- System.out.println(result);
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
-
- }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。