Synchronous login of discuz, login of discuz
First of all thanks to dozer senior UCenter translated into C # blog address -----------> http://www.dozer.cc/second thanks to the group of friends happy ending classmates enthusiastic guidance, although the encounter but let me feel the warmth of the world
Discuz ConstructionSynchronous Login
Discuz is a general community forum software system developed by kangsheng.
Kangsheng has other products. In order to allow one account to log on to multiple websites to be unobstructed, The UCenter
This article introduces synchronous login between Asp. Net Website and Discuz.
It is recommended to look at the dozer write tutorial http://www.dozer.cc/2011/01/ucenter-api-in-depth-1st.html
Most of my operations are for him.
First, obtain UCenter For. Nethttps: // github.com/dozer47528/UCenter-API-For-DotNet. What is UCenter?
Simply put, it is also a website. You can take charge of the official introductions of users on N websites. I will briefly describe the synchronous login process.
Class Library Overview
The class library is divided into the following parts:
If Discuz is successfully installed, you can view your Discuz in the UCenter application management. Now, add a website and ask the UCenter to manage this website to create an empty Asp. net Web application, remember to reference the class library right-click the website project --> properties ---> Web found that I found the project URL, remember that this URL will be used here. Of course, you cannot perform synchronous login. Now, your new website and UCenter are still in the old and dead status. The website is associated with the UCenter.
After submission, the configuration information is generated at the bottom.
Define ('uc _ CONNECT ', 'mysql ');
Define ('uc _ dbhost', 'localhost ');
Define ('uc _ dbuser', 'root ');
Define ('uc _ DBPW ', '20140901 ');
Define ('uc _ dbname', 'ultrax ');
Define ('uc _ dbcharset', 'gbk ');
Define ('uc _ dbtablepre', ''ultrax '. pre_ucenter _');
Define ('uc _ DBCONNECT ', '0 ');
Define ('uc _ key', 'fd144298af7e4797a66acc0c18c97ea3 ');
Define ('uc _ api', 'HTTP: // localhost: 8080/uc_server ');
Define ('uc _ charset', 'gbk ');
Define ('uc _ ip ','');
Define ('uc _ APPID ', '2 ');
Define ('uc _ PPP ', '20 ');
If you return to the Application Center, you will find that the communication you just added has failed. This is normal because your website has not configured the PHP configuration information to fill in the Web. in config, the following template is filled in one by one. It may not be available below. the items marked in red above and below
1 <configuration> 2 <system. web> 3 <compilation debug = "true" targetFramework = "4.0"/> 4 <pages controlRenderingCompatibilityVersion = "3.5" clientIDMode = "AutoID"/> 5 </system. web> 6 <appSettings> 7 <! -- Client Version --> 8 <add key = "UC_CLIENT_VERSION" value = "1.5.2"/> 9 <! -- Release date --> 10 <add key = "UC_CLIENT_RELEASE" value = "20101001"/> 11 <! -- API switch (value Type: True False default value: True) --> 12 <! -- Whether users can be deleted --> 13 <add key = "API_DELETEUSER" value = "True"/> 14 <! -- Whether to rename a user --> 15 <add key = "API_RENAMEUSER" value = "True"/> 16 <! -- Whether to obtain the tag --> 17 <add key = "API_GETTAG" value = "True"/> 18 <! -- Allow synchronous logon --> 19 <add key = "API_SYNLOGIN" value = "True"/> 20 <! -- Whether to allow synchronous logout --> 21 <add key = "API_SYNLOGOUT" value = "True"/> 22 <! -- Allow password change --> 23 <add key = "API_UPDATEPW" value = "True"/> 24 <! -- Whether to allow keyword update --> 25 <add key = "API_UPDATEBADWORDS" value = "True"/> 26 <! -- Whether domain name resolution cache can be updated --> 27 <add key = "API_UPDATEHOSTS" value = "True"/> 28 <! -- Allow update of Application List --> 29 <add key = "API_UPDATEAPPS" value = "True"/> 30 <! -- Whether to allow update of Client Cache --> 31 <add key = "API_UPDATECLIENT" value = "True"/> 32 <! -- Allow updating user credits --> 33 <add key = "API_UPDATECREDIT" value = "True"/> 34 <! -- Whether to enable point settings for UCenter --> 35 <add key = "API_GETCREDITSETTINGS" value = "True"/> 36 <! -- Whether to allow the user to obtain a certain point --> 37 <add key = "API_GETCREDIT" value = "True"/> 38 <! -- Allow update of application credit settings --> 39 <add key = "API_UPDATECREDITSETTINGS" value = "True"/> 40 <! -- The API switch ends --> 41 <! -- Return Value Setting --> 42 <! -- Return success (default: 1) --> 43 <add key = "API_RETURN_SUCCEED" value = "1"/> 44 <! -- Return failure (default:-1) --> 45 <add key = "API_RETURN_FAILED" value = "-1"/> 46 <! -- Return disabled (default:-2) --> 47 <add key = "API_RETURN_FORBIDDEN" value = "-2"/> 48 <! -- End of Return Value Setting --> 49 50 51 <! -- [Required] Communication key --> 52 <add key = "UC_KEY" value = "FD144298AF7E4797A66ACC0C18C97EA3"/> 53 <! -- [Required] UCenter address --> 54 <add key = "UC_API" value =" http://localhost:8080/uc_server "/> 55 <! -- [Required] default encoding --> 56 <add key = "UC_CHARSET" value = "gbk"/> 57 <! -- [Optional] UCenter IP --> 58 <add key = "UC_IP" value = ""/> 59 <! -- [Required] Application ID --> 60 <add key = "UC_APPID" value = "2"/> 61 </appSettings> 62 </configuration>
In this way, my website will be able to communicate with the UCenter, but how can I communicate?
Here I will create an ashx demonstration Talk is cheap. Show you the code
1 public void ProcessRequest (HttpContext context) 2 {3 context. response. contentType = "text/html"; 4 IUcClient client = new UcClient (); 5 var user = client. userLogin ("us1", "111111"); // log on to 6 var js = client. userSynlogin (user. uid); // return a js Code, which is the key to synchronous login 7 if (user. result = LoginResult. success) 8 {9 context. response. write (js); 10 context. response. write (user. userName); 11} 12}
This is a piece of code that notifies the UCenter, us1 users, and other applications managed by the UCenter to log on.
The above can be considered as my website to go to The UCenter, but how to find me in the UCenter, the so-called communication must be your visit
Add an API folder and add a uc. ashx file below (not familiar, right? This is just set in the UCenter Application Management Center)
Let uc inherit UcApiBase and implement its abstract Method
Delete the ProcessRequest method of uc. ashx because UcApiBase has
To start your website
- Make sure that your iis is enabled
- Wampserver runs properly and needs to be Green (MySQL is started. I split it into two articles, so this is a little abrupt)
- Make sure your Discuz can access
- Make sure that the configuration and Web. Config in UCenter are correct.
- Make sure your new site runs on the server
After the application is started, you will find that the original communication failure in the UCenter becomes a successful access to TestHandler. if the user name is displayed on the ashx success page, the user name jumps to Discuz.
This figure can explain the ProcessRequest of TestHandler. ashx.
The returned js will be executed in the browser.
It will request the UCenterApi under the discuz website. It will tell Discuz who has logged on to this section. js also explains why uc. ashx must be placed in an api folder. In this way, synchronous login is generally finished. The following describes how to synchronize discuz to log on to your website and find apps on uc_client \ data \ cache under your discuz website. php
1 <?php 2 $_CACHE['apps'] = array ( 3 1 => 4 array ( 5 'appid' => '1', 6 'type' => 'DISCUZX', 7 'name' => 'Discuz! Board', 8 'url' => 'http://localhost:8080', 9 'ip' => '',10 'viewprourl' => '',11 'apifilename' => 'uc.php',12 'charset' => '',13 'dbcharset' => '',14 'synlogin' => '1',15 'recvnote' => '1',16 'extra' => false,17 'tagtemplates' => '',18 'allowips' => '',19 ),20 );21 ?>
Make a copy of it. Make sure you modify it as appropriate.
1 <?php 2 $_CACHE['apps'] = array ( 3 1 => 4 array ( 5 'appid' => '1', 6 'type' => 'DISCUZX', 7 'name' => 'Discuz! Board', 8 'url' => 'http://localhost:8080', 9 'ip' => '',10 'viewprourl' => '',11 'apifilename' => 'uc.php',12 'charset' => '',13 'dbcharset' => '',14 'synlogin' => '1',15 'recvnote' => '1',16 'extra' => false,17 'tagtemplates' => '',18 'allowips' => '',19 ),20 2 =>21 array (22 'appid' => '2',23 'type' => 'OTHER',24 'name' => 'MyWebSite',25 'url' => 'http://localhost:7067',26 'ip' => '',27 'viewprourl' => '',28 'apifilename' => 'uc.ashx',29 'charset' => '',30 'dbcharset' => '',31 'synlogin' => '1',32 'recvnote' => '1',33 'extra' => false,34 'tagtemplates' => '',35 'allowips' => '',36 ),37 );38 ?>
I don't know why I want to do this. If I don't change it like this, you won't return a piece of js to you during discuz login, not to mention synchronous login, so that synchronous login will trigger the uc of your website when you log on to discuz. asxh public override ApiReturn SynLogin (int uid) method you can write your operations here, for example