国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 開發 > PHP > 正文

php微信開發之關注事件

2024-05-04 21:50:46
字體:
來源:轉載
供稿:網友

本文實例為大家分享了php微信關注事件的具體代碼,供大家參考,具體內容如下:

  1. <!--?php 
  2. /** 
  3.  * wechat php test 
  4.  */ 
  5.   
  6. //define your token 
  7. define("TOKEN""weixin"); 
  8. $wechatObj = new wechatCallbackapiTest(); 
  9. //$wechatObj--->valid(); 
  10. $wechatObj->responseMsg(); 
  11. class wechatCallbackapiTest 
  12.   public function valid() 
  13.   { 
  14.     $echoStr = $_GET["echostr"]; 
  15.   
  16.     //valid signature , option 
  17.     if($this->checkSignature()){ 
  18.       echo $echoStr
  19.       exit
  20.     } 
  21.   } 
  22.   
  23.   public function responseMsg() 
  24.   { 
  25.     //get post data, May be due to the different environments 
  26.     $postStr = $GLOBALS["HTTP_RAW_POST_DATA"]; 
  27.   
  28.     //extract post data 
  29.     if (!emptyempty($postStr)){ 
  30.   
  31.         $postObj = simplexml_load_string($postStr'SimpleXMLElement', LIBXML_NOCDATA); 
  32.         $fromUsername = $postObj->FromUserName; 
  33.         $toUsername = $postObj->ToUserName; 
  34.         $type = $postObj->MsgType; 
  35.         $customevent = $postObj->Event; 
  36.         $keyword = trim($postObj->Content); 
  37.         $time = time(); 
  38.         $textTpl = "<xml> 
  39.               <tousername><!--[CDATA[%s]]--></tousername> 
  40.               <fromusername><!--[CDATA[%s]]--></fromusername> 
  41.               <createtime>%s</createtime> 
  42.               <msgtype><!--[CDATA[%s]]--></msgtype> 
  43.               <content><!--[CDATA[%s]]--></content> 
  44.               <funcflag>0</funcflag> 
  45.               </xml>";        
  46.         if($type=="event" and $customrevent=="subscribe"){ 
  47.           $contentStr = "感謝你的關注/n回復1查看聯系方式/n回復2查看最新資訊/n回復3查看法律文書"
  48.           $msgType = "text"
  49.           $resultStr = sprintf($textTpl$fromUsername$toUsername$time$msgType$contentStr); 
  50.           echo $resultStr
  51.           }   
  52.         if(!emptyempty$keyword )) 
  53.         {                 
  54.           $msgType = "text"
  55.           if($keyword=="1"){ 
  56.           $contentStr = "qiphon";} 
  57.           if($keyword=="2"){ 
  58.           $contentStr = "test 。";} 
  59.           if($keyword=="3"){ 
  60.           $contentStr = "test333";}          
  61.           $resultStr = sprintf($textTpl$fromUsername$toUsername$time$msgType$contentStr); 
  62.           echo $resultStr
  63.         }else
  64.           echo "Input something..."
  65.         } 
  66.   
  67.     }else { 
  68.       echo ""
  69.       exit
  70.     } 
  71.   } 
  72.   
  73.   private function checkSignature() 
  74.   { 
  75.     $signature = $_GET["signature"]; 
  76.     $timestamp = $_GET["timestamp"]; 
  77.     $nonce = $_GET["nonce"];   
  78.   
  79.     $token = TOKEN; 
  80.     $tmpArr = array($token$timestamp$nonce); 
  81.     sort($tmpArr); 
  82.     $tmpStr = implode( $tmpArr ); 
  83.     $tmpStr = sha1( $tmpStr ); 
  84.   
  85.     if$tmpStr == $signature ){ 
  86.       return true; 
  87.     }else
  88.       return false; 
  89.     } 
  90.   } 
  91.   
  92. ?> 

 

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 大埔县| 泾源县| 房产| 岳普湖县| 磐石市| 资阳市| 荔波县| 武清区| 双江| 淮阳县| 莒南县| 志丹县| 黎川县| 崇左市| 宜兰县| 扎兰屯市| 仪征市| 偏关县| 景泰县| 宣汉县| 普安县| 汶上县| 文安县| 云安县| 莱州市| 岚皋县| 临海市| 康定县| 耿马| 永登县| 东乌| 蓬莱市| 连山| 吉隆县| 盐山县| 东至县| 金秀| 永福县| 天气| 上高县| 防城港市|