php如何实现验证token、回复图文\文本、推送消息的实用微信类
发表于:2025-02-23 作者:千家信息网编辑
千家信息网最后更新 2025年02月23日,小编给大家分享一下php如何实现验证token、回复图文\文本、推送消息的实用微信类,希望大家阅读完这篇文章之后都有所收获,下面让我们一起去探讨吧!具体代码如下
千家信息网最后更新 2025年02月23日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、回复图文\文本、推送消息的实用微信类"有了一定的了解,如果想了解更多相关知识,欢迎关注行业资讯频道,感谢各位的阅读!
实用
图文
文本
消息
推送
验证
篇文章
代码
完了
更多
知识
行业
资讯
资讯频道
频道
数据库的安全要保护哪些东西
数据库安全各自的含义是什么
生产安全数据库录入
数据库的安全性及管理
数据库安全策略包含哪些
海淀数据库安全审计系统
建立农村房屋安全信息数据库
易用的数据库客户端支持安全管理
连接数据库失败ssl安全错误
数据库的锁怎样保障安全
数据库工程师实习报告
网络安全五问三讲一讨论原则
广东网站服务器厂家直供
服务器内存排行
在麦当劳做软件开发
静安区智能化软件开发咨询热线
金融科技或互联网融资模式
数据库系统原理及应用第5版答案
腾讯网络安全保卫局
遂宁软件开发操作
业务系统网络安全测试
杭州数据库培训哪里好
网络安全六大看点资料
服务器连接失败怎么办
数据库两张表合并到一个表格
分布式网络安全大脑
两个实例是两个服务器吗
石家庄网络安全技术专业就业
探针接入网络安全监测装置
上海科技互联网公司
初中网络安全读后感
专科学软件开发有用吗
360网络安全专业分析
智唐科技和互联网
网络安全法禁止渗透入侵
在麦当劳做软件开发
呼和浩特软件开发公司
查询成绩最高前五名数据库
数据库两张表合并到一个表格
sql如何显示数据库前三条记录