wuxw
2023-11-01 7fca0ff445f4c19d547daf71b47201505cb2b9c0
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();
    }
}