From 7fca0ff445f4c19d547daf71b47201505cb2b9c0 Mon Sep 17 00:00:00 2001
From: wuxw <928255095@qq.com>
Date: 星期三, 01 十一月 2023 14:36:22 +0800
Subject: [PATCH] 优化代码
---
service-job/src/main/java/com/java110/job/msgNotify/WechatTemplateImpl.java | 44 ++++++++++++++++++++++++++++++++++++++++++--
1 files changed, 42 insertions(+), 2 deletions(-)
diff --git a/service-job/src/main/java/com/java110/job/msgNotify/WechatTemplateImpl.java b/service-job/src/main/java/com/java110/job/msgNotify/WechatTemplateImpl.java
index 1ba8a53..0b7a51e 100644
--- a/service-job/src/main/java/com/java110/job/msgNotify/WechatTemplateImpl.java
+++ b/service-job/src/main/java/com/java110/job/msgNotify/WechatTemplateImpl.java
@@ -204,7 +204,7 @@
JSONObject template = null;
for (int templateIndex = 0; templateIndex < templateLists.size(); templateIndex++) {
template = templateLists.getJSONObject(templateIndex);
- if (title.equals(template.getString("title"))) {
+ if (title.equals(template.getString("title")) && templateHasKey(template.getString("content"), keys)) {
return template.getString("template_id");
}
}
@@ -217,13 +217,29 @@
templateLists = templateListObj.getJSONArray("template_list");
for (int templateIndex = 0; templateIndex < templateLists.size(); templateIndex++) {
template = templateLists.getJSONObject(templateIndex);
- if (title.equals(template.getString("title"))) {
+ if (title.equals(template.getString("title")) && templateHasKey(template.getString("content"), keys)) {
return template.getString("template_id");
}
}
return "-1";
+ }
+
+ /**
+ * 鍏抽敭瀛楁槸鍚﹂兘鍖呭惈
+ * @param content
+ * @param keys
+ * @return
+ */
+ private boolean templateHasKey(String content, String[] keys) {
+ for (String key : keys) {
+ if (!content.contains(key)) {
+ return false;
+ }
+ }
+
+ return true;
}
public String getAccessToken(String communityId) {
@@ -251,4 +267,28 @@
return accessToken;
}
+
+ @Override
+ public String getAppId(String communityId) {
+ SmallWeChatDto smallWeChatDto = new SmallWeChatDto();
+ smallWeChatDto.setWeChatType(SmallWeChatDto.WECHAT_TYPE_PUBLIC);
+ smallWeChatDto.setObjType(SmallWeChatDto.OBJ_TYPE_COMMUNITY);
+ smallWeChatDto.setObjId(communityId);
+ List<SmallWeChatDto> smallWeChatDtos = smallWeChatInnerServiceSMOImpl.querySmallWeChats(smallWeChatDto);
+
+ if (smallWeChatDtos == null || smallWeChatDtos.size() < 1) {
+ String appIdCache = MappingCache.getValue(WechatConstant.WECHAT_DOMAIN, "appId");
+ String appSecretCache = MappingCache.getValue(WechatConstant.WECHAT_DOMAIN, "appSecret");
+ String mchIdCache = MappingCache.getValue(WechatConstant.WECHAT_DOMAIN, "mchId");
+ String keyCache = MappingCache.getValue(MappingConstant.WECHAT_STORE_DOMAIN, "key");
+ smallWeChatDto = new SmallWeChatDto();
+ smallWeChatDto.setAppId(appIdCache);
+ smallWeChatDto.setAppSecret(appSecretCache);
+ smallWeChatDto.setMchId(mchIdCache);
+ smallWeChatDto.setPayPassword(keyCache);
+ } else {
+ smallWeChatDto = smallWeChatDtos.get(0);
+ }
+ return smallWeChatDto.getAppId();
+ }
}
--
Gitblit v1.8.0