悠鸣海

微信公众号开发自动回复消息乱码(都是???)


问题环境:
1.Spring mvc
2.微信平台-JAVA


    在编写自动回复消息的时候出现乱码,最后发现问题是由于spring mvc的@ResponseBody注解返回字符串时默认返回的是“ISO-8859-1”而不是utf-8。


Spring mvc相关字符编码均已添加,例如:

    <!--web.xml配置文件 -->
              <filter>
                  <description>字符集过滤器</description>
                  <filter-name>encodingFilter</filter-name>
                  <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
                  <init-param>
                      <description>字符集编码</description>
                      <param-name>encoding</param-name>
                      <param-value>UTF-8</param-value>
                  </init-param>
                  <init-param>
                      <param-name>forceEncoding</param-name>
                      <param-value>true</param-value>
                  </init-param>
              </filter>
              <filter-mapping>
                  <filter-name>encodingFilter</filter-name>
                  <url-pattern>/*</url-pattern>
              </filter-mapping>

 <!-- Spring mvc 配置文件 -->   
              <bean id="mappingJacksonHttpMessageConverter"
                  class="org.springframework.http.converter.json.MappingJacksonHttpMessageConverter">
                  <property name="supportedMediaTypes">
                      <list>
                          <value>text/html;charset=UTF-8</value>
                      </list>
                  </property>
              </bean>
          
              <bean id="mappingStringHttpMessageConverter"
                  class="org.springframework.http.converter.StringHttpMessageConverter">
                  <property name="supportedMediaTypes">
                      <list>
                          <value>text/html;charset=UTF-8</value>
                      </list>
                  </property>
              </bean>

问题解决办法: @RequestMapping(value = "/weixin/validation" , method = RequestMethod.POST , produces = "text/html;charset=UTF-8")

引用: 微信开发自动回复消息乱码问题
Copyright©2014 悠鸣海版权所有   桂ICP备13003698号
联系邮箱: office@yominhi.com    Powered by: Kenneth