Recently, I did a project of resource database system. The teacher said that we can build an open source forum instead of developing social modules. I just saw an open source project in open source China that uses the UCenter function of discuz to realize synchronous login( https://code.google.com/p/discuz-ucenter-api-for-java/ )I can’t help but be overjoyed, so I spent a few hours following the tutorial and did it again Very easy to succeed, close up this article to do a memorial..
Uenter is a bridge for the direct transmission of information between Comsenz’s products. Through the UCenter webmaster, Comsenz series products can be integrated seamlessly to realize one-stop registration, login and exit of users. UCenter can make all Comsenz products more closely linked, realize the unified registration and login of users, and make the community really run. UCenter has a well-established interface, which can hook up the third-party network application program of any other platform after simple modification. As a traditional bridge of information, UCenter has a unified mechanism of SMS and friends. End users can easily pass through it in various applications without repeated login, registration and exit. The unified tag mechanism connects all applications in the community closely, so that users can travel freely in the community, quickly find the applications they need and get the best use experience.
First, the first step is to 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 didn’t encounter any special problems, except that the PHP and Apache versions did not match, which delayed some time, the rest were basically smooth.
If PHP has 2_ 4, you need to download a lower version of PHP, otherwise the Apache server will not be able to parse PHP files normally.
The second step is to install discuz. The version I installed is discuz_ X3.1_ SC_ UTF8.zip。 When installing, check new installation to install UCenter by the way. If you don’t install it, you need to download and install it yourself. The version is UCenter 1.5+
Step 3: start to configure the UCenter server (the program installed by UCenter)
As shown in the figure:
The third step is to configure our own program, that is, the client.
1. Copy the jar package in the open source project https://code.google.com/p/discuz-ucenter-api-for-java/downloads/list
2. Configure a servlet for docking with UCenter
<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. Put the configuration file( config.properties )Copy to the SRC directory
# ================================================
# * Discuz! Ucenter API for JAVA
# ================================================
# UC comunication settings
#
#
#If the UC server URL is a new installation mode, UCenter can be installed with discuz. The path is
UC_ API = http: / / {discuz root} / 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. Put demo (JSP) in open source project_ demo.jsp )Copy to the root of the application. The original author’s JSP file encoding and file header have a little problem, so I modified it a little bit.
/**
* ================================================
* Discuz! Ucenter API for JAVA
* ================================================
* JSP call example
*
* more information: http://code.google.com/p/discuz-ucenter-api-for-java/
* Author: Liang Ping (No_ [email protected] )
* created on: February 20, 2009
*/
%>
<%@ 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”);
LinkedList<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 (“login succeeded”);
out.println($username);
out.println($password);
out.println($email);
String $ucsynlogin = uc.uc_user_synlogin($uid);
out.println (“login succeeded” + $ucsylign);
/ / 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 has been deleted”);
} else if($uid == -2) {
out.println (“wrong password”);
} else {
out.println (the “undefined”);
}
}else{
out.println(“Login failed”);
System.out.println(result);
}
%>
If the example can run, then the registration of what can be directly read on the official website code to understand, very simple.