...
|
...
|
@@ -276,7 +276,7 @@ public class WechatServiceImpl implements IWechatService { |
|
|
try {
|
|
|
//下载网络图片
|
|
|
String fileName = String.valueOf(System.currentTimeMillis()) + MessageSenderConstant.IMG_SUFFIX;
|
|
|
String pathFile = MessageSenderConstant.TEMP_FILE_PATH + fileName;
|
|
|
String pathFile = MessageSenderConstant.TEMP_FILE_PATH + '/' + fileName;
|
|
|
HttpClientUtil.downFromPicUrl(customMsgBO.getSendContent(), MessageSenderConstant.TEMP_FILE_PATH, fileName);
|
|
|
//上传微信 获取 media_id
|
|
|
String addMediaUrl = getMediaUrl(accessToken);
|
...
|
...
|
@@ -289,7 +289,7 @@ public class WechatServiceImpl implements IWechatService { |
|
|
JSONObject resultObj = JSONObject.parseObject(mediaIdResult);
|
|
|
|
|
|
//校验返回结果
|
|
|
if (!checkResult(customMsgBO, resultObj,fileName)) return false;
|
|
|
if (!checkResult(customMsgBO, resultObj,pathFile)) return false;
|
|
|
|
|
|
//删除下载的图片
|
|
|
deleteFile(pathFile);
|
...
|
...
|
@@ -315,12 +315,12 @@ public class WechatServiceImpl implements IWechatService { |
|
|
return Consts.ADD_MATERIAL_URL.replace("ACCESSTOKEN",accessToken.getToken()).replace("TYPE", WechatCustomMsgTypeEnum.IMAGE.getText());
|
|
|
}
|
|
|
|
|
|
private boolean checkResult(WechatCustomMsgBO customMsgBO, JSONObject resultObj,String fileName) throws KeyManagementException, NoSuchAlgorithmException, NoSuchProviderException, IOException {
|
|
|
private boolean checkResult(WechatCustomMsgBO customMsgBO, JSONObject resultObj,String pathFile) throws KeyManagementException, NoSuchAlgorithmException, NoSuchProviderException, IOException {
|
|
|
if(resultObj.get("errcode") != null){
|
|
|
//这里重新获取token再调用一次
|
|
|
String newAccessToken = sendWechatRequest.getNewToken(customMsgBO.getPublicNumCode());
|
|
|
String addMateralUrl = Consts.ADD_MATERIAL_URL.replace("ACCESSTOKEN",newAccessToken).replace("TYPE", WechatCustomMsgTypeEnum.IMAGE.getText());
|
|
|
String mediaIdResult = HttpClientUtil.connectHttpsByPost(addMateralUrl,new File(MessageSenderConstant.TEMP_FILE_PATH + fileName));
|
|
|
String mediaIdResult = HttpClientUtil.connectHttpsByPost(addMateralUrl,new File(pathFile));
|
|
|
if(StringUtils.isEmpty(mediaIdResult) || JSONObject.parseObject(mediaIdResult).get("errcode") != null){
|
|
|
logger.warn("checkResult with try again error,sceneKey is {},error is {}",customMsgBO.getSendKey(),mediaIdResult);
|
|
|
return false;
|
...
|
...
|
|