国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 語言 > PHP > 正文

驗證token、回復(fù)圖文/文本、推送消息的實用微信類php代碼

2024-05-04 23:47:29
字體:
供稿:網(wǎng)友

本文實例為大家分享了用于驗證token,回復(fù)圖文、文本,向用戶推送消息等功能的微信類,具體代碼如下

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

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持VeVb武林網(wǎng)。


注:相關(guān)教程知識閱讀請移步到PHP教程頻道。
發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表

圖片精選

主站蜘蛛池模板: 汉寿县| 故城县| 大荔县| 玛纳斯县| 全南县| 泌阳县| 霍州市| 禹城市| 广宁县| 丰原市| 都昌县| 横峰县| 乌拉特后旗| 山丹县| 奎屯市| 洛隆县| 东明县| 怀仁县| 龙里县| 乌拉特中旗| 佛冈县| 吴忠市| 庐江县| 玛曲县| 逊克县| 常宁市| 水城县| 甘泉县| 巴南区| 桃源县| 汝州市| 宁阳县| 如东县| 察哈| 岳西县| 苗栗市| 禄劝| 海口市| 平昌县| 阆中市| 高阳县|