|
@@ -3,10 +3,8 @@ package com.zanxiang.game.module.manage.service.api;
|
|
|
import com.zanxiang.game.module.base.ServerInfo;
|
|
|
import com.zanxiang.game.module.base.rpc.IWxApiServiceRpc;
|
|
|
import com.zanxiang.game.module.manage.pojo.dto.GameAppletDTO;
|
|
|
-import com.zanxiang.game.module.manage.pojo.dto.KfUploadTempMediaDTO;
|
|
|
import com.zanxiang.game.module.manage.service.IGameAppletService;
|
|
|
import com.zanxiang.module.util.JsonUtil;
|
|
|
-import com.zanxiang.module.util.exception.BaseException;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.dubbo.config.annotation.DubboReference;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
@@ -59,7 +57,13 @@ public class KfWxApiService {
|
|
|
.queryParam("access_token", accessToken)
|
|
|
.build().toUri();
|
|
|
// 发送请求
|
|
|
- String result = restTemplate.postForObject(uri, msgParamMap, String.class);
|
|
|
+ String result;
|
|
|
+ try {
|
|
|
+ result = restTemplate.postForObject(uri, msgParamMap, String.class);
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("客服消息发送异常, e : {}", e.getMessage());
|
|
|
+ return Tuples.of(400L, e.getMessage());
|
|
|
+ }
|
|
|
log.error("客服消息发送结果, result : {}", result);
|
|
|
Map<String, String> resultMap = JsonUtil.toMap(result, Map.class, String.class);
|
|
|
return Tuples.of(Long.valueOf(resultMap.get("errcode")), resultMap.get("errmsg"));
|
|
@@ -68,7 +72,15 @@ public class KfWxApiService {
|
|
|
/**
|
|
|
* 上传临时素材
|
|
|
*/
|
|
|
- public String mediaUpload(String accessToken, MultipartFile files) {
|
|
|
+ public Tuple2<Long, String> mediaUpload(Long gameId, MultipartFile files) {
|
|
|
+ GameAppletDTO gameAppletDTO = gameAppletService.getByGameId(gameId);
|
|
|
+ if (gameAppletDTO == null) {
|
|
|
+ return Tuples.of(400L, "小程序信息不存在");
|
|
|
+ }
|
|
|
+ //客服消息参数构造
|
|
|
+ log.error("客服消息发送参数, gameId : {}", gameId);
|
|
|
+ //获取接口token
|
|
|
+ String accessToken = wxApiServiceRpc.getAccessToken(gameAppletDTO.getAppId(), gameAppletDTO.getAppSecret());
|
|
|
URI uri = UriComponentsBuilder.fromHttpUrl("https://api.weixin.qq.com/cgi-bin/media/upload")
|
|
|
.queryParam("access_token", accessToken)
|
|
|
.queryParam("type", "image")
|
|
@@ -85,22 +97,18 @@ public class KfWxApiService {
|
|
|
map.add("media", formEntity);
|
|
|
//http请求头
|
|
|
HttpEntity<LinkedMultiValueMap<String, Object>> httpEntity = new HttpEntity<>(map, httpHeaders);
|
|
|
- Object result;
|
|
|
+ String result;
|
|
|
try {
|
|
|
- result = restTemplate.postForObject(uri, httpEntity, Object.class);
|
|
|
+ result = restTemplate.postForObject(uri, httpEntity, String.class);
|
|
|
} catch (Exception e) {
|
|
|
log.error("客服消息上传临时素材异常, e : {}", e.getMessage());
|
|
|
- throw new BaseException("上传临时素材异常");
|
|
|
+ return Tuples.of(400L, e.getMessage());
|
|
|
}
|
|
|
- if (result == null) {
|
|
|
-// log.error("企微上传临时素材异常, accessToken : {}, type : {}", accessToken, type);
|
|
|
- throw new BaseException("企微上传临时素材返回结果为空");
|
|
|
- }
|
|
|
- KfUploadTempMediaDTO res = JsonUtil.toObj(JsonUtil.toString(result), KfUploadTempMediaDTO.class);
|
|
|
- if (res.isSuccess()) {
|
|
|
- return res.getMedia_id();
|
|
|
- }
|
|
|
-// log.error("企微上传临时素材异常, accessToken : {}, type : {}, errmsg : {}", accessToken, type, res.getErrmsg());
|
|
|
- throw new BaseException("企微上传临时素材失败");
|
|
|
+ log.error("客服消息上传临时素材结果, result : {}", result);
|
|
|
+ Map<String, String> resultMap = JsonUtil.toMap(result, Map.class, String.class);
|
|
|
+ //错误码
|
|
|
+ long resultCode = Long.parseLong(resultMap.get("errcode"));
|
|
|
+ //返回
|
|
|
+ return resultCode == 0 ? Tuples.of(resultCode, resultMap.get("media_id")) : Tuples.of(resultCode, resultMap.get("errmsg"));
|
|
|
}
|
|
|
}
|