php微信公众平台开发类实例
发布时间:2020-12-12 20:48:46 所属栏目:PHP教程 来源:网络整理
导读:本篇章节讲解php微信公众平台开发类。供大家参考研究。具体分析如下: ThinkWechat.php类文件如下: auth($token) || exit; if(!empty($_GET['echostr'])){ exit($_GET['echostr']); } else { try { $xml = file_get_contents("php://input"); $xml
本篇章节讲解php微信公众平台开发类。分享给大家供大家参考。具体分析如下: ThinkWechat.php类文件如下: auth($token) || exit;
if(!empty($_GET['echostr'])){
exit($_GET['echostr']);
} else {
try
{
$xml = file_get_contents("php://input");
$xml = new SimpleXMLElement($xml);
$xml || exit;
foreach ($xml as $key => $value) {
$this->data[$key] = strval($value);
}
}catch(Exception $e){
}
}
}
/**
* 获取微信推送的数据
* @return array 转换为数组后的数据
*/
public function request(){
return $this->data;
}
/**
* * 响应微信发送的信息(自动回复)
* @param string $to 接收用户名
* @param string $from 发送者用户名
* @param array $content 回复信息,文本信息为string类型
* @param string $type 消息类型
* @param string $flag 是否新标刚接受到的信息
* @return string XML字符串
*/
public function response($content,$type = 'text',$flag = 0){
/* 基础数据 */
$this->data = array(
'ToUserName' => $this->data['FromUserName'],'FromUserName' => $this->data['ToUserName'],'CreateTime' => time(),'MsgType' => $type,);
/* 添加类型数据 */
$this->$type($content);
/* 添加状态 */
$this->data['FuncFlag'] = $flag;
/* 转换数据为XML */
$xml = new SimpleXMLElement('
希望本文所述对大家的php程序设计有所帮助。 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |