I stepped on the pit, I hope you don't fall in.
Cloud service needs and ucenter do docking, a PHP, a Java, fortunately with the Discuz_ucenter_api_for_java, help me solve most of the problem, why is the majority of problems, because he did not solve the Chinese login, Chinese synchronous login problem, I do not understand the code this piece, engaged in an afternoon head dizzy, fortunately, the company's phper fully cooperate with me. Finally solved the problem, the idea is: PHP and Java string one pair. Just say the solution.
1: Replace the base64 encoding,
The author does not know where to find a Base64 code implementation, I deleted the use of the Commons-codec library inside the base64 implementation. Modify the Phpfunctions class
protectedstring Base64_decode (String input) {Try { return NewString (Base64.decode (input), "iso8859-1"); } Catch(Exception e) {returnE.getmessage (); } } protectedstring Base64_encode (String input) {Try { return NewString (Base64.encode (Input.getbytes ("Iso-8859-1"))); //return new String (Base64.encode (Input.getbytes ("UTF-8")), "iso8859-1");}Catch(Exception e) {returnE.getmessage (); } }
Why is iso-8859-1, this I analysis is not tomcat problem, is ucenter use iso-8859-1, I see Ucenter return value, is an XML string, encoding is iso-8859-1.
2: Implement the Chinese login problem. Two places modified:
The UrlEncode method of 1:phpfunctions class
protected string UrlEncode (String value) { try { return urlencoder.encode (value, " UTF-8 "); Catch (unsupportedencodingexception e) { e.printstacktrace (); } return NULL ; }
The Uc_fopen method of 2:client
New BufferedReader (new inputstreamreader (INS, "UTF-8"));
3: Synchronous Login for Chinese:
Modifies the Uc_authcode method of the Clent.
if($operation. Equals ("DECODE") ) {String $result= $result 1.substring (0, $result 1.length ()); String Temp=substr ($result. toString (), 26); Try{Temp=NewString (Temp.getbytes ("iso8859-1"), "UTF-8"); } Catch(unsupportedencodingexception e) {e.printstacktrace (); } if((Integer.parseint (substr ($result. toString (), 0, 10)) = = 0 | | Long.parselong (substr ($result. toString (), 0,))-time () > 0) &&substr ($result. toString (),Equals (SUBSTR (MD5 (temp+ $keyb), 0, 16))) { returntemp; } Else { return""; } } Else { return$KEYC +base64_encode ($result 1.toString ()). ReplaceAll ("=", "" "); }
The Chinese question of Discuz_ucenter_api_for_java