Is php different from java's Chinese md5? The project team wants to build a component to communicate with other companies. they are developed in php, java on our side, and md5 encryption on the URL address. every time I retrieve the component, an error occurs .. I am troubled by this problem for two or three days. Finally, I found that md5 in Chinese in java is different from md5 in php. there is no problem in English at all... solution 1: Do php and java write their own md5 algorithms? is php different from java's Chinese md5?
The project team wants to build a component to communicate with other companies. they are developed in php, java on our side, and md5 encryption on the URL address. every time I retrieve the component, an error occurs .. I am troubled by this problem for two or three days. Finally, I found that md5 in Chinese in java is different from md5 in php. there is no problem in English at all...
Solution 1: Write the md5 algorithm on both sides of php and java ..
Solution 2: Call the php page through java. the url parameter generates the md5 format and communicates with other companies.
The code is as follows:
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); // Use POST to submit data
Post. setRequestHeader ("Content-Type", "text/html; charset = gb2312 ");
Client.exe cuteMethod (post );
String response = new String (post. getResponseBodyAsString (). getBytes ("gb2312"); // print the result page
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 ));
?>