时间:2021-05-25
本文实例为大家分享了用于验证token,回复图文、文本,向用户推送消息等功能的微信类,具体代码如下
<?phpclass Wechat{ private $data = array(); public function __construct($token){ $this -> 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('<xml></xml>'); $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; }}?>以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。
声明:本页内容来源网络,仅供用户参考;我单位不保证亦不表示资料全面及准确无误,也不保证亦不表示这些资料为最新信息,如因任何原因,本网内容或者用户因倚赖本网内容造成任何损失或损害,我单位将不会负任何法律责任。如涉及版权问题,请提交至online#300.cn邮箱联系删除。
微信开发前,需要设置token,这个是微信设置的,可以任意设置,用来实现微信通讯。这里有一个别人写的微信类,功能还比较不错。weixin.class.php代码
本文实例为大家分享了ASP.NET微信粉丝信息接口查看代码,供大家参考,具体内容如下微信Token实体类://////微信Token实体类///publiccl
本文实例讲述了php微信公众平台开发类。分享给大家供大家参考。具体分析如下:ThinkWechat.php类文件如下:auth($token)||exit;if
微信小程序消息推送php服务器验证实例详解微信文档(靠下有个“接入指引”):https://mp.weixin.qq.com/debug/wxadoc/dev/
微信公众号开发之回复图文消息,供大家参考,具体内容如下图文消息的主要参数说明通过微信官方的消息接口指南,可以看到对图文消息的参数介绍,如下图所示:从上图可以了解