WeChat payment request Chinese garbled solution! ! ! ! ! !

The solution to the WeChat payment garbled problem:

first make sure the file format is UTF-8,


here comes the point, ---------------------------- -------------------------------------------------- -------------------------------------------------- -------------------------------------------------- -------------------------------------------------- ----------------------------------------------
If you use The RestTemplate in the spring framework must set the encoding character set to UTF-8, because its default is 8859-1 My God, I am about to crash
private static RestTemplate template = new RestTemplate();

static{
List<HttpMessageConverter<? >> converterList=template.getMessageConverters();
        HttpMessageConverter<?> converterTarget = null;
        for (HttpMessageConverter<?> item : converterList) {
            if (item.getClass() == StringHttpMessageConverter.class) {
                converterTarget = item;
                break;
            }
        }

        if (converterTarget != null) {
            converterList.remove(converterTarget);
        }
        HttpMessageConverter<?> converter = new StringHttpMessageConverter(Charset.forName("UTF-8"));
        converterList.add(converter);
}



请各位参见代码 , 屡试不爽!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326210834&siteId=291194637