From f489119f6f8a2c789c1249cb7403ceb4b105b6f6 Mon Sep 17 00:00:00 2001 From: zxc <954985706@qq.com> Date: Tue, 28 Jul 2020 09:03:43 +0800 Subject: [PATCH] =?UTF-8?q?=E5=BE=AE=E4=BF=A1=E7=AC=AC=E4=B8=89=E6=96=B9?= =?UTF-8?q?=E5=B9=B3=E5=8F=B0-{APPID}/callback=E4=BF=AE=E6=94=B9=EF=BC=8C?= =?UTF-8?q?=E8=8E=B7=E5=8F=96component=5Faccess=5Ftoken=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/epmet/constant/ModuleConstant.java | 3 + .../epmet/controller/WarrantController.java | 3 +- .../ComponentVerifyTicketServiceImpl.java | 82 +++++++++---------- .../service/impl/WarrantServiceImpl.java | 60 +++++++------- 4 files changed, 77 insertions(+), 71 deletions(-) diff --git a/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/constant/ModuleConstant.java b/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/constant/ModuleConstant.java index d787e30ed1..1bc5e3b98b 100644 --- a/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/constant/ModuleConstant.java +++ b/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/constant/ModuleConstant.java @@ -75,6 +75,9 @@ public interface ModuleConstant { //代码审核结果推送 如下 String EVENT = "Event"; + String MSG_TYPE = "MsgType"; + String EVENT_LOW = "event"; + String TEXT = "text"; String WEAPP_AUDIT_SUCCESS = "weapp_audit_success"; //审核通过 String WEAPP_AUDIT_FAIL = "weapp_audit_fail"; //审核不通过 String WEAPP_AUDIT_DELAY = "weapp_audit_delay"; //审核延后 diff --git a/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/controller/WarrantController.java b/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/controller/WarrantController.java index 2760162a5c..90139540e1 100644 --- a/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/controller/WarrantController.java +++ b/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/controller/WarrantController.java @@ -6,6 +6,7 @@ import lombok.extern.slf4j.Slf4j; import org.dom4j.DocumentException; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; @@ -25,7 +26,7 @@ public class WarrantController { @Autowired private WarrantService warrantService; - @RequestMapping(value ="/{APPID}/callback") + @PostMapping(value ="/{APPID}/callback") public String acceptMessageAndEvent(HttpServletRequest request, @PathVariable("APPID") String appid, HttpServletResponse response)throws IOException, DocumentException, AesException { return warrantService.acceptMessageAndEvent(request, appid, response); diff --git a/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/service/impl/ComponentVerifyTicketServiceImpl.java b/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/service/impl/ComponentVerifyTicketServiceImpl.java index d00460d8a0..85986d041e 100644 --- a/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/service/impl/ComponentVerifyTicketServiceImpl.java +++ b/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/service/impl/ComponentVerifyTicketServiceImpl.java @@ -201,24 +201,26 @@ public class ComponentVerifyTicketServiceImpl implements ComponentVerifyTicketSe jsonObject.put(ModuleConstant.TICKET_UNDERLINE_KEY, componentVerifyTicket); String post = HttpClientManager.getInstance().sendPostByJSON(WxMaCodeConstant.API_COMPONENT_TOKEN_URL, JSON.toJSONString(jsonObject)).getData(); Map hashMap = JSON.parseObject(post, Map.class); - String componentAccessToken = hashMap.get(COMPONENT_ACCESS_TOKEN).toString(); - Integer expiresIn = (Integer) hashMap.get(ModuleConstant.EXPIRES_IN); - Date expiresInTime = this.countExpirationTime(expiresIn.toString()); - if (StringUtils.isNotEmpty(componentAccessToken)) { - //令牌信息存DB - ComponentAccessTokenFormDTO formDTO = new ComponentAccessTokenFormDTO(); - formDTO.setComponentAccessToken(componentAccessToken); - formDTO.setExpiresInTime(expiresInTime); - //先逻辑删,在插入 - log.info(ThirdRunTimeInfoConstant.START_DELETE_COMPONENT_ACCESS_TOKEN); - componentAccessTokenDao.deleteOldComponentAccessToken(); - componentAccessTokenDao.insertComponentAccessToken(formDTO); - //存缓存 - redisThird.setComponentAccessToken(componentAccessToken); - } else { - throw new RenException(ThirdRunTimeInfoConstant.FAILURE_ACCESS_TOKEN); + if (!hashMap.containsKey(ModuleConstant.ERR_MSG)) { + String componentAccessToken = hashMap.get(COMPONENT_ACCESS_TOKEN).toString(); + Integer expiresIn = (Integer) hashMap.get(ModuleConstant.EXPIRES_IN); + Date expiresInTime = this.countExpirationTime(expiresIn.toString()); + if (StringUtils.isNotEmpty(componentAccessToken)) { + //令牌信息存DB + ComponentAccessTokenFormDTO formDTO = new ComponentAccessTokenFormDTO(); + formDTO.setComponentAccessToken(componentAccessToken); + formDTO.setExpiresInTime(expiresInTime); + //先逻辑删,在插入 + log.info(ThirdRunTimeInfoConstant.START_DELETE_COMPONENT_ACCESS_TOKEN); + componentAccessTokenDao.deleteOldComponentAccessToken(); + componentAccessTokenDao.insertComponentAccessToken(formDTO); + //存缓存 + redisThird.setComponentAccessToken(componentAccessToken); + } else { + throw new RenException(ThirdRunTimeInfoConstant.FAILURE_ACCESS_TOKEN); + } + log.info(ThirdRunTimeInfoConstant.SUCCESS_ACCESS_TOKEN); } - log.info(ThirdRunTimeInfoConstant.SUCCESS_ACCESS_TOKEN); } } @@ -232,31 +234,27 @@ public class ComponentVerifyTicketServiceImpl implements ComponentVerifyTicketSe public String preAuthCode() { log.info(START_GET_PRE_AUTH_CODE); String preAuthCode = ""; - try { - String accessToken = redisThird.getComponentAccessToken(); - JSONObject jsonObject = new JSONObject(); - jsonObject.put(ModuleConstant.COMPONENT_APPID, componentAppId); - String post = HttpClientManager.getInstance().sendPostByJSON(WxMaCodeConstant.API_CREATE_PREAUTHCODE_URL + accessToken, JSON.toJSONString(jsonObject)).getData(); - log.info(String.format(POST_RESULT,post)); - Map hashMap = JSON.parseObject(post, Map.class); - preAuthCode = hashMap.get(ModuleConstant.PRE_AUTH_CODE).toString(); - Integer expiresIn = (Integer) hashMap.get(ModuleConstant.EXPIRES_IN); - Date expiresInTime = this.countExpirationTime(expiresIn.toString()); - if (StringUtils.isNotEmpty(preAuthCode)) { - //预授权码 存DB - PreAuthTokenFormDTO formDTO = new PreAuthTokenFormDTO(); - formDTO.setPreAuthToken(preAuthCode); - formDTO.setExpiresInTime(expiresInTime); - //先逻辑删除,在插入DB - preAuthTokenDao.updateOldPreAuthCode(); - preAuthTokenDao.insertPreAuthToken(formDTO); - //预授权码 放入缓存 - redisThird.setPreAuthCode(preAuthCode); - } else { - throw new RuntimeException(FAILURE_GET_PRE_AUTH_CODE); - } - } catch (Exception e) { - e.printStackTrace(); + String accessToken = redisThird.getComponentAccessToken(); + JSONObject jsonObject = new JSONObject(); + jsonObject.put(ModuleConstant.COMPONENT_APPID, componentAppId); + String post = HttpClientManager.getInstance().sendPostByJSON(WxMaCodeConstant.API_CREATE_PREAUTHCODE_URL + accessToken, JSON.toJSONString(jsonObject)).getData(); + log.info(String.format(POST_RESULT,post)); + Map hashMap = JSON.parseObject(post, Map.class); + preAuthCode = hashMap.get(ModuleConstant.PRE_AUTH_CODE).toString(); + Integer expiresIn = (Integer) hashMap.get(ModuleConstant.EXPIRES_IN); + Date expiresInTime = this.countExpirationTime(expiresIn.toString()); + if (StringUtils.isNotEmpty(preAuthCode)) { + //预授权码 存DB + PreAuthTokenFormDTO formDTO = new PreAuthTokenFormDTO(); + formDTO.setPreAuthToken(preAuthCode); + formDTO.setExpiresInTime(expiresInTime); + //先逻辑删除,在插入DB + preAuthTokenDao.updateOldPreAuthCode(); + preAuthTokenDao.insertPreAuthToken(formDTO); + //预授权码 放入缓存 + redisThird.setPreAuthCode(preAuthCode); + } else { + throw new RuntimeException(FAILURE_GET_PRE_AUTH_CODE); } log.info(END_GET_PRE_AUTH_CODE); return preAuthCode; diff --git a/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/service/impl/WarrantServiceImpl.java b/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/service/impl/WarrantServiceImpl.java index d5a3d500af..c55f647789 100644 --- a/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/service/impl/WarrantServiceImpl.java +++ b/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/service/impl/WarrantServiceImpl.java @@ -90,35 +90,39 @@ public class WarrantServiceImpl implements WarrantService { // 将xml转为map Map result = WXXmlToMapUtil.multilayerXmlToMap(msg); Map xml = (Map) result.get(ModuleConstant.XML); - Long createTime = Long.valueOf(xml.get(ModuleConstant.CREATE_TIME).toString()); - CodeAuditRecordFormDTO codeAuditRecord = componentVerifyTicketService.mapToEntity(xml, CodeAuditRecordFormDTO.class); - codeAuditRecord.setWechatCreateTime(new Date(createTime)); - String toUserName = codeAuditRecord.getToUserName();//小程序原始ID - CustomerIdAndClientResultDTO customerIdAndClientResultDTO = miniInfoDao.selectCustomerIdAndClientByToUserName(toUserName); - String clientType = customerIdAndClientResultDTO.getClientType(); - String customerId = customerIdAndClientResultDTO.getCustomerId(); - TemplateAndAppIdResultDTO templateAndAppId = codeCustomerDao.selectTemplateAndAppId(customerId, clientType); - String authAppId = templateAndAppId.getAuthAppId(); - String templateId = templateAndAppId.getTemplateId(); - codeAuditRecord.setClientType(clientType); - codeAuditRecord.setCustomerId(customerId); - codeAuditRecord.setAuthAppId(authAppId); - codeAuditRecord.setTemplateId(templateId); - //插入 代码审核 记录 - codeAuditRecordDao.insertCodeAuditRecord(codeAuditRecord); - // 修改 code_audit_result 中的代码审核结果 - String event = codeAuditRecord.getEvent(); - String codeResult = null; - switch (event){ - case ModuleConstant.WEAPP_AUDIT_SUCCESS: - codeResult = ModuleConstant.AUDIT_SUCCESS; - case ModuleConstant.WEAPP_AUDIT_FAIL: - codeResult = ModuleConstant.AUDIT_FAILED; - case ModuleConstant.WEAPP_AUDIT_DELAY: - codeResult = ModuleConstant.DELAY; + if (xml.get(ModuleConstant.MSG_TYPE).equals(ModuleConstant.EVENT_LOW)) { + Long createTime = Long.valueOf(xml.get(ModuleConstant.CREATE_TIME).toString()); + CodeAuditRecordFormDTO codeAuditRecord = componentVerifyTicketService.mapToEntity(xml, CodeAuditRecordFormDTO.class); + codeAuditRecord.setWechatCreateTime(new Date(createTime)); + String toUserName = codeAuditRecord.getToUserName();//小程序原始ID + CustomerIdAndClientResultDTO customerIdAndClientResultDTO = miniInfoDao.selectCustomerIdAndClientByToUserName(toUserName); + String clientType = customerIdAndClientResultDTO.getClientType(); + String customerId = customerIdAndClientResultDTO.getCustomerId(); + TemplateAndAppIdResultDTO templateAndAppId = codeCustomerDao.selectTemplateAndAppId(customerId, clientType); + String authAppId = templateAndAppId.getAuthAppId(); + String templateId = templateAndAppId.getTemplateId(); + codeAuditRecord.setClientType(clientType); + codeAuditRecord.setCustomerId(customerId); + codeAuditRecord.setAuthAppId(authAppId); + codeAuditRecord.setTemplateId(templateId); + //插入 代码审核 记录 + codeAuditRecordDao.insertCodeAuditRecord(codeAuditRecord); + // 修改 code_audit_result 中的代码审核结果 + String event = codeAuditRecord.getEvent(); + String codeResult = null; + switch (event) { + case ModuleConstant.WEAPP_AUDIT_SUCCESS: + codeResult = ModuleConstant.AUDIT_SUCCESS; + case ModuleConstant.WEAPP_AUDIT_FAIL: + codeResult = ModuleConstant.AUDIT_FAILED; + case ModuleConstant.WEAPP_AUDIT_DELAY: + codeResult = ModuleConstant.DELAY; + } + String codeCustomerId = codeCustomerDao.selectCodeCustomerId(codeAuditRecord); + codeAuditResultDao.updateAuditResult(customerId, codeCustomerId, codeResult); + }else if (xml.get(ModuleConstant.MSG_TYPE).equals(ModuleConstant.TEXT)){ + } - String codeCustomerId = codeCustomerDao.selectCodeCustomerId(codeAuditRecord); - codeAuditResultDao.updateAuditResult(customerId,codeCustomerId,codeResult); return ModuleConstant.SUCCESS; } }