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.