| | |
| | | package com.stylefeng.guns.modular.system.util; |
| | | |
| | | import cn.hutool.crypto.SecureUtil; |
| | | import cn.hutool.http.HttpRequest; |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.alibaba.fastjson.JSONArray; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.stylefeng.guns.core.util.MD5Util; |
| | | import com.stylefeng.guns.core.util.ToolUtil; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.http.MediaType; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | import java.util.Arrays; |
| | |
| | | * @author zhibing.pu |
| | | * @Date 2023/3/31 10:05 |
| | | */ |
| | | @Component |
| | | public class SMSUtil { |
| | | |
| | | @Autowired |
| | | private HttpClientUtil httpClientUtil; |
| | | private static String username = "Ztrbkjhy"; |
| | | |
| | | private String username = "Ztrbkjhy"; |
| | | private static String password = "Zycx2023Rbkj"; |
| | | |
| | | private String password = "Zycx2023Rbkj"; |
| | | |
| | | private String signature = "【昭阳出行】"; |
| | | private static String signature = "【昭阳出行】"; |
| | | |
| | | |
| | | /** |
| | | * 模板短信发送 |
| | | * @param mobile 手机号 |
| | | * @param tpId 模板id |
| | | * @param records 模板变量[ |
| | | * @param records 模板变量 |
| | | * "records":[ |
| | | * { |
| | | * "mobile":"138****0000" |
| | | * "mobile":"138****0000", |
| | | * "tpContent":{ |
| | | * "var1":"变量1", |
| | | * "var2":"变量2" |
| | | * } |
| | | * }, |
| | | * { |
| | | * "mobile":"138****0001" |
| | | * "mobile":"138****0001", |
| | | * "tpContent":{ |
| | | * "var1":"变量2", |
| | | * "var2":"变量2" |
| | | * } |
| | | * } |
| | | * ] |
| | | */ |
| | | public void sendSmsTp(String mobile, Long tpId, List<Object> records){ |
| | | String url = "https://api.mix2.zthysms.com/v2/sendSmsTp"; |
| | | Map<String, Object> params = new HashMap<>(); |
| | | params.put("username", username); |
| | | params.put("password", password); |
| | | params.put("tKey", System.currentTimeMillis() / 1000); |
| | | params.put("signature", signature); |
| | | params.put("tpId", tpId); |
| | | params.put("mobile", mobile); |
| | | params.put("records", records); |
| | | String s = httpClientUtil.pushHttpRequset("POST", url, params, null, "json"); |
| | | if(ToolUtil.isEmpty(s)){ |
| | | return; |
| | | public static void sendSmsTp(Long tpId, JSONArray records){ |
| | | //地址 |
| | | String urls = "https://api.mix2.zthysms.com/v2/sendSmsTp"; |
| | | //请求入参 |
| | | JSONObject requestJson = new JSONObject(); |
| | | //账号 |
| | | requestJson.put("username", username); |
| | | //tKey |
| | | long tKey = System.currentTimeMillis() / 1000; |
| | | requestJson.put("tKey", tKey); |
| | | //明文密码 |
| | | requestJson.put("password", SecureUtil.md5(SecureUtil.md5(password) + tKey)); |
| | | //模板ID |
| | | requestJson.put("tpId", tpId); |
| | | //签名 |
| | | requestJson.put("signature", signature); |
| | | //扩展号 |
| | | requestJson.put("ext", ""); |
| | | //自定义参数 |
| | | requestJson.put("extend", ""); |
| | | requestJson.put("records", records); |
| | | String result = HttpRequest.post(urls) |
| | | .timeout(60000) |
| | | .body(requestJson.toJSONString(), MediaType.APPLICATION_JSON_UTF8_VALUE).execute().body(); |
| | | if(ToolUtil.isNotEmpty(result)){ |
| | | JSONObject jsonObject = JSON.parseObject(result); |
| | | int code = jsonObject.getIntValue("code"); |
| | | if(200 != code){ |
| | | System.err.println(jsonObject.getString("msg")); |
| | | } |
| | | }else{ |
| | | System.err.println("短信发送异常"); |
| | | } |
| | | } |
| | | |