|
@@ -5,6 +5,7 @@ import com.alibaba.fastjson.JSONObject;
|
|
|
import com.tzld.piaoquan.growth.common.common.base.CommonResponse;
|
|
|
import com.tzld.piaoquan.growth.common.common.enums.MessageAttachmentTypeEnum;
|
|
|
import com.tzld.piaoquan.growth.common.component.HttpPoolClient;
|
|
|
+import com.tzld.piaoquan.growth.common.component.ProxyHttpPoolClient;
|
|
|
import com.tzld.piaoquan.growth.common.dao.mapper.GuaranteesVideoMapper;
|
|
|
import com.tzld.piaoquan.growth.common.dao.mapper.MessageAttachmentMapper;
|
|
|
import com.tzld.piaoquan.growth.common.model.bo.AdPutFlowParam;
|
|
@@ -52,6 +53,9 @@ public class MessageAttachmentServiceImpl implements MessageAttachmentService {
|
|
|
@Autowired
|
|
|
private HttpPoolClient httpPoolClient;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private ProxyHttpPoolClient proxyHttpPoolClient;
|
|
|
+
|
|
|
@Autowired
|
|
|
private WeComAccessTokenService weComAccessTokenService;
|
|
|
|
|
@@ -329,52 +333,43 @@ public class MessageAttachmentServiceImpl implements MessageAttachmentService {
|
|
|
if (StringUtils.isNotEmpty(mediaId)) {
|
|
|
return mediaId;
|
|
|
}
|
|
|
- if (corpId == 1L) {
|
|
|
- String filePath = UUID.randomUUID() + ".jpg"; // 临时文件路径
|
|
|
- try {
|
|
|
- HttpURLConnection httpUrl = (HttpURLConnection) new URL(cover).openConnection();
|
|
|
- httpUrl.connect();
|
|
|
- InputStream inputStream = httpUrl.getInputStream();
|
|
|
-
|
|
|
- // 将文件内容写入临时文件
|
|
|
- try (OutputStream outputStream = Files.newOutputStream(Paths.get(filePath))) {
|
|
|
- byte[] buffer = new byte[4096];
|
|
|
- int bytesRead;
|
|
|
- while ((bytesRead = inputStream.read(buffer)) != -1) {
|
|
|
- outputStream.write(buffer, 0, bytesRead);
|
|
|
- }
|
|
|
- }
|
|
|
- inputStream.close();
|
|
|
- httpUrl.disconnect();
|
|
|
- File file = new File(filePath);
|
|
|
- String weComAccessToken = weComAccessTokenService.getWeComAccessToken(corpId);
|
|
|
- String url = String.format(POST_WE_COM_MEDIA_UPLOAD + "?access_token=%s&type=%s", weComAccessToken, "image");
|
|
|
- String res = httpPoolClient.post(url, file);
|
|
|
- JSONObject jsonObject = JSONObject.parseObject(res);
|
|
|
- if (jsonObject != null && jsonObject.getInteger("errcode") == 0) {
|
|
|
- mediaId = jsonObject.getString("media_id");
|
|
|
- redisTemplate.opsForValue().set(key, mediaId, 2, TimeUnit.DAYS);
|
|
|
+
|
|
|
+ String filePath = UUID.randomUUID() + ".jpg"; // 临时文件路径
|
|
|
+ try {
|
|
|
+ HttpURLConnection httpUrl = (HttpURLConnection) new URL(cover).openConnection();
|
|
|
+ httpUrl.connect();
|
|
|
+ InputStream inputStream = httpUrl.getInputStream();
|
|
|
+
|
|
|
+ // 将文件内容写入临时文件
|
|
|
+ try (OutputStream outputStream = Files.newOutputStream(Paths.get(filePath))) {
|
|
|
+ byte[] buffer = new byte[4096];
|
|
|
+ int bytesRead;
|
|
|
+ while ((bytesRead = inputStream.read(buffer)) != -1) {
|
|
|
+ outputStream.write(buffer, 0, bytesRead);
|
|
|
}
|
|
|
- Files.delete(Paths.get(filePath));
|
|
|
- } catch (Exception e) {
|
|
|
- log.error("getPicMediaId error", e);
|
|
|
}
|
|
|
- return mediaId;
|
|
|
- } else {
|
|
|
- try {
|
|
|
- String weComAccessToken = weComAccessTokenService.getWeComAccessToken(corpId);
|
|
|
- String url = String.format(POST_WE_COM_MEDIA_UPLOAD + "?access_token=%s&type=%s", weComAccessToken, "image");
|
|
|
- String res = weComSendService.sendPostFile(url, cover);
|
|
|
- JSONObject jsonObject = JSONObject.parseObject(res);
|
|
|
- if (jsonObject != null && jsonObject.getInteger("errcode") == 0) {
|
|
|
- mediaId = jsonObject.getString("media_id");
|
|
|
- redisTemplate.opsForValue().set(key, mediaId, 2, TimeUnit.DAYS);
|
|
|
- }
|
|
|
- } catch (Exception e) {
|
|
|
- log.error("getPicMediaId error", e);
|
|
|
+ inputStream.close();
|
|
|
+ httpUrl.disconnect();
|
|
|
+ File file = new File(filePath);
|
|
|
+ String weComAccessToken = weComAccessTokenService.getWeComAccessToken(corpId);
|
|
|
+ String url = String.format(POST_WE_COM_MEDIA_UPLOAD + "?access_token=%s&type=%s", weComAccessToken, "image");
|
|
|
+ String res;
|
|
|
+ if (corpId == 1L) {
|
|
|
+ res = httpPoolClient.post(url, file);
|
|
|
+ } else {
|
|
|
+ res = proxyHttpPoolClient.post(url, file);
|
|
|
}
|
|
|
- return mediaId;
|
|
|
+ JSONObject jsonObject = JSONObject.parseObject(res);
|
|
|
+ if (jsonObject != null && jsonObject.getInteger("errcode") == 0) {
|
|
|
+ mediaId = jsonObject.getString("media_id");
|
|
|
+ redisTemplate.opsForValue().set(key, mediaId, 2, TimeUnit.DAYS);
|
|
|
+ }
|
|
|
+ Files.delete(Paths.get(filePath));
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("getPicMediaId error", e);
|
|
|
}
|
|
|
+ return mediaId;
|
|
|
+
|
|
|
}
|
|
|
|
|
|
|