网络编程 
首页 > 网络编程 > 浏览文章

验证token、回复图文\文本、推送消息的实用微信类php代码

(编辑:jimmy 日期: 2024/10/26 浏览:3 次 )

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

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

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

上一篇:浅谈PHP值mysql操作类
下一篇:php 在字符串指定位置插入新字符的简单实现
一句话新闻
微软与英特尔等合作伙伴联合定义“AI PC”:键盘需配有Copilot物理按键
几个月来,英特尔、微软、AMD和其它厂商都在共同推动“AI PC”的想法,朝着更多的AI功能迈进。在近日,英特尔在台北举行的开发者活动中,也宣布了关于AI PC加速计划、新的PC开发者计划和独立硬件供应商计划。
在此次发布会上,英特尔还发布了全新的全新的酷睿Ultra Meteor Lake NUC开发套件,以及联合微软等合作伙伴联合定义“AI PC”的定义标准。
友情链接:杰晶网络 DDR爱好者之家 南强小屋 黑松山资源网 白云城资源网 SiteMap