|
@@ -1,8 +1,11 @@
|
|
|
package thyyxxk.webserver.service.outpatient.wxapi;
|
|
|
|
|
|
+import cn.hutool.core.util.StrUtil;
|
|
|
import com.alibaba.fastjson.JSONArray;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
+import lombok.Data;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.jetbrains.annotations.NotNull;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.web.client.RestTemplate;
|
|
@@ -11,6 +14,9 @@ import thyyxxk.webserver.utils.SnowFlakeId;
|
|
|
import thyyxxk.webserver.utils.TokenUtil;
|
|
|
import thyyxxk.webserver.utils.WeComUtil;
|
|
|
|
|
|
+import javax.annotation.PostConstruct;
|
|
|
+import java.util.concurrent.ThreadLocalRandom;
|
|
|
+
|
|
|
@Service
|
|
|
@Slf4j
|
|
|
public class SendWxInfoService {
|
|
@@ -28,7 +34,7 @@ public class SendWxInfoService {
|
|
|
}
|
|
|
|
|
|
public JSONObject sendCorpWxMsg(String touser, String content) {
|
|
|
- String requestUrl= SEND_MSG_URL.replace("ACCESS_TOKEN", tokenService.getWeComSendMsgToken());
|
|
|
+ String requestUrl = SEND_MSG_URL.replace("ACCESS_TOKEN", tokenService.getWeComSendMsgToken());
|
|
|
JSONObject msgObj = new JSONObject();
|
|
|
msgObj.put("content", content);
|
|
|
JSONObject param = new JSONObject();
|
|
@@ -46,8 +52,56 @@ public class SendWxInfoService {
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
+ public static @NotNull String generateRandomNumber(int length) {
|
|
|
+ StringBuilder sb = new StringBuilder(length);
|
|
|
+ ThreadLocalRandom random = ThreadLocalRandom.current();
|
|
|
+ for (int i = 0; i < length; i++) {
|
|
|
+ sb.append(random.nextInt(0, 10)); // 生成0到9之间的随机数字
|
|
|
+ }
|
|
|
+ return sb.toString();
|
|
|
+ }
|
|
|
+
|
|
|
+ public static @NotNull String generateRandomNumber() {
|
|
|
+ return generateRandomNumber(6);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Data
|
|
|
+ public static class Verification {
|
|
|
+ private String verificationCode;
|
|
|
+ private String error;
|
|
|
+ }
|
|
|
+
|
|
|
+ public Verification sendResetPassword(String touser) {
|
|
|
+ String requestUrl = SEND_MSG_URL.replace("ACCESS_TOKEN", tokenService.getWeComSendMsgToken());
|
|
|
+ String verificationCode = generateRandomNumber();
|
|
|
+ JSONObject msgObj = new JSONObject() {{
|
|
|
+ put("content", StrUtil.format("重置密码\n您的验证码为:【{}】\n30分钟有效", verificationCode));
|
|
|
+ }};
|
|
|
+ JSONObject param = new JSONObject() {{
|
|
|
+ put("touser", touser);
|
|
|
+ put("msgtype", "text");
|
|
|
+ put("agentid", AGENT_ID);
|
|
|
+ put("safe", 0);
|
|
|
+ put("text", msgObj);
|
|
|
+ }};
|
|
|
+
|
|
|
+ RestTemplate restTemplate = new RestTemplate();
|
|
|
+ String response = restTemplate.postForObject(requestUrl, param, String.class);
|
|
|
+ JSONObject result = JSONObject.parseObject(response);
|
|
|
+ log.info("推送企业信息消息:\n内容:{}\n结果:{}", param, result);
|
|
|
+ Integer errcode = result.getInteger("errcode");
|
|
|
+ int a = null == errcode ? -1 : errcode;
|
|
|
+
|
|
|
+ Verification v = new Verification();
|
|
|
+ v.setVerificationCode(a == 0 ? verificationCode : null);
|
|
|
+ v.setError(result.getString("errmsg"));
|
|
|
+ return v;
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
public int sendCriticalValue(String touser, String content) {
|
|
|
- String requestUrl= SEND_MSG_URL.replace("ACCESS_TOKEN", tokenService.getWeComSendMsgToken());
|
|
|
+ String requestUrl = SEND_MSG_URL.replace("ACCESS_TOKEN", tokenService.getWeComSendMsgToken());
|
|
|
JSONObject msgObj = new JSONObject();
|
|
|
msgObj.put("content", content);
|
|
|
JSONObject param = new JSONObject();
|