国产探花免费观看_亚洲丰满少妇自慰呻吟_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.     $keyword = trim($postObj->Content); 
  35.     $time = time(); 
  36.     $textTpl = "<xml> 
  37.        <tousername><!--[CDATA[%s]]--></tousername> 
  38.        <fromusername><!--[CDATA[%s]]--></fromusername> 
  39.        <createtime>%s</createtime> 
  40.        <msgtype><!--[CDATA[%s]]--></msgtype> 
  41.        <content><!--[CDATA[%s]]--></content> 
  42.        <funcflag>0</funcflag> 
  43.        </xml>";     
  44.     if(!emptyempty$keyword )) 
  45.     { 
  46.      $msgType = "text"
  47.      if($keyword=="1"){ 
  48.      $contentStr = "qiphon";} 
  49.      if($keyword=="2"){ 
  50.      $contentStr = "最新資訊:《環境違法行為舉報獎勵辦法》";} 
  51.      if($keyword=="3"){ 
  52.      $contentStr = "31離婚協議/n32租房合同/n33交通事故協議書";}      
  53.      $resultStr = sprintf($textTpl$fromUsername$toUsername$time$msgType$contentStr); 
  54.      echo $resultStr
  55.     }else
  56.      echo "Input something..."
  57.     } 
  58.   
  59.   }else { 
  60.    echo ""
  61.    exit
  62.   } 
  63.  } 
  64.   
  65.  private function checkSignature() 
  66.  { 
  67.   $signature = $_GET["signature"]; 
  68.   $timestamp = $_GET["timestamp"]; 
  69.   $nonce = $_GET["nonce"];  
  70.   
  71.   $token = TOKEN; 
  72.   $tmpArr = array($token$timestamp$nonce); 
  73.   sort($tmpArr); 
  74.   $tmpStr = implode( $tmpArr ); 
  75.   $tmpStr = sha1( $tmpStr ); 
  76.   //Vevb.com 
  77.   if$tmpStr == $signature ){ 
  78.    return true; 
  79.   }else
  80.    return false; 
  81.   } 
  82.  } 
  83.   
  84. ?> 

 

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 平乡县| 滁州市| 扬中市| 含山县| 鄂尔多斯市| 新津县| 景德镇市| 宝清县| 大新县| 冷水江市| 运城市| 塘沽区| 芜湖市| 桃源县| 营口市| 体育| 礼泉县| 衡南县| 广河县| 洱源县| 朝阳县| 天峻县| 玉树县| 托克逊县| 水城县| 宜都市| 灵丘县| 丹东市| 普兰店市| 新泰市| 麻城市| 沽源县| 和硕县| 洪泽县| 团风县| 开阳县| 安西县| 内乡县| 合山市| 定边县| 宽甸|