Browse Source

微信第三方平台-{APPID}/callback修改,获取component_access_token修改

master
zxc 5 years ago
parent
commit
f489119f6f
  1. 3
      epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/constant/ModuleConstant.java
  2. 3
      epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/controller/WarrantController.java
  3. 82
      epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/service/impl/ComponentVerifyTicketServiceImpl.java
  4. 60
      epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/service/impl/WarrantServiceImpl.java

3
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 EVENT = "Event";
String MSG_TYPE = "MsgType";
String EVENT_LOW = "event";
String TEXT = "text";
String WEAPP_AUDIT_SUCCESS = "weapp_audit_success"; //审核通过 String WEAPP_AUDIT_SUCCESS = "weapp_audit_success"; //审核通过
String WEAPP_AUDIT_FAIL = "weapp_audit_fail"; //审核不通过 String WEAPP_AUDIT_FAIL = "weapp_audit_fail"; //审核不通过
String WEAPP_AUDIT_DELAY = "weapp_audit_delay"; //审核延后 String WEAPP_AUDIT_DELAY = "weapp_audit_delay"; //审核延后

3
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.dom4j.DocumentException;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable; 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.RequestMapping;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
@ -25,7 +26,7 @@ public class WarrantController {
@Autowired @Autowired
private WarrantService warrantService; private WarrantService warrantService;
@RequestMapping(value ="/{APPID}/callback") @PostMapping(value ="/{APPID}/callback")
public String acceptMessageAndEvent(HttpServletRequest request, @PathVariable("APPID") String appid, public String acceptMessageAndEvent(HttpServletRequest request, @PathVariable("APPID") String appid,
HttpServletResponse response)throws IOException, DocumentException, AesException { HttpServletResponse response)throws IOException, DocumentException, AesException {
return warrantService.acceptMessageAndEvent(request, appid, response); return warrantService.acceptMessageAndEvent(request, appid, response);

82
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); jsonObject.put(ModuleConstant.TICKET_UNDERLINE_KEY, componentVerifyTicket);
String post = HttpClientManager.getInstance().sendPostByJSON(WxMaCodeConstant.API_COMPONENT_TOKEN_URL, JSON.toJSONString(jsonObject)).getData(); String post = HttpClientManager.getInstance().sendPostByJSON(WxMaCodeConstant.API_COMPONENT_TOKEN_URL, JSON.toJSONString(jsonObject)).getData();
Map hashMap = JSON.parseObject(post, Map.class); Map hashMap = JSON.parseObject(post, Map.class);
String componentAccessToken = hashMap.get(COMPONENT_ACCESS_TOKEN).toString(); if (!hashMap.containsKey(ModuleConstant.ERR_MSG)) {
Integer expiresIn = (Integer) hashMap.get(ModuleConstant.EXPIRES_IN); String componentAccessToken = hashMap.get(COMPONENT_ACCESS_TOKEN).toString();
Date expiresInTime = this.countExpirationTime(expiresIn.toString()); Integer expiresIn = (Integer) hashMap.get(ModuleConstant.EXPIRES_IN);
if (StringUtils.isNotEmpty(componentAccessToken)) { Date expiresInTime = this.countExpirationTime(expiresIn.toString());
//令牌信息存DB if (StringUtils.isNotEmpty(componentAccessToken)) {
ComponentAccessTokenFormDTO formDTO = new ComponentAccessTokenFormDTO(); //令牌信息存DB
formDTO.setComponentAccessToken(componentAccessToken); ComponentAccessTokenFormDTO formDTO = new ComponentAccessTokenFormDTO();
formDTO.setExpiresInTime(expiresInTime); formDTO.setComponentAccessToken(componentAccessToken);
//先逻辑删,在插入 formDTO.setExpiresInTime(expiresInTime);
log.info(ThirdRunTimeInfoConstant.START_DELETE_COMPONENT_ACCESS_TOKEN); //先逻辑删,在插入
componentAccessTokenDao.deleteOldComponentAccessToken(); log.info(ThirdRunTimeInfoConstant.START_DELETE_COMPONENT_ACCESS_TOKEN);
componentAccessTokenDao.insertComponentAccessToken(formDTO); componentAccessTokenDao.deleteOldComponentAccessToken();
//存缓存 componentAccessTokenDao.insertComponentAccessToken(formDTO);
redisThird.setComponentAccessToken(componentAccessToken); //存缓存
} else { redisThird.setComponentAccessToken(componentAccessToken);
throw new RenException(ThirdRunTimeInfoConstant.FAILURE_ACCESS_TOKEN); } 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() { public String preAuthCode() {
log.info(START_GET_PRE_AUTH_CODE); log.info(START_GET_PRE_AUTH_CODE);
String preAuthCode = ""; String preAuthCode = "";
try { String accessToken = redisThird.getComponentAccessToken();
String accessToken = redisThird.getComponentAccessToken(); JSONObject jsonObject = new JSONObject();
JSONObject jsonObject = new JSONObject(); jsonObject.put(ModuleConstant.COMPONENT_APPID, componentAppId);
jsonObject.put(ModuleConstant.COMPONENT_APPID, componentAppId); String post = HttpClientManager.getInstance().sendPostByJSON(WxMaCodeConstant.API_CREATE_PREAUTHCODE_URL + accessToken, JSON.toJSONString(jsonObject)).getData();
String post = HttpClientManager.getInstance().sendPostByJSON(WxMaCodeConstant.API_CREATE_PREAUTHCODE_URL + accessToken, JSON.toJSONString(jsonObject)).getData(); log.info(String.format(POST_RESULT,post));
log.info(String.format(POST_RESULT,post)); Map hashMap = JSON.parseObject(post, Map.class);
Map hashMap = JSON.parseObject(post, Map.class); preAuthCode = hashMap.get(ModuleConstant.PRE_AUTH_CODE).toString();
preAuthCode = hashMap.get(ModuleConstant.PRE_AUTH_CODE).toString(); Integer expiresIn = (Integer) hashMap.get(ModuleConstant.EXPIRES_IN);
Integer expiresIn = (Integer) hashMap.get(ModuleConstant.EXPIRES_IN); Date expiresInTime = this.countExpirationTime(expiresIn.toString());
Date expiresInTime = this.countExpirationTime(expiresIn.toString()); if (StringUtils.isNotEmpty(preAuthCode)) {
if (StringUtils.isNotEmpty(preAuthCode)) { //预授权码 存DB
//预授权码 存DB PreAuthTokenFormDTO formDTO = new PreAuthTokenFormDTO();
PreAuthTokenFormDTO formDTO = new PreAuthTokenFormDTO(); formDTO.setPreAuthToken(preAuthCode);
formDTO.setPreAuthToken(preAuthCode); formDTO.setExpiresInTime(expiresInTime);
formDTO.setExpiresInTime(expiresInTime); //先逻辑删除,在插入DB
//先逻辑删除,在插入DB preAuthTokenDao.updateOldPreAuthCode();
preAuthTokenDao.updateOldPreAuthCode(); preAuthTokenDao.insertPreAuthToken(formDTO);
preAuthTokenDao.insertPreAuthToken(formDTO); //预授权码 放入缓存
//预授权码 放入缓存 redisThird.setPreAuthCode(preAuthCode);
redisThird.setPreAuthCode(preAuthCode); } else {
} else { throw new RuntimeException(FAILURE_GET_PRE_AUTH_CODE);
throw new RuntimeException(FAILURE_GET_PRE_AUTH_CODE);
}
} catch (Exception e) {
e.printStackTrace();
} }
log.info(END_GET_PRE_AUTH_CODE); log.info(END_GET_PRE_AUTH_CODE);
return preAuthCode; return preAuthCode;

60
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 // 将xml转为map
Map<String, Object> result = WXXmlToMapUtil.multilayerXmlToMap(msg); Map<String, Object> result = WXXmlToMapUtil.multilayerXmlToMap(msg);
Map<String,Object> xml = (Map<String, Object>) result.get(ModuleConstant.XML); Map<String,Object> xml = (Map<String, Object>) result.get(ModuleConstant.XML);
Long createTime = Long.valueOf(xml.get(ModuleConstant.CREATE_TIME).toString()); if (xml.get(ModuleConstant.MSG_TYPE).equals(ModuleConstant.EVENT_LOW)) {
CodeAuditRecordFormDTO codeAuditRecord = componentVerifyTicketService.mapToEntity(xml, CodeAuditRecordFormDTO.class); Long createTime = Long.valueOf(xml.get(ModuleConstant.CREATE_TIME).toString());
codeAuditRecord.setWechatCreateTime(new Date(createTime)); CodeAuditRecordFormDTO codeAuditRecord = componentVerifyTicketService.mapToEntity(xml, CodeAuditRecordFormDTO.class);
String toUserName = codeAuditRecord.getToUserName();//小程序原始ID codeAuditRecord.setWechatCreateTime(new Date(createTime));
CustomerIdAndClientResultDTO customerIdAndClientResultDTO = miniInfoDao.selectCustomerIdAndClientByToUserName(toUserName); String toUserName = codeAuditRecord.getToUserName();//小程序原始ID
String clientType = customerIdAndClientResultDTO.getClientType(); CustomerIdAndClientResultDTO customerIdAndClientResultDTO = miniInfoDao.selectCustomerIdAndClientByToUserName(toUserName);
String customerId = customerIdAndClientResultDTO.getCustomerId(); String clientType = customerIdAndClientResultDTO.getClientType();
TemplateAndAppIdResultDTO templateAndAppId = codeCustomerDao.selectTemplateAndAppId(customerId, clientType); String customerId = customerIdAndClientResultDTO.getCustomerId();
String authAppId = templateAndAppId.getAuthAppId(); TemplateAndAppIdResultDTO templateAndAppId = codeCustomerDao.selectTemplateAndAppId(customerId, clientType);
String templateId = templateAndAppId.getTemplateId(); String authAppId = templateAndAppId.getAuthAppId();
codeAuditRecord.setClientType(clientType); String templateId = templateAndAppId.getTemplateId();
codeAuditRecord.setCustomerId(customerId); codeAuditRecord.setClientType(clientType);
codeAuditRecord.setAuthAppId(authAppId); codeAuditRecord.setCustomerId(customerId);
codeAuditRecord.setTemplateId(templateId); codeAuditRecord.setAuthAppId(authAppId);
//插入 代码审核 记录 codeAuditRecord.setTemplateId(templateId);
codeAuditRecordDao.insertCodeAuditRecord(codeAuditRecord); //插入 代码审核 记录
// 修改 code_audit_result 中的代码审核结果 codeAuditRecordDao.insertCodeAuditRecord(codeAuditRecord);
String event = codeAuditRecord.getEvent(); // 修改 code_audit_result 中的代码审核结果
String codeResult = null; String event = codeAuditRecord.getEvent();
switch (event){ String codeResult = null;
case ModuleConstant.WEAPP_AUDIT_SUCCESS: switch (event) {
codeResult = ModuleConstant.AUDIT_SUCCESS; case ModuleConstant.WEAPP_AUDIT_SUCCESS:
case ModuleConstant.WEAPP_AUDIT_FAIL: codeResult = ModuleConstant.AUDIT_SUCCESS;
codeResult = ModuleConstant.AUDIT_FAILED; case ModuleConstant.WEAPP_AUDIT_FAIL:
case ModuleConstant.WEAPP_AUDIT_DELAY: codeResult = ModuleConstant.AUDIT_FAILED;
codeResult = ModuleConstant.DELAY; 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; return ModuleConstant.SUCCESS;
} }
} }

Loading…
Cancel
Save