When you follow or remove the public account, the event is pushed to the URL entered by the developer. It is convenient for developers to send a welcome message to users or unbind accounts. Below is an example of public platform interest and interest cancellation :? Phpdefine (... when you follow and cancel the public account, this event is pushed to the URL entered by the developer. This allows developers to send welcome messages to users or unbind accounts.
The following is an example of paying attention to and removing attention from the public platform:
ResponseMsg ();} else {$ wechatObj-> valid ();} class wechatCallbackapiTest {public function valid () {$ echoStr = $ _ GET ["echostr"]; if ($ this-> checkSignature () {echo $ echoStr; exit ;}} public function responseMsg () // execute the receiver method {$ postStr = $ GLOBALS ["HTTP_RAW_POST_DATA"]; if (! Empty ($ postStr) {$ postObj = simplexml_load_string ($ postStr, 'simplexmlelement', LIBXML_NOCDATA); $ RX_TYPE = trim ($ postObj-> MsgType); switch ($ RX_TYPE) {case "event": $ result = $ this-> receiveEvent ($ postObj); breadk;} echo $ result;} else {echo ""; exit ;}} private function receiveEvent ($ object) {$ content = ""; switch ($ postObj-> Event) {case "subscribe": $ content = "Welcome to Wangzhi blog "; // Here is the prompt message break; case "unsubscribe": $ content = ""; break;} $ result = $ this-> transmitText ($ object, $ content); return $ result;} private function transmitText ($ object, $ content) {$ textTpl ="
%s
%s
% S
text
%s
0
"; $ Result = sprintf ($ textTpl, $ object-> FromUserName, $ object-> $ ToUserName, time (), $ content); return $ result ;} private function checkSignature () {$ signature =$ _ GET ["signature"]; $ timestamp =$ _ GET ["timestamp"]; $ nonce = $ _ GET ["nonce"]; $ token = TOKEN; $ tmpArr = array ($ token, $ timestamp, $ nonce); sort ($ tmpArr, SORT_STRING ); $ tmpStr = implode ($ tmpArr); $ tmpStr = sha1 ($ tmpStr); if ($ tmpStr ==$ Signature) {return true;} else {return false ;}}?>
Code parameters:
Parameter description
ToUserName developer id
FromUserName sender account (an OpenID)
CreateTime message creation time (integer)
MsgType message type, event
Event type, subscribe and unsubscribe)