Auth.php 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. <?php
  2. /*
  3. |--------------------------------------------------------------------------
  4. | receive.php 用于接收微信发过来的信息
  5. |--------------------------------------------------------------------------
  6. */
  7. namespace Component\Service;
  8. use Dever;
  9. use Main\Lib\Wechat;
  10. class Auth
  11. {
  12. const TYPE = 5;
  13. /**
  14. * wechat
  15. *
  16. * @var Wechat
  17. */
  18. private $wechat;
  19. /**
  20. * result
  21. *
  22. * @var array
  23. */
  24. private $result;
  25. /**
  26. * output
  27. *
  28. * @var string
  29. */
  30. private $output;
  31. /**
  32. * 构造函数 初始化
  33. *
  34. * @return mixed
  35. */
  36. public function __construct()
  37. {
  38. }
  39. /**
  40. * 业务推送接口 微信服务器会将所有请求都推送到这里
  41. *
  42. * @return mixed
  43. */
  44. public function main()
  45. {
  46. $this->output = '';
  47. # 获取微信消息
  48. $this->request();
  49. # 对消息进行验证,并根据类型得到本平台的配置数据
  50. //$this->response();
  51. # 输出
  52. $this->output();
  53. }
  54. /**
  55. * 输出
  56. *
  57. * @return mixed
  58. */
  59. private function output()
  60. {
  61. if (!$this->output) {
  62. $this->output = 'success';
  63. }
  64. echo $this->output;die;
  65. }
  66. /**
  67. * 获取微信发送的内容
  68. *
  69. * @return mixed
  70. */
  71. private function request()
  72. {
  73. //$post = $_GET ? $_GET : $_POST;
  74. $post = file_get_contents('php://input');
  75. Dever::log(time());
  76. if (!empty($post)) {
  77. $post = json_encode($post);
  78. Dever::log($post);
  79. return;
  80. libxml_disable_entity_loader(true);
  81. $result = (array) simplexml_load_string($post, 'SimpleXMLElement', LIBXML_NOCDATA);
  82. $this->handle($result);
  83. } else {
  84. return false;
  85. }
  86. }
  87. }