|
|
@@ -0,0 +1,93 @@
|
|
|
+package org.dromara.common.core.utils.sms;
|
|
|
+
|
|
|
+import cn.hutool.http.HttpRequest;
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.dromara.common.core.domain.model.ErrorInfo;
|
|
|
+
|
|
|
+@Slf4j
|
|
|
+public class SmsUtil {
|
|
|
+
|
|
|
+// @Value("${sms.gateway.systemCode:SYS004}")
|
|
|
+// private String systemCode;
|
|
|
+//
|
|
|
+// @Value("${sms.gateway.secret:afcd53c8cfdcfb2b150238a783a04d355697d84857dacbd931522fa8ade94b2d}")
|
|
|
+// private String secret;
|
|
|
+//
|
|
|
+// @Value("${sms.gateway.url:http://172.16.137.140:48088/system/sms-gateway/send}") // http://59.231.239.52:48088/system/sms-gateway/send
|
|
|
+// private String url;
|
|
|
+
|
|
|
+
|
|
|
+ public static boolean send(String smsUrl, String systemCode, String secret, String desMobile, String content) {
|
|
|
+ try {
|
|
|
+ String systemKey = generateSystemKey(systemCode, secret);
|
|
|
+
|
|
|
+ JSONObject body = new JSONObject();
|
|
|
+ body.put("systemKey", systemKey);
|
|
|
+ body.put("desMobile", desMobile);
|
|
|
+ body.put("content", content);
|
|
|
+ body.put("CpPassword", "220324");
|
|
|
+ body.put("CpName", "fzgj");
|
|
|
+ body.put("userId", "test_user_001");
|
|
|
+ body.put("ExtCode", "10010");
|
|
|
+
|
|
|
+
|
|
|
+ String response = HttpRequest.post(smsUrl)
|
|
|
+ .header("Content-Type", "application/json")
|
|
|
+ .body(body.toJSONString())
|
|
|
+ .execute().body();
|
|
|
+
|
|
|
+ JSONObject result = JSONObject.parseObject(response);
|
|
|
+ JSONObject data = result.getJSONObject("data");
|
|
|
+ if (result.getInteger("code") != null && result.getInteger("code") == 0
|
|
|
+ && data != null && "0".equals(data.getString("code"))) {
|
|
|
+ log.info("短信发送成功: mobile={}, content={}, smsid={}", desMobile, content, data.getString("smsid"));
|
|
|
+ return true;
|
|
|
+ } else {
|
|
|
+ log.error("短信发送失败: mobile={}, response={}", desMobile, response);
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("短信发送异常: mobile={}", desMobile, e);
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public static String generateSystemKey(String systemCode, String secret) {
|
|
|
+ long timestamp = System.currentTimeMillis();
|
|
|
+ String data = systemCode + ":" + timestamp;
|
|
|
+ String signature = AesEncryptUtil.encrypt(data, secret);
|
|
|
+ return systemCode + ":" + timestamp + ":" + signature;
|
|
|
+ }
|
|
|
+
|
|
|
+ public static void main(String[] args) {
|
|
|
+ String systemCode = "SYS004";
|
|
|
+ String secret = "afcd53c8cfdcfb2b150238a783a04d355697d84857dacbd931522fa8ade94b2d";
|
|
|
+ String url = "http://172.16.137.140:48088/system/sms-gateway/send";
|
|
|
+
|
|
|
+
|
|
|
+ String message = "【湖南省委党校】" + " 您好:\n" +
|
|
|
+ "欢迎您参加【普通培训班】培训!"+ System.currentTimeMillis();
|
|
|
+
|
|
|
+ String message2 = "【湖南省委党校】您的登录验证码是:111,有效期3分钟,请勿泄露给他人。";
|
|
|
+
|
|
|
+ String message3 = String.format("【湖南省委党校】\n尊敬的【%s】:\n 欢迎您参加【%s】培训!\n 请去前台办理入住手续。" , "小王", "普通班");
|
|
|
+
|
|
|
+ String message4 = "【湖南省委党校】您好:\n" +
|
|
|
+ " 本次操作的验证码为:406899,您正在使用短信办理自助业务,有效期1分钟";
|
|
|
+
|
|
|
+ String message5 = "【湖南省委党校】{\"code\":400,\"type\":\"CONSUME_CHECK_FAIL\",\"message\":\"消费记录已上传\",\"detils\":\"消费记录已上传:3c9ca4eafa00090000475500000b4000\"}";
|
|
|
+
|
|
|
+ ErrorInfo errorInfo = new ErrorInfo();
|
|
|
+ errorInfo.setCode(400);
|
|
|
+ errorInfo.setMessage("消费记录已上传");
|
|
|
+ errorInfo.setType("CONSUME_CHECK_FAIL");
|
|
|
+ errorInfo.setDetils("消费记录已上传:3c9ca4eafa00090000475500000b4000");
|
|
|
+
|
|
|
+ String message6 = "【湖南省委党校】"+JSONObject.toJSONString(errorInfo);
|
|
|
+
|
|
|
+ send(url,systemCode, secret, "15674973790",message2);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+}
|