实用的微信类,用于验证token,回复图文、文本,向用户推送消息等
来源:互联网 发布:wps mac 免费完整版 编辑:程序博客网 时间:2024/06/09 06:10
<?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; }}?>
0 0
- 实用的微信类,用于验证token,回复图文、文本,向用户推送消息等
- thinkphp框架下的微信验证、关注回复图文,文本、向用户推送消息、首次登录入库或更新用户资料等
- 微信开发中signature的验证,文本消息回复,单图文消息回复,多图文消息回复
- 微信公众号验证token+关注回复+关键字回复+单图文回复
- Java模拟登录微信平台,主动推送消息给用户,自动绑定url、token等
- dwr消息推送---向指定用户推送
- dwr消息推送----向所有用户推送
- 基于PHP的微信公众平台开发(TOKEN验证,消息回复)
- Java微信公众平台开发(五)——文本及图文消息回复的实现
- iOS8推送消息的快速回复处理
- iOS8推送消息的快速回复处理
- iOS8推送消息的快速回复处理
- iOS8推送消息的快速回复处理
- iOS8推送消息的快速回复处理
- iOS8推送消息的快速回复处理
- iOS8推送消息的快速回复处理
- iOS8推送消息的快速回复处理
- iOS8推送消息的快速回复处理
- nyoj305表达式求值 栈的应用
- warning: Unsupported Configuration: Prototype table cells must have reuse identifiers
- 程序员技术练级攻略
- 深入浅出RxJava(一:基础篇)
- 用C实现mooc作业的5人评价思路
- 实用的微信类,用于验证token,回复图文、文本,向用户推送消息等
- MuleESB--HelloWorld
- C编译器剖析_5.1 中间代码生成及优化_简介
- EditPlus配置MASM5.0
- 华为在线测试题[基础篇]--删除字符串中出现次数最少的字符
- 深入浅出RxJava(二:操作符)
- SPOJ LCS Longest Common Substring 后缀自动机
- 最小乘积(基本型)
- ffmpeg中的sws_scale算法性能测试