PHP   发布时间:2019-11-12  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了验证token、回复图文\文本、推送消息的实用微信类php代码大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

本文实例为大家分享了用于验证token,回复图文、文本,向用户推送消息等功能的微信类,具体代码如下

php;"> 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;
}
}
?>

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持菜鸟教程。

大佬总结

以上是大佬教程为你收集整理的验证token、回复图文\文本、推送消息的实用微信类php代码全部内容,希望文章能够帮你解决验证token、回复图文\文本、推送消息的实用微信类php代码所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。