Ucenter communication failure when combined with other applications, Ucenter application principle and debugging

Source: Internet
Author: User
Ucenter communication failure when combined with other applications
Ucenter is a user center, multiple applications can use Ucenter, so that users have a pass, not once to register a different user name
Now the Internet User Center is almost Tencent's user center, because everyone has QQ number


But when you do the application of how to join Ucenter such articles online a lot of
Custom application, after joining the application list, Ucenter detects whether communication with the application is normal and sometimes fails.
His principle is to go to a Web site to detect his return value, the address is generally like this
testlink= "admin.php?m=app&a=ping&inajax=1&url=http%3a%2f%2f192.168.0.89%3a5635&ip=&appid=3 &random=14230 "
The function that responds to this link is the onping in/admin/app.php/.
The role of this function is to access the parameters that you add when you configure the application, and typically the URL of this location is
Http://192.168.0.89:5619/api/uc.php?code=28b4P9649Mub1wWGejarHl214enhA2Xt7vLkJPBskk50AwqDza8Ehx0T5%2FNwGtsBdB%2BmZ%2FTCibQ
This code is an encrypted string,
In the api/uc.php, the code is decoded and decoded, which is basically the string
action=test&time=1321131313

Contains two parameters, call the function and the time of the call, so that only the return value is 1 on it, you can communicate successfully

$get = $post = Array ();
$code = strval (@$_get[' code '); 
Parse_str (Uc_api_x_authcode ($code, ' DECODE ', Uc_key), $get);
$timestamp = time ();
if (empty ($get))
{
    die (' Invalid Request ');
} elseif ($timestamp-$get [' time '] > 3600)
{
     die (' Authracation has expiried ');
}
$action = $get [' action '];
$post = Xml_unserialize (file_get_contents (' php://input '));
 
if (In_array ($get [' action]], array (
    ' test ',
    ' renameuser ',
    ' synlogin ',
    ' synlogout ',
    ' UPDATEPW ',
))
{
    $funcname = "uc_api_{$get [' Action ']}";    
    if (function_exists ($funcname))
    {
        exit ($funcname ($get, $post));
    }
Exit (api_return_failed);

/* Communicate with Ucenter
/function Uc_api_test ($get, $post) {return
    api_return_succeed;
}
/**/


Look at what the server has done, iterate through the application and send a onping test to the application each time you open the application list, the function

The onping () function in control/admin/app.php in Ucenter


		if ($app [' Extra '] [' AppPath '] && @include $app [' Extra '] [' AppPath ']. /api/'. $app [' Apifilename ']) {

			$uc _note = new Uc_note ();
			$status = $uc _note->test ($note [' GetData '], $note [' postdata ']);
		} else {

			$this->load (' note ');
			$url = $_env[' Note ']->get_url_code (' Test ', ', ', $appid);
			Die ($url);
			Var_dump ($_env[' app ');d ie ();
			$status = $_env[' app ']->test_api ($url, $IP);
		}


If the call returns a result of 1 those displayed successfully, otherwise the display fails, Test_api in the model/app.php file



	function Test_api ($url, $ip = ') {
		$this->base->load (' misc ');
		if (! $ip) {
			$ip = $_env[' Misc ']->get_host_by_url ($url);
		}

		if ($ip < 0) {return
			FALSE;
		}
		Return $_env[' misc ']->dfopen ($url, 0, ', ', 1, $IP);
	}


To call the Dfopen function in misc.php.
The Dfopen function uses PHP's underlying function fsockopen to communicate with the program, returning the result of the communication to the Onping function, if the communication succeeds if 1, the display fails

In order to facilitate debugging we can in the Dfopen information, the input and output values recorded in the file,

Error_log ("[uc_server]\ r \n $url\ r \ n$post\r\n\r\n"  ' c:/log/php_fopen.txt ');


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.