Debugging of interface parameters of the PHP micro-communication Platform _php example of a method for judging user behavior

Source: Internet
Author: User

The example of this article is about how to judge the user behavior by debugging the interface parameters of the PHP version micro-communication platform. Share to everyone for your reference, specific as follows:

Micro-credit development, found that there is an important variable $postobj, obtained an XML structure loaded in the object because the user sent the event, before only know the user to send a message, I processed.

Today to get a user subscription to push a message function, but found that do not know how to determine the user is subscribed to the operation, or unsubscribe, or send a message, the code is as follows:

Public Function responsemsg ()
{
 global $db;
 Get post data, May is due to the different environments
 $postStr = $GLOBALS ["Http_raw_post_data"];
 $POSTOBJ = simplexml_load_string ($postStr, ' simplexmlelement ', libxml_nocdata);
 Writeover ("Msg.txt", $postStr.) RN "," A + ");
 。。。。。
}

Found that the $POSTSTR is not encapsulated before the string, direct printing, you can know the user's behavior, test output files are as follows:

<xml><tousername><! [cdata[gh_a64528aca3b]]></tousername>
<fromusername><![ Cdata[osgh_jvetxjslfk_6qsigevasyk]]></fromusername>
<createtime>1394705044</createtime >
<msgtype><![ Cdata[text]]></msgtype>
<content><![ cdata[ha]]></content>
<MsgId>5990212551746www.phpfensi.com353512</MsgId>
</xml >

Msgtype can determine the user behavior text indicates that the user entered a text message, if it is a subscription, then it is the event that everyone test themselves.

An example of a new user paying attention to a message sent by a public account is the following code:

<xml><tousername><! [cdata[gh_a5218aca3b]]></tousername>
<fromusername><![ Cdata[osgh_jvetxjslfk_6qsigevyk]]></fromusername>
<CreateTime>1394706271</CreateTime>
<msgtype><! [cdata[event]]></msgtype>
<event><![ Cdata[subscribe]]></event>
<eventkey><![ Cdata[]]></eventkey>
</xml>

This allows you to get a specific type of event.

$msgtype = $POSTOBJ->msgtype; can judge the behavior of the user, the subsequent operation is much more convenient.

Attach code to write log file:

The ' R ' read-only mode opens, pointing the file pointer to the file header.

' r+ ' read-write mode opens, pointing the file pointer to the file header.

The ' W ' write mode opens, pointing the file pointer to the file header and truncating the file size to zero. If the file does not exist, try creating it.

' w+ ' read-write mode opens, points the file pointer to the file header and truncates the file size to zero. If the file does not exist, try creating it.

The ' a ' write mode opens, pointing the file pointer at the end of the file. If the file does not exist, try creating it.

An ' A + ' read-write mode opens, pointing the file pointer to the end of the file. If the file does not exist, try creating it.

The PHP instance code is as follows:

function Writeover2 ($filename, $data, $method = "rb+", $iflock =1)
{
 @touch ($filename),/* created if the file does not exist. Can be used File_ exists validation and other creation of file functions instead. The test result efficiency is quite * * *
 $handle = @fopen ($filename, $method);
 if ($iflock) {
  flock ($handle, LOCK_EX);
 }
 Fwrite ($handle, $data);
 if ($method = = "rb+") ftruncate ($handle, strlen ($data));
 Fclose ($handle);


For more information on PHP related content readers can view the site topics: "PHP micro-credit Development Skills summary", "PHP coding and transcoding Operation skills Summary", "PHP Network Programming Skills Summary", "PHP basic Grammar Introductory Course", "PHP string (String) Usage Summary", "php+ MySQL Database operations Introduction tutorial and PHP Common database operation Skills Summary

I hope this article will help you with the PHP program design.

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.