Home  >  Article  >  Backend Development  >  php 与 java 汉语言 md5 不一样

php 与 java 汉语言 md5 不一样

WBOY
WBOYOriginal
2016-06-13 13:06:301027browse

php 与 java 中文 md5 不一样?
项目组要做个组件与别的公司进行通信,他们那边是php 开发,我们这边的是java,URL 地址是md5加密,我每次调取时,都发生错误..这个问题我困扰二三天,最后发现java 中中文的md5与php 中的中文 md5 不一样,英文完全没有问题...
解决方法一:php 与 java 两边自己 写md5算法..
解决方法二:通过java 调用php 页面,url 参数生成md5 格式,再与别的公司进行通信
          代码如下:
          java 端 :
public static String EncoderByMd5(String str,String url){

   str=java.net.URLEncoder.encode(str,"gb2312"); CommHttpInterface http = new CommHttpInterface();

return http.phpRequest(url+"?"+str);
}

public static String phpRequest(String url){  
    try{  
        HttpClient client = new HttpClient();  
        PostMethod post = new PostMethod(url);//使用POST方式提交数据  
        post.setRequestHeader("Content-Type","text/html;charset=gb2312");  
        client.executeMethod(post);  
        String response = new String(post.getResponseBodyAsString().getBytes("gb2312"));//打印结果页面  
        post.releaseConnection();  
        return response;  
    } catch(IOException e){  
        e.printStackTrace();  
        return null;  
    }  





   php 端:
header("Content-type: text/html; charset=gb2312");
$paramStr= urldecode($_GET["md5str"]);
echo strtolower(md5($paramStr));
?>


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn