Browse Source

短信发送模板

zhaopeiqing 3 years ago
parent
commit
7595280168

+ 6 - 6
src/main/java/com/ssm/controller/business/SendMessageContorller.java

@@ -217,15 +217,15 @@ public class SendMessageContorller {
 	@WithoutUserLogin
 	@RoleLimit(pid = Const.SYSTEM_ROLE_LIMIT_PID, mid = Const.SYSTEM_ROLE_LIMIT_MID)
 	@Transactional(value = "txManager")
-	@RequestMapping(value = "sendSmsBySignId")
-	public void sendSms(HttpServletRequest request, HttpServletResponse response) {
+	@RequestMapping(value = "sendTemplateSms")
+	public void sendTemplateSms(HttpServletRequest request, HttpServletResponse response) {
 		JSONObject json = new JSONObject();
 		try {
 			request.setCharacterEncoding("utf-8");
-			String smsUserPhoens = request.getParameter("phones");
+			String smsUserPhones = request.getParameter("phones");
 			String content = request.getParameter("contents");
-			String signId = request.getParameter("signId");
-			String res = SmsUtil.sendNewSmsPostBySignId(smsUserPhoens, content, signId);
+			String templateId = request.getParameter("templateId");
+			String res = SmsUtil.sendNewTemplateSmsSmsPost(smsUserPhones, content, templateId);
 			Map mapObj = JSON.parseObject(res, Map.class);
 			String msgNo = mapObj.get("msg_no").toString();
 			Integer code = Integer.valueOf(mapObj.get("code").toString());
@@ -233,7 +233,7 @@ public class SendMessageContorller {
 			SmsRecord smsRecord = new SmsRecord();
 			smsRecord.setContent(content);
 			smsRecord.setCreateDate(new Date());
-			smsRecord.setPhoens(smsUserPhoens);
+			smsRecord.setPhoens(smsUserPhones);
 			smsRecord.setMsgid(msgNo);
 			smsRecordService.insertSelective(smsRecord);
 			if (code == 0) {// 提交供应商成功,查询发送是否成功

+ 5 - 4
src/main/java/com/ssm/util/sms/SmsUtil.java

@@ -120,17 +120,18 @@ public class SmsUtil {
 	 *
 	 * @param phones  手机号码
 	 * @param content 发送的内容
-	 * @param signId 模板Id
+	 * @param templateId 模板id
 	 * @return res    json返回值
 	 */
-	public static String sendNewSmsPostBySignId(String phones, String content, String signId) throws IOException {
+	public static String sendNewTemplateSmsSmsPost(String phones, String content, String templateId) throws IOException {
 		HttpClient httpClient = HttpClients.createDefault();
-		HttpPost httpPost = new HttpPost("https://api.4321.sh/sms/send");
+		HttpPost httpPost = new HttpPost("https://api.4321.sh/sms/template");
 		httpPost.addHeader("Content-Type", "application/json");
 		Map<String, Object> map = new HashMap<>();
 		map.put("apikey", "N11727b332");// api接口账号
 		map.put("secret", "1172799e3242ebe1");// api接口秘钥
-		map.put("sign_id", signId);// 签名id
+		map.put("sign_id", 101760);// 签名id
+		map.put("template_id", templateId);// 模板id
 		map.put("mobile", phones);// 手机号
 		map.put("content", content);// 短信内容
 		String json = JSON.toJSONString(map);