Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

使用spring的RestTemplate配置,签名会失败 #42

Closed
mmzhi opened this issue Feb 8, 2021 · 3 comments
Closed

使用spring的RestTemplate配置,签名会失败 #42

mmzhi opened this issue Feb 8, 2021 · 3 comments

Comments

@mmzhi
Copy link

mmzhi commented Feb 8, 2021

具体原因是WechatPay2Credentials类中的buildMessage方法,EntityUtils.toString会将utf-8默认转换成GBK,再拼接签名,就会导致签名不一致

@xy-peng
Copy link
Contributor

xy-peng commented Feb 9, 2021

EntityUtils.toString(entity)会使用entity中设置的字符集的。直接给entity设置成utf-8字符集就好了,而且微信支付只支持utf-8。

@mmzhi
Copy link
Author

mmzhi commented Feb 10, 2021

RestTemplate,默认是不会在entity写入字符集信息的,现在目前做法,就是我把该项目原来整个复制下来,EntityUtils.toString强制使用UTF-8字符集转换

@xy-peng
Copy link
Contributor

xy-peng commented Feb 19, 2021

这个问题理论上应该是在RestTemplate侧解决的,你 @mmzhi 看看stackoverflow上的建议行不行?

RestTemplate restTemplate = new RestTemplate();
restTemplate.getMessageConverters()
        .add(0, new StringHttpMessageConverter(StandardCharsets.UTF_8));

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants