php 與 java 漢語言 md5 不一樣

來源:互聯網
上載者:User
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));
?>


  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.