|
@@ -9,6 +9,7 @@ import org.jetbrains.annotations.NotNull;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.web.client.RestTemplate;
|
|
|
+import thyyxxk.webserver.config.exception.BizException;
|
|
|
import thyyxxk.webserver.service.TokenService;
|
|
|
import thyyxxk.webserver.utils.SnowFlakeId;
|
|
|
import thyyxxk.webserver.utils.WeComUtil;
|
|
@@ -33,7 +34,14 @@ public class SendWxInfoService {
|
|
|
}
|
|
|
|
|
|
public JSONObject sendCorpWxMsg(String touser, String content) {
|
|
|
- String requestUrl = SEND_MSG_URL.replace("ACCESS_TOKEN", tokenService.getWeComSendMsgToken());
|
|
|
+ String weComToken = tokenService.getWeComSendMsgToken();
|
|
|
+ if (StrUtil.isBlank(weComToken)) {
|
|
|
+ JSONObject json = new JSONObject();
|
|
|
+ json.put("errcode", -1);
|
|
|
+ json.put("msg", "无法推送消息,没有企业微信token");
|
|
|
+ return json;
|
|
|
+ }
|
|
|
+ String requestUrl = SEND_MSG_URL.replace("ACCESS_TOKEN", weComToken);
|
|
|
JSONObject msgObj = new JSONObject();
|
|
|
msgObj.put("content", content);
|
|
|
JSONObject param = new JSONObject();
|
|
@@ -70,7 +78,13 @@ public class SendWxInfoService {
|
|
|
}
|
|
|
|
|
|
public Verification sendResetPassword(String touser) {
|
|
|
- String requestUrl = SEND_MSG_URL.replace("ACCESS_TOKEN", tokenService.getWeComSendMsgToken());
|
|
|
+ Verification v = new Verification();
|
|
|
+ String weComToken = tokenService.getWeComSendMsgToken();
|
|
|
+ if (StrUtil.isBlank(weComToken)) {
|
|
|
+ v.setError("没有企业微信token");
|
|
|
+ return v;
|
|
|
+ }
|
|
|
+ String requestUrl = SEND_MSG_URL.replace("ACCESS_TOKEN", weComToken);
|
|
|
String verificationCode = generateRandomNumber();
|
|
|
JSONObject msgObj = new JSONObject() {{
|
|
|
put("content", StrUtil.format("重置密码\n您的验证码为:【{}】\n30分钟有效", verificationCode));
|
|
@@ -89,7 +103,6 @@ public class SendWxInfoService {
|
|
|
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;
|
|
@@ -98,7 +111,12 @@ public class SendWxInfoService {
|
|
|
|
|
|
|
|
|
public int sendCriticalValue(String touser, String content) {
|
|
|
- String requestUrl = SEND_MSG_URL.replace("ACCESS_TOKEN", tokenService.getWeComSendMsgToken());
|
|
|
+ String weComToken = tokenService.getWeComSendMsgToken();
|
|
|
+ if (StrUtil.isBlank(weComToken)) {
|
|
|
+ log.error("无法推送危急值,没有企业微信token");
|
|
|
+ return -1;
|
|
|
+ }
|
|
|
+ String requestUrl = SEND_MSG_URL.replace("ACCESS_TOKEN", weComToken);
|
|
|
JSONObject msgObj = new JSONObject();
|
|
|
msgObj.put("content", content);
|
|
|
JSONObject param = new JSONObject();
|
|
@@ -118,8 +136,14 @@ public class SendWxInfoService {
|
|
|
|
|
|
|
|
|
public JSONObject createGroupChat(String name) {
|
|
|
- String url = CREATE_GROUP_URL.replace("ACCESS_TOKEN", tokenService.getWeComSendMsgToken());
|
|
|
JSONObject msgobj = new JSONObject();
|
|
|
+ String weComToken = tokenService.getWeComSendMsgToken();
|
|
|
+ if (StrUtil.isBlank(weComToken)) {
|
|
|
+ msgobj.put("errcode", -1);
|
|
|
+ msgobj.put("msg", "无法创建企业微信群聊,没有企业微信token");
|
|
|
+ return msgobj;
|
|
|
+ }
|
|
|
+ String url = CREATE_GROUP_URL.replace("ACCESS_TOKEN", weComToken);
|
|
|
msgobj.put("name", name);
|
|
|
msgobj.put("owner", "1038");
|
|
|
JSONArray userlist = new JSONArray();
|
|
@@ -134,8 +158,14 @@ public class SendWxInfoService {
|
|
|
}
|
|
|
|
|
|
public JSONObject sendGroupMsg(String chatid, String content) {
|
|
|
- String url = SEND_GROUP_MSG.replace("ACCESS_TOKEN", tokenService.getWeComSendMsgToken());
|
|
|
JSONObject msgobj = new JSONObject();
|
|
|
+ String weComToken = tokenService.getWeComSendMsgToken();
|
|
|
+ if (StrUtil.isBlank(weComToken)) {
|
|
|
+ msgobj.put("errcode", -1);
|
|
|
+ msgobj.put("msg", "无法发送企业微信群聊消息,没有企业微信token");
|
|
|
+ return msgobj;
|
|
|
+ }
|
|
|
+ String url = SEND_GROUP_MSG.replace("ACCESS_TOKEN", weComToken);
|
|
|
msgobj.put("chatid", chatid);
|
|
|
msgobj.put("msgtype", "text");
|
|
|
JSONObject text = new JSONObject();
|
|
@@ -149,7 +179,12 @@ public class SendWxInfoService {
|
|
|
}
|
|
|
|
|
|
public void sendFile(String touser, String mediaId) {
|
|
|
- String requestUrl = SEND_MSG_URL.replace("ACCESS_TOKEN", tokenService.getWeComSendFileToken());
|
|
|
+ String weComToken = tokenService.getWeComSendFileToken();
|
|
|
+ if (StrUtil.isBlank(weComToken)) {
|
|
|
+ log.error("无法发送文件,没有企业微信token");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ String requestUrl = SEND_MSG_URL.replace("ACCESS_TOKEN", weComToken);
|
|
|
JSONObject obj = new JSONObject();
|
|
|
obj.put("agentid", 1000024);
|
|
|
obj.put("touser", touser);
|