123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102 |
- <?php
- /*
- |--------------------------------------------------------------------------
- | receive.php 用于接收微信发过来的信息
- |--------------------------------------------------------------------------
- */
- namespace Component\Service;
- use Dever;
- use Main\Lib\Wechat;
- class Auth
- {
- const TYPE = 5;
- /**
- * wechat
- *
- * @var Wechat
- */
- private $wechat;
-
- /**
- * result
- *
- * @var array
- */
- private $result;
-
- /**
- * output
- *
- * @var string
- */
- private $output;
-
- /**
- * 构造函数 初始化
- *
- * @return mixed
- */
- public function __construct()
- {
-
- }
-
- /**
- * 业务推送接口 微信服务器会将所有请求都推送到这里
- *
- * @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;
- $post = file_get_contents('php://input');
-
- Dever::log(time());
- if (!empty($post)) {
- $post = json_encode($post);
- Dever::log($post);
- return;
- libxml_disable_entity_loader(true);
- $result = (array) simplexml_load_string($post, 'SimpleXMLElement', LIBXML_NOCDATA);
- $this->handle($result);
- } else {
- return false;
- }
- }
- }
|