|
@@ -1,5 +1,6 @@
|
|
|
package com.fs.wx.order.service;
|
|
package com.fs.wx.order.service;
|
|
|
|
|
|
|
|
|
|
+import cn.binarywang.wx.miniapp.api.WxMaService;
|
|
|
import cn.hutool.core.exceptions.ExceptionUtil;
|
|
import cn.hutool.core.exceptions.ExceptionUtil;
|
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
|
import cn.hutool.http.*;
|
|
import cn.hutool.http.*;
|
|
@@ -7,10 +8,12 @@ import cn.hutool.json.JSONUtil;
|
|
|
import com.fasterxml.jackson.annotation.JsonInclude;
|
|
import com.fasterxml.jackson.annotation.JsonInclude;
|
|
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
|
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
|
|
+import com.fs.core.config.WxMaConfiguration;
|
|
|
import com.fs.wx.order.dto.UploadShippingInfoRequest;
|
|
import com.fs.wx.order.dto.UploadShippingInfoRequest;
|
|
|
import com.fs.wx.order.dto.WeChatApiConfig;
|
|
import com.fs.wx.order.dto.WeChatApiConfig;
|
|
|
import com.fs.wx.order.dto.WeChatApiResponse;
|
|
import com.fs.wx.order.dto.WeChatApiResponse;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
+import me.chanjar.weixin.common.error.WxErrorException;
|
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.web.util.UriComponentsBuilder;
|
|
import org.springframework.web.util.UriComponentsBuilder;
|
|
|
|
|
|
|
@@ -30,8 +33,8 @@ public class ShippingService {
|
|
|
* @param request 发货信息请求体
|
|
* @param request 发货信息请求体
|
|
|
* @return 微信 API 的响应
|
|
* @return 微信 API 的响应
|
|
|
*/
|
|
*/
|
|
|
- public WeChatApiResponse uploadShippingInfo(UploadShippingInfoRequest request) {
|
|
|
|
|
- WeChatAuthService weChatAuthService = WeChatAuthFactory.getWeChatAuthService(request.getAppid());
|
|
|
|
|
|
|
+ public WeChatApiResponse uploadShippingInfo(UploadShippingInfoRequest request) throws WxErrorException {
|
|
|
|
|
+ final WxMaService weChatAuthService = WxMaConfiguration.getMaService(request.getAppid());
|
|
|
String accessToken = weChatAuthService.getAccessToken(false);
|
|
String accessToken = weChatAuthService.getAccessToken(false);
|
|
|
if (accessToken == null) {
|
|
if (accessToken == null) {
|
|
|
log.error("获取微信 Access Token 失败");
|
|
log.error("获取微信 Access Token 失败");
|
|
@@ -81,7 +84,6 @@ public class ShippingService {
|
|
|
log.warn("微信接口返回业务错误: code={}, message={}", weChatApiResponse.getErrcode(), weChatApiResponse.getErrmsg());
|
|
log.warn("微信接口返回业务错误: code={}, message={}", weChatApiResponse.getErrcode(), weChatApiResponse.getErrmsg());
|
|
|
if(ObjectUtil.equal(weChatApiResponse.getErrcode(),40001)) {
|
|
if(ObjectUtil.equal(weChatApiResponse.getErrcode(),40001)) {
|
|
|
log.info("token缓存失效,清除token,等待下次执行...");
|
|
log.info("token缓存失效,清除token,等待下次执行...");
|
|
|
- weChatAuthService.clearToken();
|
|
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
return weChatApiResponse;
|
|
return weChatApiResponse;
|