|
@@ -14,6 +14,7 @@ import org.springframework.stereotype.Service;
|
|
|
import org.springframework.util.LinkedMultiValueMap;
|
|
import org.springframework.util.LinkedMultiValueMap;
|
|
|
import org.springframework.util.MultiValueMap;
|
|
import org.springframework.util.MultiValueMap;
|
|
|
|
|
|
|
|
|
|
+import java.nio.charset.StandardCharsets;
|
|
|
import java.time.LocalDateTime;
|
|
import java.time.LocalDateTime;
|
|
|
import java.util.HashMap;
|
|
import java.util.HashMap;
|
|
|
import java.util.List;
|
|
import java.util.List;
|
|
@@ -21,7 +22,6 @@ import java.util.Map;
|
|
|
import java.util.Objects;
|
|
import java.util.Objects;
|
|
|
|
|
|
|
|
@SuppressWarnings("SpellCheckingInspection")
|
|
@SuppressWarnings("SpellCheckingInspection")
|
|
|
-@Service
|
|
|
|
|
public class WeChatService {
|
|
public class WeChatService {
|
|
|
@Getter
|
|
@Getter
|
|
|
@AllArgsConstructor
|
|
@AllArgsConstructor
|
|
@@ -75,12 +75,28 @@ public class WeChatService {
|
|
|
body,
|
|
body,
|
|
|
null
|
|
null
|
|
|
);
|
|
);
|
|
|
|
|
+
|
|
|
|
|
+ if(Objects.requireNonNull(res.getHeaders().get(HttpHeaders.CONTENT_TYPE)).contains("application/json")){
|
|
|
|
|
+ if (res.getBody() != null) {
|
|
|
|
|
+ String json = new String(res.getBody(), StandardCharsets.UTF_8);
|
|
|
|
|
+ JSONObject jsonObject = JSONObject.parseObject(json);
|
|
|
|
|
+ String errcode = jsonObject.getString("errcode");
|
|
|
|
|
+ if (errcode != null&&errcode.equals("40001")) {
|
|
|
|
|
+ refreshAccessToken();
|
|
|
|
|
+ res = HttpUtil.requestPostWithJson(
|
|
|
|
|
+ WX_ACODE_PATH + getAccessToken(),
|
|
|
|
|
+ body,
|
|
|
|
|
+ null
|
|
|
|
|
+ );
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
HttpHeaders headers = new HttpHeaders();
|
|
HttpHeaders headers = new HttpHeaders();
|
|
|
copyHeader(headers, res.getHeaders(), HttpHeaders.CONTENT_TYPE);
|
|
copyHeader(headers, res.getHeaders(), HttpHeaders.CONTENT_TYPE);
|
|
|
copyHeader(headers, res.getHeaders(), HttpHeaders.CONTENT_LENGTH);
|
|
copyHeader(headers, res.getHeaders(), HttpHeaders.CONTENT_LENGTH);
|
|
|
|
|
|
|
|
headers.add(HttpHeaders.CACHE_CONTROL,"public, max-age=3600");
|
|
headers.add(HttpHeaders.CACHE_CONTROL,"public, max-age=3600");
|
|
|
- headers.add(HttpHeaders.ACCESS_CONTROL_ALLOW_ORIGIN,"*");
|
|
|
|
|
return new ResponseEntity<>(res.getBody(), headers, res.getStatusCode());
|
|
return new ResponseEntity<>(res.getBody(), headers, res.getStatusCode());
|
|
|
}
|
|
}
|
|
|
|
|
|