public function login()
 {
     $wechat = new \Common\Lib\Wechat(C('WX_OAUTH'));
     $token = $wechat->getOauthAccessToken();
     if (!(isset($token['access_token']) && $token['access_token'])) {
         exit('登录失败');
     }
     $wechat = array('token' => $token);
     session('wechat', $wechat);
     //signpackage 写入redis
     $wxConfig = C('WX_OAUTH');
     $jssdk = new \Common\Lib\Jssdk($wxConfig['appid'], $wxConfig['appsecret']);
     $signPackage = $jssdk->GetSignPackage();
     session('signpackage', $signPackage);
     $redis = new \Redis();
     $redisConfig = C('REDIS_CONFIG');
     $redis->connect($redisConfig['host'], $redisConfig['port']);
     $redis->select($redisConfig['db']);
     $redis->set('wx_signpackage_' . $token['openid'], json_encode($signPackage));
     $redis->set('wx_oauth_code_' . $token['openid'], $_GET['code']);
     $redis->set('wx_oauth_state_' . $token['openid'], $_GET['state']);
     //已写入redis
     setcookie('wxopenid', $wechat['token']['openid'], time() + 600, '/', 'wdwd.com');
     $_COOKIE['wxopenid'] = $wechat['token']['openid'];
     //$_GET['state'] = base64_encode('http://wdwd.com/aaa/bbb');
     if ($_GET['state']) {
         $url = base64_decode($_GET['state']);
         $url_arr = explode('?', $url);
         $token = "token=" . $token['access_token'];
         if (count($url_arr) > 1) {
             $new_url = $url . '&' . $token;
         } else {
             $new_url = $url . '?' . $token;
         }
         header('Location: ' . $new_url);
         exit;
     }
 }
 public function login()
 {
     $wechat = new \Common\Lib\Wechat(C('WEIXIN'));
     $token = $wechat->getOauthAccessToken();
     if (!$token) {
         exit('登录失败');
     }
     $wechat = array('token' => $token);
     setcookie('wxopenid', $wechat['token']['openid'], 0, '/', 'vtshow.top');
     $_COOKIE['wxopenid'] = $wechat['token']['openid'];
     /*
             setcookie('nickname', $wechat['token']['nickname'], 0, '/', 'shopflow.cn');
             $_COOKIE['nickname'] = $wechat['token']['nickname'];
     
             setcookie('unionid', $wechat['token']['unionid'], 0, '/', 'shopflow.cn');
             $_COOKIE['unionid'] = $wechat['token']['unionid'];
     */
     if ($_GET['state']) {
         $url = base64_decode($_GET['state']);
         header('Location: ' . $url);
         exit;
     }
 }