wxauthor.php 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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. elseif(wechat_helper::has_origin_url())
  19. {
  20. $author = new thrid_author\wxauthor();
  21. $user_info = $author->callback($code);
  22. if(empty($user_info)) {
  23. Log::record("微信取到的信息为空",Log::DEBUG);
  24. }
  25. else
  26. {
  27. wechat_helper::set_userinfo($user_info);
  28. $origin_url = wechat_helper::get_origin_url();
  29. wechat_helper::clear_origin_url();
  30. Log::record("origin_url={$origin_url}",Log::DEBUG);
  31. if(!empty($origin_url))
  32. {
  33. $html = "<!DOCTYPE html>
  34. <html lang=\"en\">
  35. <head>
  36. <meta charset=\"UTF-8\">
  37. <meta http-equiv=\"Cache-Control\" content=\"no-cache, no-store, must-revalidate\" />
  38. <meta http-equiv=\"Pragma\" content=\"no-cache\" />
  39. <meta http-equiv=\"Expires\" content=\"0\" />
  40. <title>跳转中</title>
  41. </head>
  42. <body>
  43. <script>
  44. window.location.replace(\"{$origin_url}\");
  45. </script>
  46. </body>
  47. </html>";
  48. echo $html;
  49. }
  50. }
  51. }
  52. else
  53. {
  54. $host = urldecode($state);
  55. $url = "{$host}/mobile/wxauthor.php?code={$code}";
  56. Log::record("redirect url={$url}",Log::DEBUG);
  57. $html = "<!DOCTYPE html>
  58. <html lang=\"en\">
  59. <head>
  60. <meta charset=\"UTF-8\">
  61. <meta http-equiv=\"Cache-Control\" content=\"no-cache, no-store, must-revalidate\" />
  62. <meta http-equiv=\"Pragma\" content=\"no-cache\" />
  63. <meta http-equiv=\"Expires\" content=\"0\" />
  64. <title>跳转中</title>
  65. </head>
  66. <body>
  67. <script>
  68. window.location.replace(\"{$url}\");
  69. </script>
  70. </body>
  71. </html>";
  72. echo $html;
  73. }