Skip to content

Commit

Permalink
fix: 解决微信小程序登录返回乱码问题
Browse files Browse the repository at this point in the history
  • Loading branch information
lichong-a committed Oct 13, 2024
1 parent 4316e60 commit 257fa77
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.convert.converter.Converter;
import org.springframework.http.converter.StringHttpMessageConverter;
import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder;
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;

import java.nio.charset.StandardCharsets;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.time.LocalDateTime;
Expand All @@ -31,6 +33,13 @@
@Configuration
public class JacksonConfig {

@Bean
public StringHttpMessageConverter stringHttpMessageConverter() {
StringHttpMessageConverter converter = new StringHttpMessageConverter();
converter.setDefaultCharset(StandardCharsets.UTF_8);
return converter;
}

@Bean
public MappingJackson2HttpMessageConverter mappingJackson2HttpMessageConverter() {
Jackson2ObjectMapperBuilder builder =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ public void successLoginHandler(@NonNull HttpServletRequest request,
User currentUser = (User) authentication.getPrincipal();
String accessToken = this.generateToken(currentUser);
response.addHeader(SecurityConstant.TOKEN_HEADER_KEY, accessToken);
response.setContentType(MediaType.APPLICATION_JSON_VALUE);
response.setContentType(MediaType.APPLICATION_JSON_UTF8_VALUE);
Cookie cookie = new Cookie(SecurityConstant.TOKEN_COOKIE_KEY, accessToken);
cookie.setHttpOnly(true);
response.addCookie(cookie);
Expand Down

0 comments on commit 257fa77

Please sign in to comment.