最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

驗(yàn)證token、回復(fù)圖文\文本、推送消息的實(shí)用微信類php代碼

 更新時(shí)間:2016年06月28日 10:56:28   作者:liuzp111  
這篇文章主要為大家詳細(xì)介紹了php代碼實(shí)現(xiàn)驗(yàn)證token、回復(fù)圖文\文本、推送消息的實(shí)用微信類,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

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

<?php
class 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)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評(píng)論

阳曲县| 昌黎县| 龙江县| 藁城市| 鄯善县| 甘洛县| 丰宁| 河西区| 新郑市| 新河县| 库伦旗| 乐清市| 望奎县| 青海省| 桃园县| 陆良县| 浦北县| 湘阴县| 信丰县| 晋城| 北碚区| 富宁县| 南通市| 宁海县| 青海省| 黄梅县| 丰镇市| 广丰县| 荃湾区| 马鞍山市| 安平县| 嫩江县| 综艺| 漳平市| 盱眙县| 眉山市| 夏邑县| 辽阳县| 图们市| 淮滨县| 鞍山市|