'%s',//文本回复XML模板
'image' => '%s',//图片回复XML模板
'music' => '%s',//音乐模板
'news' => '%s%s%s',// 新闻主体
'news_item' => ' ',//某个新闻模板
);
/**
* @微信入口
*/
public function actionIndex(){
/*if(!empty($_GET["signature"]) && !empty($_GET['echostr'])){
return $this->checkSignature();
}*/
return $this->responseMsg();
}
private function checkSignature()
{
$signature = $_GET["signature"];
$timestamp = $_GET["timestamp"];
$nonce = $_GET["nonce"];
$token = "3dxh";
$tmpArr = array($token, $timestamp, $nonce);
sort($tmpArr, SORT_STRING);
$tmpStr = implode( $tmpArr );
$tmpStr = sha1( $tmpStr );
if( $tmpStr == $signature ){
return $_GET['echostr'];
}else{
return false;
}
}
public function responseMsg(){
$xml_str = file_get_contents("php://input");
/*
获得请求时POST:XML字符串
不能用$_POST获取,因为没有key
*/
\Yii::info("进入",'wxpay');
$msg = "";
if(!empty($xml_str)){
// 解析该xml字符串,利用simpleXML
// libxml_disable_entity_loader(true);
//禁止xml实体解析,防止xml注入
$request_xml = simplexml_load_string($xml_str, 'SimpleXMLElement', LIBXML_NOCDATA);
\Yii::info($request_xml->MsgType,'wxpay');
$msg = sprintf($this->_msg_template['text'], $request_xml->ToUserName, $request_xml->FromUserName, time(), "333");
echo $msg;
exit();
//判断该消息的类型,通过元素MsgType
switch ($request_xml->MsgType){
case 'event':
//判断具体的时间类型(关注、取消、点击)
$event = $request_xml->Event;
if ($event=='subscribe') { // 关注事件
// $this->_doSubscribe($request_xml);
}elseif ($event=='CLICK') {//菜单点击事件
// $this->_doClick($request_xml);
}elseif ($event=='VIEW') {//连接跳转事件
// $this->_doView($request_xml);
}else{
}
break;
case 'text'://文本消息
// $this->_doText($request_xml);
break;
case 'image'://图片消息
// $this->_doImage($request_xml);
break;
case 'voice'://语音消息
// $this->_doVoice($request_xml);
break;
case 'video'://视频消息
// $this->_doVideo($request_xml);
break;
case 'shortvideo'://短视频消息
// $this->_doShortvideo($request_xml);
break;
case 'location'://位置消息
// $this->_doLocation($request_xml);
break;
case 'link'://链接消息
// $this->_doLink($request_xml);
break;
}
}
return $msg;
}
}