WeChat development series tutorial (2)

Source: Internet
Author: User
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!

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.