赞
踩
在短信服务中,找到国内消息—签名管理—添加签名, 并等待签名审核通过
在短信服务中,找到国内消息—模板管理—添加模板, 并等待签名审核通过
附带上相关阿里会使用到的SDK链接
短信服务API参考
(单人短信发送,批量短信发送等等相关传参操作都有写):https://help.aliyun.com/document_detail/419268.html?spm=a2c4g.44282.0.0.5db43d46F1iN7T工单提交
(遇到技术问题可以向工单中心提交):https://smartservice.console.aliyun.com/service/create-ticket?spm=5176.12818093.top-nav.ditem-0.3be916d0c5Ayjm&product=dysms发送测试短信(可单人可批量,甚至有源码):
https://help.aliyun.com/document_detail/108064.htm?spm=a2c4g.101346.0.0.84781bceleoajG#task-2126833
<dependency>
<groupId>com.aliyun</groupId>
<artifactId>aliyun-java-sdk-core</artifactId>
<version>4.5.3</version>
</dependency>
<dependency>
<groupId>com.aliyun</groupId>
<artifactId>aliyun-java-sdk-dysmsapi</artifactId>
<version>1.1.0</version>
</dependency>
只需要根据业务需求改动红框圈出的部分. 注: 模板code必须和模板参数保持一致!!!
public Boolean sendMessage() { DefaultProfile profile = DefaultProfile.getProfile("cn-hangzhou", "accessKeyId", "secret"); 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", "手机号");// 手机号 request.putQueryParameter("SignName", "申请好的签名");// 短信签名 request.putQueryParameter("TemplateCode", "申请好的模板code");// 短信模版CODE // 构建短信验证码 必须和模板保持一致 Map<String,Object> map = new HashMap<>(); map.put("code",12138); request.putQueryParameter("TemplateParam", JSONObject.toJSONString(map)); try { CommonResponse response = client.getCommonResponse(request); System.out.println(response.getData()); return response.getHttpResponse().isSuccess(); } catch (Exception e) { e.printStackTrace(); } return false; }
只需要根据业务需求改动红框圈出的部分. 注: 手机号,签名名称,模板参数等改为集合形式传参,并且集合中的签名名称数量,模板参数数量必须和手机号数量保持一致!!! 并且 模板code必须和模板参数保持一致!!!
public static String sendSmsBatch() { DefaultProfile profile = DefaultProfile.getProfile("cn-hangzhou", "accessKeyId", "secret"); 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("SendBatchSms"); request.putQueryParameter("RegionId", "cn-hangzhou"); request.putQueryParameter("PhoneNumberJson","[\"手机号1\",\"手机号2\"]"); request.putQueryParameter("SignNameJson", "[\"签名1\",\"签名2\"]"); request.putQueryParameter("TemplateParamJson", "[{\"code\":\"模板1\"},{\"code\":\"模板2\"}]"); request.putQueryParameter("TemplateCode", "SMS_460565185"); CommonResponse response= null; try { response = client.getCommonResponse(request); System.out.println(response.getData()); } catch (ServerException e) { e.printStackTrace(); } catch (ClientException e) { e.printStackTrace(); } return response.getData(); }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。