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

首頁 > 編程 > PHP > 正文

PHP微信接口封裝類

2020-03-22 18:30:54
字體:
供稿:網(wǎng)友
  • <?php/*** 微信公眾平臺接口PHP封裝功能類文件* author* date 2013-4-9 PRC:E+8 23:03*/define("TOKEN", "chuangenit");$wechatObj = new wechatCallbackapiTest();$wechatObj->weixin_run(); //執(zhí)行接收器方法html' target='_blank'>class wechatCallbackapiTest{private $fromUsername;private $toUsername;private $times;private $keyword;public function weixin_run(){$this->responseMsg();$arr[]=array("很靠譜,不錯!","aa","http://www.chuangen.com/pic/hj/s_4.png","http://www.baidu.com");$arr[]=array("很靠譜,不錯!","aa","http://www.chuangen.com/pic/hj/s_4.png","http://www.baidu.com");$arr[]=array("很靠譜,不錯!","aa","http://www.chuangen.com/pic/hj/s_4.png","http://www.baidu.com");$this->fun_xml("news",$arr,array(2,0));}function t($n){include("t_api.php");$c_name=$t_api[$n];$json=file_get_contents("http://m.weather.com.cn/data/101110310.html");return json_decode($json);}public function valid(){$echoStr = $_GET["echostr"];//valid signature , optionif($this->checkSignature()){echo $echoStr;exit;}}public function responseMsg(){$postStr = $GLOBALS["HTTP_RAW_POST_DATA"];if (!empty($postStr)){$postObj = simplexml_load_string($postStr, 'SimpleXMLElement', LIBXML_NOCDATA);$this->fromUsername = $postObj->FromUserName;$this->toUsername = $postObj->ToUserName;$this->keyword = trim($postObj->Content);$this->times = time();}else {echo "this a file for weixin API!";exit;}}//微信封裝類,//type: text 文本類型, news 圖文類型//text,array(內(nèi)容),array(ID)//news,array(array(標(biāo)題,介紹,圖片,超鏈接),...小于10條),array(條數(shù),ID)private function fun_xml($type,$value_arr,$o_arr=array(0)){//=================xml header============$con="<xml><ToUserName><![CDATA[{$this->fromUsername}]]></ToUserName><FromUserName><![CDATA[{$this->toUsername}]]></FromUserName><CreateTime>{$this->times}</CreateTime><MsgType><![CDATA[{$type}]]></MsgType>";//=================type content============switch($type){case "text" :$con.="<Content><![CDATA[{$value_arr[0]}]]></Content><FuncFlag>{$o_arr}</FuncFlag>";break;case "news" :$con.="<ArticleCount>{$o_arr[0]}</ArticleCount><Articles>";foreach($value_arr as $id=>$v){if($id>=$o_arr[0]) break; else null; //判斷數(shù)組數(shù)不超過設(shè)置數(shù)$con.="<item><Title><![CDATA[{$v[0]}]]></Title><Description><![CDATA[{$v[1]}]]></Description><PicUrl><![CDATA[{$v[2]}]]></PicUrl><Url><![CDATA[{$v[3]}]]></Url></item>";}$con.="</Articles><FuncFlag>{$o_arr[1]}</FuncFlag>";break;} //end switch//=================end return============echo $con."</xml>";}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;}}}?>

    PHP編程

    鄭重聲明:本文版權(quán)歸原作者所有,轉(zhuǎn)載文章僅為傳播更多信息之目的,如作者信息標(biāo)記有誤,請第一時間聯(lián)系我們修改或刪除,多謝。

  • 發(fā)表評論 共有條評論
    用戶名: 密碼:
    驗證碼: 匿名發(fā)表
    主站蜘蛛池模板: 奈曼旗| 兰考县| 小金县| 东乌珠穆沁旗| 荥阳市| 门头沟区| 敦煌市| 益阳市| 祁东县| 伊通| 承德县| 东辽县| 禄丰县| 广汉市| 连云港市| 孟州市| 盖州市| 吉隆县| 宁陵县| 石景山区| 恭城| 陵川县| 莫力| 永春县| 遵义县| 江油市| 白朗县| 师宗县| 武威市| 阿拉善左旗| 保亭| 潮州市| 林口县| 成安县| 阿勒泰市| 连州市| 雅安市| 离岛区| 彩票| 雅安市| 石首市|