您的位置:首页 > 其它

支付宝即时到账,传参乱码.

2016-06-17 15:37 405 查看
被郁闷了,支付宝即时转账,只能通过form 方式传参。然后,在本地的时候中文是ok 的但是一到传送到支付宝的时候就一直验签报错。

我问过支付宝的技术客服,确定 md5.sign()支持 汉字。 那问题就局限在传参的时候了。

然而不管我怎么设置,都没有办法解决乱码:

如下:

    response.setHeader("Cache-Control", "no-cache");

               response.setCharacterEncoding("utf-8");

               response.setContentType("text/html;charset=utf-8");

最后通过这篇文章(http://blog.csdn.net/hengyunabc/article/details/17056237)解决了问题,主要内容如下:

tomcat里一劳永逸解决乱码问题

要想在tomcat中一劳永逸解决乱码问题,可以这样做:

1.设置tomcat,conf/server.xml文件中,useBodyEncodingForURI="true":

[html]
view plain
copy

<Connector port="8080" protocol="HTTP/1.1"   
           connectionTimeout="20000"   
           redirectPort="8443" useBodyEncodingForURI="true"/>  

2.增加一个filter:

[java]
view plain
copy

public class CodeFilter implements Filter {  
    @Override  
    public void init(FilterConfig filterConfig) throws ServletException {     
    }  
    @Override  
    public void doFilter(ServletRequest request, ServletResponse response,  
            FilterChain chain) throws IOException, ServletException {  
        request.setCharacterEncoding("utf-8");  
        response.setCharacterEncoding("utf-8");  
        chain.doFilter(request, response);  
    }  
    @Override  
    public void destroy() {   
    }  
}  

3.在web.xml中配置filter:

[html]
view plain
copy

<filter>  
    <filter-name>CodeFilter</filter-name>  
    <filter-class>com.leg.filter.CodeFilter</filter-class>  
</filter>  
  
<filter-mapping>  
    <filter-name>CodeFilter</filter-name>  
    <url-pattern>*</url-pattern>  
</filter-mapping> 

附上 支付宝接受异步返回的代码: http://xiongjiajia.iteye.com/blog/1327567   非常详尽。。。踩着巨人的肩膀啊。。。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息