wxauthor.php 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: stanley-king
  5. * Date: 2017/4/26
  6. * Time: 下午2:46
  7. */
  8. require_once (BASE_ROOT_PATH . '/helper/third_author/wxauthor.php');
  9. require_once (BASE_ROOT_PATH . '/helper/session.php');
  10. ini_set('date.timezone','Asia/Shanghai');
  11. error_reporting(E_ERROR);
  12. $code = $_GET['code'];
  13. $state = $_GET['state'];
  14. Log::record("state:{$state} originurl=" . wechat_helper::get_origin_url(),Log::DEBUG);
  15. if(empty($code)) {
  16. Log::record("没有同意授权");
  17. }
  18. else
  19. {
  20. if(wechat_helper::has_origin_url())
  21. {
  22. $author = new \thrid_author\wxauthor();
  23. $user_info = $author->callback($code);
  24. if(empty($user_info)) {
  25. Log::record("微信取到的信息为空",Log::DEBUG);
  26. }
  27. else
  28. {
  29. wechat_helper::set_userinfo($user_info);
  30. $origin_url = wechat_helper::get_origin_url();
  31. wechat_helper::clear_origin_url();
  32. Log::record("origin_url={$origin_url}",Log::DEBUG);
  33. if(!empty($origin_url))
  34. {
  35. $html = "<!DOCTYPE html>
  36. <html lang=\"en\">
  37. <head>
  38. <meta charset=\"UTF-8\">
  39. <meta http-equiv=\"Cache-Control\" content=\"no-cache, no-store, must-revalidate\" />
  40. <meta http-equiv=\"Pragma\" content=\"no-cache\" />
  41. <meta http-equiv=\"Expires\" content=\"0\" />
  42. <title>跳转中</title>
  43. </head>
  44. <body>
  45. <script>
  46. window.location.replace(\"{$origin_url}\");
  47. </script>
  48. </body>
  49. </html>";
  50. echo $html;
  51. }
  52. }
  53. }
  54. else
  55. {
  56. $host = urldecode($state);
  57. $url = "{$host}/mobile/wxauthor.php?code={$code}";
  58. Log::record("redirect url={$url}",Log::DEBUG);
  59. $html = "<!DOCTYPE html>
  60. <html lang=\"en\">
  61. <head>
  62. <meta charset=\"UTF-8\">
  63. <meta http-equiv=\"Cache-Control\" content=\"no-cache, no-store, must-revalidate\" />
  64. <meta http-equiv=\"Pragma\" content=\"no-cache\" />
  65. <meta http-equiv=\"Expires\" content=\"0\" />
  66. <title>跳转中</title>
  67. </head>
  68. <body>
  69. <script>
  70. window.location.replace(\"{$url}\");
  71. </script>
  72. </body>
  73. </html>";
  74. echo $html;
  75. }
  76. }