wechat = new Wechat(self::TYPE); } /** * 获取component token 一般为系统token * * @return mixed */ public function token_api() { return $this->wechat->token(); } /** * 获取预授权码 开始用户授权 * * @return mixed */ public function test_api() { $link = $this->wechat->login('component/auth.oauth', false, false); echo '第三方平台授权';die; } /** * 获取预授权码 开始用户授权 * * @return mixed */ public function get_api() { $this->wechat->login('component/auth.oauth'); } /** * 获取oauth的token 用户token * * @return mixed */ public function oauth_api() { $this->wechat->oauth(); } /** * 业务推送接口 微信服务器会将所有请求都推送到这里 * * @return mixed */ public function main() { $this->output = ''; # 获取微信消息 $this->request(); # 对消息进行验证,并根据类型得到本平台的配置数据 //$this->response(); # 输出 $this->output(); } /** * 输出 * * @return mixed */ private function output() { if (!$this->output) { $this->output = 'success'; } echo $this->output;die; } /** * 获取微信发送的内容 * * @return mixed */ private function request() { //$post = $_GET ? $_GET : $_POST; $data = array(); $data['signature'] = '432ec06aa3a0f680924c9587ea215b4e490382b3'; $data['timestamp'] = '1525677152'; $data['nonce'] = '377902872'; $data['encrypt_type'] = 'aes'; $data['msg_signature'] = '7f62174a1402d955c2d8e61f69a309540714c579'; $xml = file_get_contents('php://input'); Dever::log(json_encode($_GET) . $xml); $xml = " "; if (!empty($xml)) { libxml_disable_entity_loader(true); $result = (array) simplexml_load_string($xml, 'SimpleXMLElement', LIBXML_NOCDATA); $result = $this->wechat->decode($data['msg_signature'], $data['timestamp'], $data['nonce'], $result['Encrypt']); if (isset($result['ComponentVerifyTicket'])) { $this->wechat->ticket($result['ComponentVerifyTicket'], 600, 100); } return true; } else { return false; } } }