| | |
| | | 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"); |
| | | } |
| | | } |
| | |
| | | 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) { |
| | |
| | | |
| | | 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(); |
| | | } |
| | | } |