This article is outdated. The latest version is:
Directory:
- Opening
- Communication principle: communication principle between ucenter APIs and sub-stations and single-point login Principle
- Encryption and decryption: authcode explanation & notes during authcode function Translation
- Website Construction: kangsheng's website & Asp.net website construction
Preface
There are multiple sub-sites under student online, including a discuz Forum
Of course, we must make full use of the powerful ucenter to achieve multi-point login.
Cross-origin communication between ucenter and other websites must use WebService.
PHP is officially encapsulated, so it is easy to handle it, but. Net...
No core communication manual can be found online, unless the php development manual is deducted.
After Google:
Ucenter interface development manual: This is an officially encapsulated version. In fact, this document cannot be called the interface development manual. It describes all encapsulated PHP functions and does not mention the core.
A project file: I was very excited when I saw this, but I was not able to use it after I adjusted it! I didn't know why at first, but I knew it only after I understood the principle. It was actually an empty shell.
A dll file: This dll is very powerful. Unfortunately, there are no routines, no manuals, no comments, and bugs...
But relatively speaking, the last DLL is the closest, so I decided to decompile it and started to study it.
Finally, we have the dozer edit version ~ Communication successful!
Source: dozer.cnblogs.com Author: Dozer
Ucenter communication principle
There are many principles on the internet, and I just know a little bit about it. Here we will take synchronous login as an example to explain the usage of this class library.
The above is the step for Synchronous login. If you have already configured it, you only need the three lines of code
namespace WebApplication1{ public partial class Default : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { var uc = new UCClient(); var user = uc.UC_User_Login("user", "password").User; Response.Write(uc.UC_User_Synlogin(user.Uid)); } }}
In short, there must be two parts in your website Program
One is the ucapi part, which must be called by ucenter
The other part is the uclient, which is used to call the ucenter
In this way, two-way communication can be implemented at the end.
Source: dozer.cnblogs.com Author: Dozer
Ucenter configuration process
By convention, log on to the ucenter background and add an application
In other places, like the PHP website, there is only one place, that is, the "application interface file name ".
Enter UC. ashx
This is related to the principles of such libraries.
Submit... Unfortunately, the communication is not successful because my website has not been configured yet ~
Submit the file and edit it again. a php configuration is displayed.
define('UC_CONNECT', 'mysql');define('UC_DBHOST', localhost');define('UC_DBUSER', 'root');define('UC_DBPW', 'mysql');define('UC_DBNAME', 'uc_discuz');define('UC_DBCHARSET', 'utf8');define('UC_DBTABLEPRE', '`uc_discuz`.uc_');define('UC_DBCONNECT', '0');define('UC_KEY', 'qwertyui');define('UC_API', 'http://localhost/ucenter');define('UC_CHARSET', 'utf-8');define('UC_IP', '127.0.0.1');define('UC_APPID', '19');define('UC_PPP', '20');
Keep it first. It will be used later ~
Source: dozer.cnblogs.com Author: Dozer
Webapplication configuration process
The first step is the Web. config file.
Create a website application and reference this class library
The above configuration information is used by PHP. We will convert it to the Web. config file.
<appSettings><add key="UC_CONNECT" value="mysql"/><add key="UC_DBHOST" value="localhost"/><add key="UC_DBUSER" value="root"/><add key="UC_DBPW" value="mysql"/><add key="UC_DBNAME" value="uc_discuz"/><add key="UC_DBCHARSET" value="utf8"/><add key="UC_APPIDUC_DBTABLEPRE" value="`uc_discuz`.uc_"/><add key="UC_DBCONNECT" value="0"/><add key="UC_KEY" value="qwertyui"/><add key="UC_API" value="http://localhost/ucenter"/><add key="UC_CHARSET" value="utf-8"/><add key="UC_IP" value="127.0.0.1"/><add key="UC_APPID" value="19"/><add key="UC_PPP" value="20"/></appSettings>
Source: dozer.cnblogs.com Author: Dozer
The second step is to create a ucapi for the ucenter to call (after this step is complete, the ucenter will display normal communication)
1. Create a file called API
2. Create a new file UC. ashx in it (do not create. aspx)
3. Open the UC. ashx file, which is inherited from ihttphandler. Let's modify it to inherit from fs. API. ucenter. ucapi. ucapibase.
4. Implement the function of this abstract class (use vs code to automatically complete the function)
5. You can write some logic code here.
For example, when someone logs on to another site synchronously, it will notify your site
Then you will call the synlogin function. At this time, you need to write some code in this function.
For example, writing cookies
Q: Why does the ucenter not directly write cookies, but does the sub-site read cookies?
A: ucenter implements cross-origin login. Therefore, the cookies of each sub-site are separated and must be implemented by yourself!
Now, after completing this step, open ucenter and you will find that the communication is successful!
The ucenter test communication is successful only by calling a test function. As long as the preceding configuration is correct, the communication is successful! However, it cannot implement any functions, and the above functions need to be improved ~
Source: dozer.cnblogs.com Author: Dozer
Step 3: Call the ucenter interface on the website
This is super simple. In fact, the code of "ucenter communication principle"
Why respon. Write?
This is related to the ucenter synchronous login principle. It sends a message to the ucenter and tells it that it will not notify other sub-sites, but return a piece of JS, which needs to be called by your website, then notify the sub-sites
OK ~ All configurations are complete ~
Source: dozer.cnblogs.com Author: Dozer
What have I done to the original DLL?
1. There are several serious problems with the original DLL encoding, resulting in an Encoding Error and the form cannot be submitted.
2. The original DLL was estimated to have been written a long time ago. During serialization and deserialization, the rule is different from the current ucenter rule. I modified it according to the current rule.
3. Fix other minor bugs
Source: dozer.cnblogs.com Author: Dozer
Class Library download & sample code
The original author of the Code cannot find it and follows the Open Source spirit.
In addition, the current code is not guaranteed to be all correct. I just tested several functions.
Class Library source code: Download
Sample Code: Download
Source: dozer.cnblogs.com Author: Dozer