[PHP微信開發(fā)]輸入關(guān)鍵詞自動推送相關(guān)信息api_第1頁
[PHP微信開發(fā)]輸入關(guān)鍵詞自動推送相關(guān)信息api_第2頁
[PHP微信開發(fā)]輸入關(guān)鍵詞自動推送相關(guān)信息api_第3頁
[PHP微信開發(fā)]輸入關(guān)鍵詞自動推送相關(guān)信息api_第4頁
[PHP微信開發(fā)]輸入關(guān)鍵詞自動推送相關(guān)信息api_第5頁
全文預(yù)覽已結(jié)束

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進行舉報或認(rèn)領(lǐng)

文檔簡介

兩個文件, api.php、 weixincontent.php 用途是在微信上面,當(dāng)用戶新關(guān)注你,會自動推送一條消息。 當(dāng)用戶發(fā)送相關(guān)信息 (關(guān)鍵詞 ),會自動將關(guān)鍵詞在你網(wǎng)站 (weixincontent.php)上面進行內(nèi)容搜索,獲取到相關(guān)數(shù)據(jù)后推送給用戶。并在后面附加一條“沒有找到滿意的內(nèi)容?戳這里查看更多【關(guān)鍵詞】內(nèi)容!”,所有推送的內(nèi)容都可以點擊鏈接到你對應(yīng)的網(wǎng)站頁面。 api.php代碼 valid(); else $wechatObj-responseMsg(); class wechatCallbackapiTest public function valid() $echoStr = $_GETechostr; if($this-checkSignature() echo $echoStr; exit; private function checkSignature() $signature = $_GETsignature; $timestamp = $_GETtimestamp; $nonce = $_GETnonce; $token = TOKEN; $tmpArr = array($token, $timestamp, $nonce); sort($tmpArr); $tmpStr = implode( $tmpArr ); $tmpStr = sha1( $tmpStr ); if( $tmpStr = $signature ) return true; else return false; public function responseMsg() $postStr = $GLOBALSHTTP_RAW_POST_DATA; $time = time(); if (!empty($postStr) $postObj = simplexml_load_string($postStr, SimpleXMLElement, LIBXML_NOCDATA); $fromUsername = $postObj-FromUserName; $toUsername = $postObj-ToUserName; $keyword = trim($postObj-Content); if($postObj-Event=subscribe)/判斷是否是新關(guān)注 $textTpl = %s %d ; $msgType=text; $content=親,感謝關(guān)注【 *】公眾微信號! ; $resultStr = sprintf($textTpl, $fromUsername, $toUsername, time(),$msgType, $content,$flag); echo $resultStr; elseif($keyword)/發(fā)送關(guān)鍵詞獲取相關(guān)信息 if (strstr($keyword,你好 ) | strstr($keyword,您好 ) | strstr($keyword,在嗎 ) | strstr($keyword,在不 ) | strstr($keyword,喂 ) | strstr($keyword,有人沒 ) | strstr($keyword,有人嗎 ) | strstr($keyword,?)/默認(rèn)如果有人輸入這些將自動回下面的內(nèi)容 $textTpl = %s ; $content=親,想要什么直接回復(fù)想要的詞就可以哦! ; $msgType=text; echo $resultStr = sprintf($textTpl, $fromUsername, $toUsername, time(),$msgType,$content); else/如果不是上面的默認(rèn)關(guān)鍵詞,則將用戶輸入的關(guān)鍵詞發(fā)送到相關(guān)的網(wǎng)站獲取數(shù)據(jù)再返回到微信推送給用戶 $xml=crawlContent($keyword);/抓取數(shù)據(jù) $xmlArr=xml_to_array($xml);/解析 xml為數(shù)組 $items=count($xmlArrpre);/這里的 pre對應(yīng)的是 weixincontent.php里面的 pre if ($items)/如果關(guān)鍵詞搜索到相關(guān)結(jié)果則運行下面程序 $picTplhead = %s ;/與下面的 picTpl拼接 $picTpl = ; $picTplfoot = 0 ;/與上面的 picTpl拼接 $tickets_count=$items=7?1:$items; $resultStrhead = sprintf($picTplhead, $fromUsername, $toUsername, time(), $tickets_count+1);/圖文消息頭 部 if ($items=7) foreach($xmlArr as $k=$f) $title=$ftitle; $description=$fdesc; $image=$fpicurl; $url=$furl; $resultpictpl .= sprintf($picTpl,$title,$description,$image,$url); elseif($items0) foreach($xmlArr as $k=$f) foreach($f as $k=$list) $title=$listtitle; $description=$listdesc; $image=$listpicurl; $url=$listurl; $resultpictpl .= sprintf($picTpl,$title,$description,$image,$url); /附加最后一條內(nèi)容 $title= 沒有找到滿意的內(nèi)容? rn 戳這里查看更多【 .$keyword.】內(nèi)容! ; $description=; $image=/public_pic.jpg; $url=/search/.$keyword;/這個 url 是對應(yīng)你網(wǎng)站的 url $resultpictpl .= sprintf($picTpl,$title,$description,$image,$url); $resultpictplfoot = sprintf($picTplfoot);/圖文消息尾部 echo $resultStr = $resultStrhead.$resultpictpl.$resultpictplfoot; else echo 親,感謝關(guān)注【 *】公眾微信號! ; exit; function crawlContent($keyword)/根據(jù)關(guān)鍵詞抓取內(nèi)容 $url=/weixincontent.php?key=$keyword; /$url這個文件要放到網(wǎng)站上面,作用是獲取 $keyword相關(guān)的數(shù)據(jù) $ch=curl_init(); curl_setopt($ch,CURLOPT_URL,$url); curl_setopt($ch,CURLOPT_HEADER,0); curl_setopt($ch,CURLOPT_TIMEOUT,30); curl_setopt($ch,CURLOPT_NOBODY,0); curl_setopt($ch,CURLOPT_RETURNTRANSFER,1); curl_setopt($ch,CURLOPT_POST,0); curl_setopt($ch,CURLOPT_USERAGENT,Mozilla/5.0 (Windows NT 6.1) AppleWebKit/536.11 (KHTML, like Gecko) Chrome/20.0.1132.47 Safari/536.11); $html=curl_exec($ch); curl_close($ch); return $html; function xml_to_array($xml) $array = (array)(simplexml_load_string($xml); foreach ($array as $key=$item) $array$key = struct_to_array(array)$item); return $array; function struct_to_array($item) if(!is_string($item) $item = (array)$item; foreach ($item as $key=$val) $item$key = struct_to_array($val); return $item; ? weixincontent.php代碼 query($sql,5); $html.=; while ($f=$rs-movenext() $url=/.$ff_id.html; $picurl=/images/.$ff_pic.;/你

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論