When Ucenter and application communication fail

Source: Internet
Author: User
Tags testlink

Failure is common.

For the first contact with Ucenter, adding one of their own applications is the biggest headache is the discovery of communication failure.
To solve this problem, first understand how Ucenter communicates with the application.
Only by knowing how the Ucenter communicates with the application can we find the cause of the communication failure.
Let's find it from the source!

If it's easier to use Firefox to help find the source of communication failure," I'm not advertising Firefox! It's really good to use. "

Let's see who it is. Output communication failure four characters:
view frame source in Firefox, right-click this frame," Note that you want to "near communication failure".

then find the app access address in the source code. Find the location where the communication failed.
Please note that communication failure four characters are generated by JS. Direct lookup of communication failures is not found.
after a serious study, we found that the communication failure was generated by code similar to the following:

<div id=" Status_3 "></div><script id=" Link_3 "testlink=" Admin.php?m=app&a=ping&inajax=1&url=http://www.seinc.com/slight&ip=&appid=3&random= 30773 "></script><script>apps[2] = ' 3 '; </script> 

appears to be accessed via admin.php to the application address, judging whether the communication was successful based on the access results.
Literally, it should be a ping inside the app. It seems like Ajax to access it.
Now that we've found the reason for the communication failure, let's go to the admin.php app and find out what the ping is going to do, and what the results are to determine if the communication succeeds or fails.

&NBSP;

Let's take a look at the Ucenter directory. It is clear that the operating code is inside the control directory. Go to the control directory, whoa! Sure enough, there's a app.php.
Don't worry! I don't see any other admin directory. Since the app has just been called through admin.php, then this action is written in the admin directory.
In fact, the control directory of app.php is the normal operation of the app. If you open the code to find the Ping method it is not found.

OK, let's go into the admin directory, open app.php, find ping. Well! Got it! such as:

This method is called onping. Let's analyze the key to find out where:

if ($status = = ' 1 ') {echo ' document.getelementbyidx_x (\ ' Status_ '. $appid. ' \ '). InnerHTML = "<span class=\ ' green\ ' > '. $this->lang[' App_connent_ok '). '  </span> "; Testlink ();"; } else {echo ' document.getelementbyidx_x (\ ' Status_ '. $appid. ' \ '). InnerHTML = "<span class=\ ' red\ ' > '. $ this->lang[' App_connent_false ']. '  </span> "; Testlink ();"; }

If the value of status is 1 is OK, the reverse is false. Just look at the code above. We notice that the address that the Onping method accesses is actually the application address +/api/+ $app [' Apifilename '].
So with the toes also understand, actually access is really address is the application directory API directory uc.php.
If you don't believe it, we'll give the output a look. Make the following changes to the code:

if ($status = = ' 1 ') {echo ' document.getelementbyidx_x (\ ' Status_ '. $appid. ' \ '). InnerHTML = "<span class=\ ' green\ ' > '. $url. '  </span> "; Testlink ();"; } else {echo ' document.getelementbyidx_x (\ ' Status_ '. $appid. ' \ '). InnerHTML = "<span class=\ ' red\ ' > '. $ URL. '  </span> "; Testlink ();"; }

Note that we have replaced the output's OK or false with the top URL. Check out the app list in admin background:
Oh, the address came out! We copy the failed address and the successful address separately to the address bar for access.
If there is only a 1 on the white page, it means success. If it's something else, it means it's a failure!

Now that we know the real address of the visit, let's see how this address tells Ucenter that the communication was successful or failed.

After opening the uc.php in the app directory API, we notice that it first decodes the get-over code and responds with an action command:

$code = $_get[' code ');p arse_str (Authcode ($code, ' DECODE ', Uc_key), $get);//First decryption is the long string behind Url?code. if (MAGIC_QUOTES_GPC) {$get = Dstripslashes ($get);} Print_r ($get);//exit;if (Time ()-$get [' time '] > 3600} {exit (' authracation has expiried ');} if (empty ($get)) {exit (' Invalid Request ');} $action = $get [' Action '];//decoded to get the action is the instruction passed by Ucenter. What instructions will ucenter pass by default? Go back to Ucenter's app.php and study onping. We found that the default pass is the test instruction.

Then we'll find the test in uc.php. Finally, the code that executes when the default connection is found is fast.
Depending on the individual situation, the code here may be different for each person. A careful study will find out where the problem is.

If lazy, can not understand, then directly deleted ... then echo 1; deceive Ucenter. See the communication success of the small hook, the heart more comfortable it.

An article just tells you why it failed. How to get the word for success. What is the impact of communication success and failure is beyond the scope of this article.
Finally, let's clean up how the ucenter interacts with the app:

  • ucenter uses the api/uc.php in the application to obtain the application communication situation, sends the instruction information. such as user updates, user deletion and other operations. There are corresponding methods in the uc.php. That is, if you have user action in Ucenter. And in the application to synchronize the words will expect uc.php. Ucenter each important operation sends instructions to uc.php. and will actively monitor the communication situation.
  • The app accesses user data through Uc_client. such as landing, registration and so on. This I have mentioned in the integration of Ucenter and WordPress.

If you add a kind of application, you can get a" communication success "small tick. Then this article is not written in vain.
Please follow other articles about Ucenter.

Thank you!
Happiness comes from sharing!

When Ucenter and application communication fail

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.