佳木斯湛栽影视文化发展公司

主頁(yè) > 知識(shí)庫(kù) > php微信開發(fā)之關(guān)鍵詞回復(fù)功能

php微信開發(fā)之關(guān)鍵詞回復(fù)功能

熱門標(biāo)簽:電子圍欄 團(tuán)購(gòu)網(wǎng)站 Mysql連接數(shù)設(shè)置 Linux服務(wù)器 服務(wù)器配置 阿里云 科大訊飛語(yǔ)音識(shí)別系統(tǒng) 銀行業(yè)務(wù)

本文實(shí)例為大家分享了php微信開發(fā)之關(guān)鍵詞回復(fù)的具體代碼,供大家參考,具體內(nèi)容如下

?php
/**
 * wechat php test
 */

//define your token
define("TOKEN", "weixin");
$wechatObj = new wechatCallbackapiTest();
//$wechatObj->valid();
$wechatObj->responseMsg();
class wechatCallbackapiTest
{
 public function valid()
 {
 $echoStr = $_GET["echostr"];

 //valid signature , option
 if($this->checkSignature()){
  echo $echoStr;
  exit;
 }
 }

 public function responseMsg()
 {
 //get post data, May be due to the different environments
 $postStr = $GLOBALS["HTTP_RAW_POST_DATA"];

 //extract post data
 if (!empty($postStr)){

  $postObj = simplexml_load_string($postStr, 'SimpleXMLElement', LIBXML_NOCDATA);
  $fromUsername = $postObj->FromUserName;
  $toUsername = $postObj->ToUserName;
  $keyword = trim($postObj->Content);
  $time = time();
  $textTpl = "xml>
    ToUserName>![CDATA[%s]]>/ToUserName>
    FromUserName>![CDATA[%s]]>/FromUserName>
    CreateTime>%s/CreateTime>
    MsgType>![CDATA[%s]]>/MsgType>
    Content>![CDATA[%s]]>/Content>
    FuncFlag>0/FuncFlag>
    /xml>";  
  if(!empty( $keyword ))
  {
   $msgType = "text";
   if($keyword=="1"){
   $contentStr = "qiphon";}
   if($keyword=="2"){
   $contentStr = "最新資訊:《環(huán)境違法行為舉報(bào)獎(jiǎng)勵(lì)辦法》";}
   if($keyword=="3"){
   $contentStr = "31離婚協(xié)議\n32租房合同\n33交通事故協(xié)議書";}   
   $resultStr = sprintf($textTpl, $fromUsername, $toUsername, $time, $msgType, $contentStr);
   echo $resultStr;
  }else{
   echo "Input something...";
  }

 }else {
  echo "";
  exit;
 }
 }

 private function checkSignature()
 {
 $signature = $_GET["signature"];
 $timestamp = $_GET["timestamp"];
 $nonce = $_GET["nonce"]; 

 $token = TOKEN;
 $tmpArr = array($token, $timestamp, $nonce);
 sort($tmpArr);
 $tmpStr = implode( $tmpArr );
 $tmpStr = sha1( $tmpStr );

 if( $tmpStr == $signature ){
  return true;
 }else{
  return false;
 }
 }
}

?>

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

您可能感興趣的文章:
  • PHP微信開發(fā)之根據(jù)用戶回復(fù)關(guān)鍵詞\位置返回附近信息
  • php微信公眾號(hào)開發(fā)之關(guān)鍵詞回復(fù)

標(biāo)簽:江蘇 蚌埠 萍鄉(xiāng) 廣元 衢州 大理 棗莊 衡水

巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《php微信開發(fā)之關(guān)鍵詞回復(fù)功能》,本文關(guān)鍵詞  ;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問題,煩請(qǐng)?zhí)峁┫嚓P(guān)信息告之我們,我們將及時(shí)溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無(wú)關(guān)。
  • 相關(guān)文章
  • 收縮
    • 微信客服
    • 微信二維碼
    • 電話咨詢

    • 400-1100-266
    沈丘县| 团风县| 平遥县| 浦县| 定安县| 九寨沟县| 廉江市| 厦门市| 教育| 沂水县| 调兵山市| 吕梁市| 安宁市| 海宁市| 通渭县| 舒城县| 晋宁县| 沛县| 仙游县| 乐昌市| 镇巴县| 六盘水市| 汾阳市| 墨玉县| 青河县| 买车| 兴仁县| 都匀市| 沐川县| 兴化市| 大石桥市| 佛学| 额敏县| 荥经县| 麻阳| 靖安县| 酉阳| 兴宁市| 银川市| 彩票| 东乡族自治县|