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