After a short answer is completed, many people do not know how to automatically send messages to users. I will share with you how to automatically send messages after successful notifications. After a short answer is completed, many people do not know how to automatically send messages to users. I will share with you how to automatically send messages after successful notifications.
We can see that event push is also introduced in the api. how is this event of interest used? Today, no nonsense. go directly to the code:
ResponseMsg (); class wechatCallbackapiTest {public function responseMsg () {$ 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 "text": $ resultStr = $ this-> receiveText ($ postObj); break; case "event": $ resultStr = $ this-> receiveEvent ($ postObj ); break; default: $ resultStr = "unknow msg type :". $ RX_TYPE; break;} echo $ resultStr;} else {echo ""; exit () ;}} privat E function deleetext ($ object) {if (! Empty ($ object) {$ fromUsername = $ object-> FromUserName; $ toUsername = $ object-> ToUserName; $ keyword = trim ($ object-> Content ); $ time = time (); // automatically replies to text messages $ textTpl ="
%s
%s
% S
%s
3
<! [CDATA [test title 1]>
测试内容啊1!
http://weixin.comsenz-service.com/20.jpg
http://www.baidu.com
<! [CDATA [haha, title]>
内容标题
http://weixin.comsenz-service.com/540.png
http://www.discuz.com
<! [CDATA [12345 haha, title]>
798465789内容标题
http://weixin.comsenz-service.com/20.jpg
http://www.google.com
1
"; If (! Empty ($ keyword) {$ msgType = "news"; // type news: text message, text: text message event: event $ resultStr = sprintf ($ textTpl, $ fromUsername, $ toUsername, $ time, $ msgType, $ contentStr); echo $ resultStr;} else {echo "Input something... ";}} else {echo" "; exit ;}} private function receiveEvent ($ object) {$ contentStr =" "; switch ($ object-> Event) {case "subscribe": $ contentStr = "Welcome to community manager! We can always contact you !! "; Break;} $ resultStr = $ this-> transmitText ($ object, $ contentStr); return $ resultStr;} private function transmitText ($ object, $ content, $ flag = 0) {$ textTpl ="
%s
%s
% S
text
%s
% D
"; $ ResultStr = sprintf ($ textTpl, $ object-> FromUserName, $ object-> ToUserName, time (), $ content, $ flag ); return $ resultStr ;}}?>
The above is the detailed content of the development series (2). For more information, see other related articles on php Chinese network!