本文主要为大家详细介绍了php代码实现验证token、回复图文\文本、推送消息的实用微信类。感兴趣的小伙伴们可以参考一下,希望对大家有所帮助。
具体代码如下<?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