|
|
@@ -0,0 +1,66 @@
|
|
|
+package com.txz.cif.service.impl;
|
|
|
+
|
|
|
+import cn.hutool.http.HttpUtil;
|
|
|
+import cn.hutool.json.JSONObject;
|
|
|
+import cn.hutool.json.JSONUtil;
|
|
|
+import com.txz.cif.configurer.jpush.JPushConf;
|
|
|
+import com.txz.cif.dto.jpush.JPushSmsDTO;
|
|
|
+import com.txz.cif.dto.jpush.JPushTemplateDTO;
|
|
|
+import com.txz.cif.service.JPushService;
|
|
|
+import lombok.AllArgsConstructor;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+
|
|
|
+/**
|
|
|
+ *
|
|
|
+ * @author: MTD®️
|
|
|
+ * @date: 2025/11/13
|
|
|
+ */
|
|
|
+@Service
|
|
|
+@Slf4j
|
|
|
+@AllArgsConstructor
|
|
|
+public class JPushServiceImpl implements JPushService {
|
|
|
+
|
|
|
+ private final JPushConf jPushConf;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public boolean sendSms(String mobile, String code) {
|
|
|
+ // {
|
|
|
+ // "to": "+8618701235678",
|
|
|
+ // "code": "398210",
|
|
|
+ // "template": {
|
|
|
+ // "id": "test-template-1",
|
|
|
+ // "language": "default",
|
|
|
+ // "params": {
|
|
|
+ // "key1": "value1",
|
|
|
+ // "key2": "value2"
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+
|
|
|
+ log.info("开始发送短信--->" + mobile + ",--->" + code);
|
|
|
+
|
|
|
+ JPushTemplateDTO templateDTO = new JPushTemplateDTO();
|
|
|
+
|
|
|
+ JPushSmsDTO pushSmsDTO = new JPushSmsDTO();
|
|
|
+ pushSmsDTO.setTo("+" + mobile);
|
|
|
+ pushSmsDTO.setCode(code);
|
|
|
+ pushSmsDTO.setTemplate(templateDTO);
|
|
|
+
|
|
|
+ String body = HttpUtil.createPost(jPushConf.getReqUrl())
|
|
|
+ .contentType("application/json")
|
|
|
+ .auth(jPushConf.getAuth())
|
|
|
+ .body(JSONUtil.toJsonStr(pushSmsDTO))
|
|
|
+ .execute()
|
|
|
+ .body();
|
|
|
+
|
|
|
+ log.info("jpush-sms-result:{}", body);
|
|
|
+ // "{\"code\":\"200\",\"message\":\"success\"}"
|
|
|
+ JSONObject resultJson = JSONUtil.parseObj(body);
|
|
|
+
|
|
|
+ if (resultJson.getInt("code") == 200) {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+}
|