The Chinese question of Discuz_ucenter_api_for_java

Source: Internet
Author: User
Tags base64 getmessage urlencode

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.