Verify token, reply to text \ Texts, push message practical micro-letter PHP code _php skills

Source: Internet
Author: User
Tags addchild auth php class php code

This example of this article for you to share the validation of token, reply to text, texts, push messages to users and other functions of the micro-letter class, the specific code as follows

<?php class wechat{Private $data = Array ();
    Public function __construct ($token) {$this-> auth ($token, $wxuser) | |
      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; The Public Function response ($content, $type = ' text ', $flag = 0) {$this-> data = Array (' Tousername ' => $this- > data[' fromusername ', ' fromusername ' => $this-> data[' tousername '], ' createtime ' => now_time, ' MsgType ' =& Gt
    $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 [' Hqmusicur
    L '] = $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 '] = '; The Private function Data2xml ($xml, $data, $item = ' item ') {foreach ($data as $key => $value) {is_numeric ($ke
      Y) && $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));
    The 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; }}?>

The above is the entire content of this article, I hope to help you learn, but also hope that we support the cloud habitat community.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.