|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
左手拿着MOTOLOLA右手拿着NOKIA,要多潇洒,有多潇洒,哈哈,终于学会了,但是可能这个时候,又会有人不经意的拍拍肩膀对你说:哥们,别高兴的太早,你还是菜鸟,离学会还差着一大截呢!
<?php /** * 微信"大众平台接口PHP100封装功效类文件 * author PHP100.com 张恩平易近 * date 2013-4-9 PRC:E+8 23:03 * linkme QQ925939 chuangen.com */ define("TOKEN", "chuangenit"); $wechatObj = new wechatCallbackapiTest(); $wechatObj->weixin_run(); //履行吸收器办法 class wechatCallbackapiTest { private $fromUsername; private $toUsername; private $times; private $keyword; public function weixin_run(){ $this->responseMsg(); $arr[]=array("创恩很靠谱,PHP100也不错!","aa","http://www.chuangen.com/pic/hj/s_4.png","http://www.chuangen.com"); $arr[]=array("创恩很靠谱,PHP100也不错!","aa","http://www.chuangen.com/pic/hj/s_4.png","http://www.chuangen.com"); $arr[]=array("创恩很靠谱,PHP100也不错!","aa","http://www.chuangen.com/pic/hj/s_4.png","http://www.chuangen.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 , option if($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(内容),array(ID) //news,array(array(题目,引见,图片,超链接),...小于10条),array(条数,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; //判别数组数不超越设置数 $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来连接数据库了,这期间你是怎么学会的,我们不去考证了,但是事实证明,你已经可以了。 |
|