Showing
1 changed file
with
5 additions
and
1 deletions
| ... | @@ -15,6 +15,7 @@ import org.springframework.http.ResponseEntity; | ... | @@ -15,6 +15,7 @@ import org.springframework.http.ResponseEntity; |
| 15 | import org.springframework.stereotype.Service; | 15 | import org.springframework.stereotype.Service; |
| 16 | import org.springframework.web.client.RestTemplate; | 16 | import org.springframework.web.client.RestTemplate; |
| 17 | 17 | ||
| 18 | +import java.util.Collections; | ||
| 18 | import java.util.HashMap; | 19 | import java.util.HashMap; |
| 19 | import java.util.Map; | 20 | import java.util.Map; |
| 20 | 21 | ||
| ... | @@ -79,7 +80,10 @@ public class WxMiniProgramHttpClient { | ... | @@ -79,7 +80,10 @@ public class WxMiniProgramHttpClient { |
| 79 | try { | 80 | try { |
| 80 | final var url = "https://api.weixin.qq.com/sns/jscode2session" + | 81 | final var url = "https://api.weixin.qq.com/sns/jscode2session" + |
| 81 | "?appid=" + appId + "&secret=" + appSecret + "&js_code=" + code + "&grant_type=authorization_code"; | 82 | "?appid=" + appId + "&secret=" + appSecret + "&js_code=" + code + "&grant_type=authorization_code"; |
| 82 | - final var response = restTemplate.getForEntity(url, WxUserOpenIdDto.class); | 83 | + HttpHeaders headers = new HttpHeaders(); |
| 84 | + headers.setAccept(Collections.singletonList(MediaType.APPLICATION_JSON)); | ||
| 85 | + HttpEntity<Void> requestEntity = new HttpEntity<>(headers); | ||
| 86 | + ResponseEntity<WxUserOpenIdDto> response = restTemplate.exchange(url, HttpMethod.GET, requestEntity, WxUserOpenIdDto.class); | ||
| 83 | return response.getBody(); | 87 | return response.getBody(); |
| 84 | } catch (Exception e) { | 88 | } catch (Exception e) { |
| 85 | log.error("Error fetching user openid", e); | 89 | log.error("Error fetching user openid", e); | ... | ... |
-
Please register or login to post a comment