初始化代码
This commit is contained in:
81
application/api/wxapi/wxmsg/BaseObject.php
Normal file
81
application/api/wxapi/wxmsg/BaseObject.php
Normal file
@@ -0,0 +1,81 @@
|
||||
<?php
|
||||
namespace app\api\wxapi\wxmsg;
|
||||
|
||||
|
||||
use app\api\wxapi\Base;
|
||||
use think\Db;
|
||||
|
||||
class BaseObject extends Base{
|
||||
|
||||
public $token; //响应接收消息URL Token
|
||||
|
||||
public function run(){
|
||||
$resq=$this->xmlToArray(file_get_contents("php://input"));
|
||||
/*$xml='<xml><ToUserName><![CDATA[gh_9f61b83af9e8]]></ToUserName>
|
||||
<FromUserName><![CDATA[oDXoW66sZbQwyYA2Rzpqd_ZA7cyI]]></FromUserName>
|
||||
<CreateTime>1605773759</CreateTime>
|
||||
<MsgType><![CDATA[event]]></MsgType>
|
||||
<Event><![CDATA[subscribe]]></Event>
|
||||
<EventKey><![CDATA[]]></EventKey>
|
||||
</xml>';
|
||||
$resq=json_decode(json_encode(simplexml_load_string($xml, 'SimpleXMLElement', LIBXML_NOCDATA)), true);*/
|
||||
foreach($resq as $key=>$val){
|
||||
$this->$key=$val;
|
||||
}
|
||||
|
||||
/*$TempDataLog=[];
|
||||
$TempDataLog['event'] = $resq['Event'];
|
||||
$TempDataLog['contents'] = json_encode($resq);
|
||||
$TempDataLog['addtime'] = time();
|
||||
Db::name('wx_temp_log')->insertGetId($TempDataLog);*/
|
||||
|
||||
//error_log(json_encode($resq), 3, 'sub.log');
|
||||
return true;
|
||||
}
|
||||
|
||||
public function CheckSignature(){
|
||||
$sign=$_GET;
|
||||
$arr['token']=$this->token;
|
||||
$arr['timestamp']=$sign['timestamp'];
|
||||
$arr['nonce']=$sign['nonce'];
|
||||
asort($arr);
|
||||
$sha1=sha1(implode('',$arr));
|
||||
if($sha1==$sign['signature']){
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public function xmlToArray($xml)
|
||||
{
|
||||
//error_log($xml, 3, 'xml.log');
|
||||
//将XML转为array
|
||||
$array_data = json_decode(json_encode(simplexml_load_string($xml, 'SimpleXMLElement', LIBXML_NOCDATA)), true);
|
||||
return $array_data;
|
||||
}
|
||||
|
||||
public function ArrayToXml($arr){
|
||||
$xml='<?xml version="1.0" encoding="UTF-8"?>';
|
||||
$xml='<xml>';
|
||||
$this->ToXml($arr,$xml);
|
||||
$xml.='</xml>';
|
||||
return $xml;
|
||||
}
|
||||
|
||||
public function ToXml($data,&$xml){
|
||||
foreach($data as $k=>$v){
|
||||
if(is_array($v)){
|
||||
$xml.=' <'.$k.'>';
|
||||
$this->ToXml($v, $xml);
|
||||
$xml.=' </'.$k.'>';
|
||||
}else{
|
||||
if(is_int($v)){
|
||||
$xml.=' <'.$k.'>'.$v.'</'.$k.'>';
|
||||
}else{
|
||||
$xml.=' <'.$k.'><![CDATA['.$v.']]></'.$k.'>';
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user