|
@@ -0,0 +1,59 @@
|
|
|
+package com.huimv.farm.damsubsidy.common.utils;
|
|
|
+
|
|
|
+
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.huimv.farm.damsubsidy.entity.Vo.SmsVo;
|
|
|
+import org.springframework.http.HttpEntity;
|
|
|
+import org.springframework.http.HttpHeaders;
|
|
|
+import org.springframework.http.MediaType;
|
|
|
+import org.springframework.util.DigestUtils;
|
|
|
+import org.springframework.web.client.RestTemplate;
|
|
|
+
|
|
|
+import java.util.Base64;
|
|
|
+
|
|
|
+public class SmsUtils {
|
|
|
+ //模板发送
|
|
|
+ private static String URL = "http://112.35.1.155:1992/sms/tmpsubmit";
|
|
|
+ private static String ECNAME = "通渭县畜牧兽医服务中心";
|
|
|
+ private static String APID = "admin";
|
|
|
+ private static String SIGN = "SJsLKUNDR";
|
|
|
+
|
|
|
+ public static JSONObject sendSms(String templateId,String mobiles) throws Exception{
|
|
|
+ RestTemplate restTemplate = new RestTemplate();
|
|
|
+
|
|
|
+
|
|
|
+ //String mobiles = "13140429955,13140429955";
|
|
|
+// String templateId = "e683346d84234fc1a0816791587a4335";
|
|
|
+
|
|
|
+ HttpHeaders httpHeaders = new HttpHeaders();
|
|
|
+ httpHeaders.setContentType(MediaType.APPLICATION_JSON);
|
|
|
+ String[] paramss = {"632431"};
|
|
|
+
|
|
|
+ SmsVo submit = new SmsVo();
|
|
|
+ submit.setApId(APID);
|
|
|
+ submit.setEcName(ECNAME);
|
|
|
+ submit.setMobiles("13140429955");
|
|
|
+ submit.setSign(SIGN);
|
|
|
+ submit.setAddSerial("");
|
|
|
+ submit.setTemplateId(templateId);
|
|
|
+ submit.setSecretKey("XuMu@123");
|
|
|
+ submit.setParams(JSON.toJSONString(paramss));
|
|
|
+
|
|
|
+ StringBuffer stringBuffer = new StringBuffer();
|
|
|
+ stringBuffer.append(submit.getEcName())
|
|
|
+ .append(submit.getApId())
|
|
|
+ .append(submit.getSecretKey())
|
|
|
+ .append(submit.getTemplateId())
|
|
|
+ .append(submit.getMobiles())
|
|
|
+ .append(submit.getParams())
|
|
|
+ .append(submit.getSign())
|
|
|
+ .append(submit.getAddSerial());
|
|
|
+ String selfMac = DigestUtils.md5DigestAsHex(stringBuffer.toString().getBytes()).toLowerCase();
|
|
|
+ String reqText = JSON.toJSONString(submit);
|
|
|
+ String body = Base64.getEncoder().encodeToString(reqText.getBytes());
|
|
|
+ HttpEntity<String> httpEntity = new HttpEntity<String>(body, httpHeaders);
|
|
|
+ JSONObject result = restTemplate.postForObject(URL, httpEntity, JSONObject.class);
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+}
|