php如何实现验证token、回复图文\文本、推送消息的实用微信类-创新互联
小编给大家分享一下php如何实现验证token、回复图文\文本、推送消息的实用微信类,希望大家阅读完这篇文章之后都有所收获,下面让我们一起去探讨吧!
成都创新互联是一家集网站建设,蔡家坡企业网站建设,蔡家坡品牌网站建设,网站定制,蔡家坡网站建设报价,网络营销,网络优化,蔡家坡网站推广为一体的创新建站企业,帮助传统企业提升企业形象加强企业竞争力。可充分满足这一群体相比中小企业更为丰富、高端、多元的互联网需求。同时我们时刻保持专业、时尚、前沿,时刻以成就客户成长自我,坚持不断学习、思考、沉淀、净化自己,让我们为更多的企业打造出实用型网站。具体代码如下
auth($token, $wxuser) || exit; if(IS_GET){ echo($_GET['echostr']); exit; }else{ $xml = file_get_contents("php://input"); $xml = new SimpleXMLElement($xml); //file_put_contents('/var/log/test.txt', $xml,FILE_APPEND); $xml || exit; foreach ($xml as $key => $value){ $this -> data[$key] = strval($value); } } } public function request(){ return $this -> data; } public function response($content, $type = 'text', $flag = 0){ $this -> data = array('ToUserName' => $this -> data['FromUserName'], 'FromUserName' => $this -> data['ToUserName'], 'CreateTime' => NOW_TIME, 'MsgType' => $type); $this -> $type($content); $this -> data['FuncFlag'] = $flag; $xml = new SimpleXMLElement(''); $this -> data2xml($xml, $this -> data); exit($xml -> asXML()); } private function text($content){ $this -> data['Content'] = $content; } private function music($music){ list($music['Title'], $music['Description'], $music['MusicUrl'], $music['HQMusicUrl']) = $music; $this -> data['Music'] = $music; } private function news($news){ $articles = array(); foreach ($news as $key => $value){ list($articles[$key]['Title'], $articles[$key]['Description'], $articles[$key]['PicUrl'], $articles[$key]['Url']) = $value; if($key >= 9){ break; } } $this -> data['ArticleCount'] = count($articles); $this -> data['Articles'] = $articles; } private function transfer_customer_service($content){ $this -> data['Content'] = ''; } private function data2xml($xml, $data, $item = 'item'){ foreach ($data as $key => $value){ is_numeric($key) && $key = $item; if(is_array($value) || is_object($value)){ $child = $xml -> addChild($key); $this -> data2xml($child, $value, $item); }else{ if(is_numeric($value)){ $child = $xml -> addChild($key, $value); }else{ $child = $xml -> addChild($key); $node = dom_import_simplexml($child); $node -> appendChild($node -> ownerDocument -> createCDATASection($value)); } } } } private function auth($token){ $signature = $_GET["signature"]; $timestamp = $_GET["timestamp"]; $nonce = $_GET["nonce"]; $tmpArr = array($token, $timestamp, $nonce); sort($tmpArr, SORT_STRING); $tmpStr = implode($tmpArr); $tmpStr = sha1($tmpStr); if(trim($tmpStr) == trim($signature)){ return true; }else{ return false; } return true; } } ?>
看完了这篇文章,相信你对“php如何实现验证token、回复图文\文本、推送消息的实用微信类”有了一定的了解,如果想了解更多相关知识,欢迎关注创新互联行业资讯频道,感谢各位的阅读!
分享题目:php如何实现验证token、回复图文\文本、推送消息的实用微信类-创新互联
当前URL:http://hbruida.cn/article/cegigd.html