function view($ctx) { App::set_base_url('https://axelahome.com/'); $id = intval($_GET['id']); $this->wx_account = WxAccount::get($id); if (!$this->wx_account) { return; } $this->wx_reply = new WxReply($this->wx_account); if ($_GET["echostr"]) { return $this->validate_wx($ctx); } if (!$this->check_sign()) { return; } // TEST if (ENV == 'dev') { if ($_GET['debug']) { $_s = "<xml>\n <ToUserName><![CDATA[{$this->wx_account->wx_id}]]></ToUserName>\n <FromUserName><![CDATA[{$_GET['user']}]]></FromUserName>\n <CreateTime>1348831860</CreateTime>\n <MsgType><![CDATA[text]]></MsgType>\n <Content><![CDATA[{$_GET['text']}]]></Content>\n <MsgId>1234567890123456</MsgId>\n </xml>"; $GLOBALS["HTTP_RAW_POST_DATA"] = $_s; } elseif ($_GET['content']) { $c = $_GET['content']; $GLOBALS["HTTP_RAW_POST_DATA"] = "<xml><ToUserName>{$this->wx_account->wx_id}</ToUserName><MsgType>text</MsgType><Content>{$c}</Content></xml>"; } } $str = $GLOBALS["HTTP_RAW_POST_DATA"]; Logger::debug("recv: " . $str); $xml = Text::xml_to_obj($str); if (!$xml) { Logger::error("bad data from weixin: {$str}"); return; } if ($xml->MsgType == 'event' && $xml->Event == 'TEMPLATESENDJOBFINISH') { return; } if ($xml->MsgType == 'event' && $xml->Event == 'unsubscribe') { return; } // 首先, 进行程序回复 if ($id == 1) { if ($this->route($xml) === true) { return; } } // 其次, 尝试自动回复 if ($this->wx_reply->auto_reply($xml) === true) { return; } $this->default_reply($xml); }
function view($ctx) { App::set_base_url('https://axelahome.com/'); $id = intval($_GET['id']); $this->wx_account = WxQiyeAccount::get($id); if (!$this->wx_account) { return; } $this->wx_cpt_utl = new WxQiyeUtil($this->wx_account); $msg_signature = isset($_GET['msg_signature']) ? $_GET['msg_signature'] : ''; $timestamp = isset($_GET['timestamp']) ? $_GET['timestamp'] : ''; $nonce = isset($_GET['nonce']) ? $_GET['nonce'] : ''; $this->wx_cpt_utl->init_meta_params($msg_signature, $timestamp, $nonce); /* 如果是验证url */ if (isset($_GET["echostr"]) && $_GET["echostr"]) { echo $this->wx_cpt_utl->validate_url(trim($_GET['echostr'])); return; } /* 验证url结束 */ /* 下面是加密解密消息体的逻辑 兼容dev环境 */ $str = $GLOBALS["HTTP_RAW_POST_DATA"]; // 接收到的原生POST数据 $msg = ''; // 解析后的明文 Logger::debug("weixin qiye recv: " . $str); /* 验证消息 */ if (ENV == 'dev' && isset($_GET['debug'])) { // dev模式下 hook $msg = "\n\t\t\t\t<xml>\n\t\t\t\t<ToUserName><![CDATA[{$this->wx_account->corp_id}]]></ToUserName>\n\t\t\t\t<FromUserName><![CDATA[{$_GET['user']}]]></FromUserName>\n\t\t\t\t<CreateTime>1451968899</CreateTime>\n\t\t\t\t<MsgType><![CDATA[text]]></MsgType>\n\t\t\t\t<Content><![CDATA[{$_GET['text']}]]></Content>\n\t\t\t\t<MsgId>4368083058310512650</MsgId>\n\t\t\t\t<AgentID>{$this->wx_account->agent_id}</AgentID>\n\t\t\t\t</xml>\n\t\t\t"; } else { $msg = $this->wx_cpt_utl->decrypt($str); } if (!$msg) { return; } $xml = Text::xml_to_obj($msg); if (!$xml) { Logger::error("bad data from weixin qiye : {$str}"); return; } if ($xml->AgentID != $this->wx_account->agent_id) { Logger::error("推送的agent_id与配置的agent_id不一致 来自微信的 {$xml->AgentID} ;配置的agent_id {$this->wx_account->agent_id}"); } // 模板消息 直接忽略 if ($xml->MsgType == 'event' && $xml->Event == 'TEMPLATESENDJOBFINISH') { return; } // 初始化xml $this->wx_cpt_utl->init_xml($xml); // 根据应用(agent_id)进行回复 $agent_id = intval($xml->AgentID); $text = ''; switch ($agent_id) { case WxQiyeUtil::AGENT_ID_axelahome_DATA_CENTER: // 懒投资数据中心的应用 $text = $this->do_lantozui_data_center($xml); break; default: return; } $text = trim($text); if (!$text) { return; } // 回复一个文本消息 $this->wx_cpt_utl->reply_text($text); }