As has been said, how to open and configure the micro-letter service number of the open mode, this time to talk about the interaction with the user some of the events.
This is mainly about the user through the micro-letter service number input box, sent to the service number of the message, how to automatically reply to the user. Non-open mode, only need to be in the micro-letter automatic response configuration keyword can be. The developer model needs to be responsemsg or defined by itself.
The Responsemsg method is the method in the relevant class when the first step is opened.
First look at this method:
Public Function responsemsg () {
$postStr = $GLOBALS ["Http_raw_post_data"];
if (! empty ($POSTSTR)) {
$po Stobj = simplexml_load_string ($postStr, ' simplexmlelement ', libxml_nocdata);
$MsgType = $postObj->msgtype;
$fromUsername = $postObj->fromusername;
$toUsername = $postObj->tousername;
$keyword = Trim ($postObj->content);
$time = time ();
$TEXTTPL = "<XML>
<tousername><![ Cdata[%s]]></tousername>
<fromusername><![ Cdata[%s]]></fromusername>
<createtime>%s</createtime>
<msgtype><![ Cdata[%s]]></msgtype>
<content><![ Cdata[%s]]></content>
</xml>
$msgType = "text";
$contentStr = ' Pro, test succeeded, already to your information! ';
$resultStr = sprintf ($TEXTTPL, $fromUsername, $toUsername, $time, $msgType, $CONTENTSTR);
Echo $resultStr; exit ();
} else {
exit ();
}
}
The method above is basically a simpler approach. Below is a description of the above important variable values representing meaning:
$POSTOBJ the data that the user sends over, in the form of XML
The following is the result of parsing xml:
$MsgType Message Type
The OpenID $fromUsername the sender of the message
$toUsername Developer Micro-signal
What $keyword Send (Note: This example is in text form)
$time are written by yourself and sometimes needed when doing business needs.
$TEXTTPL is the template style that is returned to the user. Pattern styles are also divided into several types
This is the ordinary message type: text, image, voice, video, etc., other modes of detailed view of the document, there is an event type, the next article will be detailed description.
This example uses text reply mode, other modes to view the official documents in detail
Describes the parameters of the XML below:
Tousername Please use the above fromusername to send to the user
Fromusername please use Tousername message sender (Developer micro-signal)
Createtime time (time stamp)
Msgtype message Type (reply, note: This example text)
Content replies can be written as a label. Try to control the number of words, not too much.
After the method is set up, input the data through the text box of the micro-letter service number, click Send, and you will see the reply by the service number.
Pro, Test success, has been to your information!
To this, the simplest text has been completed. The other common reply operation is basically the same process, find the corresponding type of acceptance and reply XML, and then do the operation.
Hint: Developer, can judge in Msgtype, see the message that the user sends, belong to that type, do different operation again.
For example:
if ($MsgType = = ' text ') {}
if ($MsgType = = ' image ') {}
if ($MsgType = = ' Voice ') {Voice accepted parameters, please refer to the normal message class document above, reply to action: Please select the XML format you want to reply to, please refer to the Reply User template style connection. }