Recently, a resource library system project was developed. The teacher said that he could build an open source forum to replace his own development of the social network module, just in the Open Source China saw a use of discuz UCenter function to Achieve Synchronous login open source project (https://code.google.com/p/discuz-ucenter-api-for-java/), can not help but joy, so spent a few hours according to the tutorial operation again, it was a very easy success. Close up this article to commemorate it ..
Uenter is a bridge for the direct transfer of information between various products under Comsenz. Through the UCenter webmaster, Comsenz products can be seamlessly integrated to achieve one-stop registration, login, and exit for users. UCenter allows Comsenz to closely connect all its products, achieve unified user registration and login, and truly enable the Community to run. UCenter has a well-established interface, which can be attached to a third-party network application on any other platform after simple modification. As a bridge between traditional information systems, UCenter provides a unified messaging and friend mechanism. End users can easily access various applications without repeated logon, registration, and logout. The unified TAG Mechanism closely connects various applications in the Community. Users can freely move through the community to quickly find the desired applications and obtain the best user experience.
First, install apache and ph
My versions are php-5.4.23-Win32-VC9-x86 and httpd-2.2.25-win32-x86-openssl-0.9.8y
Basically, I have not encountered any special problems, except that the php and apache versions do not support each other, and the rest are basically smooth.
If php contains 2_4, You need to download a lower version of php. Otherwise, the apache server will not be able to parse the php file normally.
Step 2: Install discuz. the installation page is discuz_x3.20. SC _utf8.zip. When you select the all-new installation option, UCenter will be installed by the way. If not, you need to download and install the UCenter1.5 + version.
Step 3: configure the UCenter server (that is, the program installed by UCenter)
:
Step 3: configure our own program, that is, the client.
1. Copy the jar package https://code.google.com/p/discuz-ucenter-api-for-java/downloads/list in the open source project
2. configure a servlet for interfacing with UCenter
Copy codeThe Code is as follows:
<Servlet>
<Servlet-name> connect_discuz </servlet-name>
<Servlet-class> com. fivestars. interfaces. bbs. api. UC </servlet-class>
<Load-on-startup> 2 </load-on-startup>
</Servlet>
<Servlet-mapping>
<Servlet-name> connect_discuz </servlet-name>
<Url-pattern>/api/uc. php </url-pattern>
</Servlet-mapping>
3. Copy the configuration file (config. properties) to the src directory.
Copy codeThe Code is as follows:
#
#===================================================== ==========
# * Discuz! Ucenter API for JAVA
#===================================================== ==========
# UC comunication settings
#
#
# If the uc server url is in a completely new installation mode, the ucenter can be installed with discuz. The path is
UC_API = http: // {discuz root directory}/uc_server
# Uc ip address
UC_IP = 127.0.0.1
# Key
UC_KEY = yunstudio
# Appid
UC_APPID = 2
# Connect mode: default value is ""
UC_CONNECT =
4. Copy the demo (Jsp_demo.jsp) in the open-source project to the application root directory. The author's jsp file encoding and file header are a little problematic, So I modified it a little.
Copy codeThe Code is as follows:
<%
/**
* ===================================================== ==========
* Discuz! Ucenter API for JAVA
* ===================================================== ==========
* JSP call example
*
* More information: http://code.google.com/p/discuz-ucenter-api-for-java/
* By Liang Ping (no_ten@163.com)
* Creation Time:
*/
%>
<% @ Page language = "java" import = "java. util. *" pageEncoding = "UTF-8" %>
<% @ Page import = "com. fivestars. interfaces. bbs. util. XMLHelper" %>
<% @ Page import = "com. fivestars. interfaces. bbs. client. Client" %>
<%
Client uc = new Client ();
String result = uc. uc_user_login ("admin", "yun ");
Export List <String> rs = XMLHelper. uc_unserialize (result );
If (rs. size ()> 0 ){
Int $ uid = Integer. parseInt (rs. get (0 ));
String $ username = rs. get (1 );
String $ password = rs. get (2 );
String $ email = rs. get (3 );
If ($ uid> 0 ){
Response. addHeader ("P3P", "CP = \" CURa ADMa DEVa PSAo PSDo our bus uni pur int dem sta pre com nav otc noi dsp cor \"");
Out. println ("Logon successful ");
Out. println ($ username );
Out. println ($ password );
Out. println ($ email );
String $ ucsynlogin = uc. uc_user_synlogin ($ uid );
Out. println ("Logon successful" + $ ucsynlogin );
// Local login code
// TODO .......
Cookie auth = new Cookie ("auth", uc. uc_authcode ($ password + "\ t" + $ uid, "ENCODE "));
Auth. setMaxAge (31536000 );
// Auth. setDomain ("localhost ");
Response. addCookie (auth );
Cookie user = new Cookie ("uchome_loginuser", $ username );
Response. addCookie (user );
} Else if ($ uid =-1 ){
Out. println ("the user does not exist or is deleted ");
} Else if ($ uid =-2 ){
Out. println ("Incorrect password ");
} Else {
Out. println ("undefined ");
}
} Else {
Out. println ("Login failed ");
System. out. println (result );
}
%>
If the example can run, you can directly view the code on the official website after registering and logging out of the website. This is very simple.