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 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"; //审核延后

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.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);

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);
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;

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
Map<String, Object> result = WXXmlToMapUtil.multilayerXmlToMap(msg);
Map<String,Object> xml = (Map<String, Object>) 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;
}
}

Loading…
Cancel
Save