/** * 接受微信非验证信息 * 首先根据msg type 进行判定,分为Event类型和非event类型 * Event类型交给WeixinEventModel处理,非event类型循环map */ public function doReceive() { $this->weixin->getRev(); $msg_type = $this->weixin->getRevType(); $data = $this->weixin->getRevData(); PLog::write('----Data----:' . print_r($data, true), Log::INFO); if ($msg_type == 'event') { //事件操作 $event = $this->weixin->getRevEvent(); PLog::write('----Event----:' . print_r($event, true), Log::INFO); $event['event'] = strtolower($event['event']); $res = D("WeixinEvent")->getWeixinRes($event, $data); } else { //用户输入 foreach ($this->operation_map as $method_class) { $class = $method_class[0]; $method = $method_class[1]; PLog::write('----Involve----:' . $class . "->" . $method . "()", Log::INFO); $res = D($class)->{$method}($data); if ($res) { break; } } } if ($res) { if (!$res) { $res = array("type" => "text", "data" => ""); } $this->set_res($res); $this->weixin->reply(); PLog::write('----Reply----:' . print_r($res, true), Log::INFO); PLog::write('-----------------------------', Log::INFO); } }
function index() { $is_active_open = C("custom_weixin_active_open"); if ($is_active_open) { PLog::write('Receive Validation Msg :' . print_r($_GET, true), Log::INFO); $result = D("Weixin")->valid(); } else { PLog::write('Result is :' . $result, Log::INFO); // var_dump(D("Weixin")); D("Weixin")->doReceive(); } }