vogue.php 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. <?php
  2. /**
  3. *
  4. * 用户在微信里面授权回跳页
  5. */
  6. $param = array(
  7. 'code' =>trim( $_GET['code'] ),
  8. 'state'=>trim( $_GET['state'] ),
  9. );
  10. $referer = trim( $_GET['appreferer'] );
  11. $weixinObj = new weixinApp();
  12. $weixinObj->getWeixinParam( $param,$referer );
  13. class weixinApp {
  14. /**
  15. * 安全key
  16. * @var string
  17. */
  18. private $securityKey = 'W61E8753YZUDMG2Q0KVFH4NAOSPLIJ9CBXTR';
  19. private $login_cookie_name = 'TM_PASSPORT_MEMBER';
  20. private $host = 'http://passport.vogue.com.cn/';
  21. private $urlParm = "front/otherCallback?type=weixinapp&site=vogue";
  22. private $logName = "wechatVogueLog";
  23. public function __construct() {}
  24. /**
  25. * @desc 实例化日志类
  26. */
  27. public function logObj(){
  28. include(dirname(__FILE__) . '/log.php');
  29. $logObj = new Log();
  30. return $logObj;
  31. }
  32. /**
  33. * 获取微信code
  34. */
  35. public function getWeixinParam( $param,$referer ) {
  36. if( $param ){
  37. if( $param['state'] != $this->securityKey ){
  38. ErrorLog::addLog( "weixinapp签名不一致,ip:".$_SERVER['REMOTE_ADDR'].",state:".$param['state'], $this->logName );
  39. //$this->writeLog("weixinapp签名不一致,ip:".$_SERVER['REMOTE_ADDR'].",state:".$param['state'] );
  40. exit('1006'); //签名不一致
  41. }
  42. $url = $this->host.$this->urlParm.'&appreferer='.$referer.'&'. http_build_query( $param );
  43. $this->common_location( $url );
  44. }else{
  45. ErrorLog::addLog( "weixinapp没有参数,ip:".$_SERVER['REMOTE_ADDR'], $this->logName );
  46. //$this->writeLog("weixinapp没有参数,ip:".$_SERVER['REMOTE_ADDR'] );
  47. exit('1007'); //参数为空
  48. }
  49. }
  50. /**
  51. * @desc 在跳转到passport里面
  52. *
  53. */
  54. public function common_location( $url, $js = false )
  55. {
  56. if($js == true)
  57. {
  58. common_output('<script>location.href="'.$url.'"</script>');
  59. }
  60. else
  61. {
  62. header('Location: ' . $url);
  63. }
  64. exit;
  65. }
  66. /**
  67. * @desc 写入日志
  68. */
  69. public function writeLog( $log_message,$type='log' ){
  70. if( $log_message ){
  71. $logObj = $this->logObj();
  72. $logObj->write( $log_message,$type ); //写入日志
  73. }else{
  74. return true;
  75. }
  76. }
  77. }