示例#1
0
 function index($ctx)
 {
     $ctx->title = '绑定微信账号';
     setcookie('no_subscribe_prj', '', time() + 3600);
     $user = UC::auth();
     if ($user) {
         $connect = WxConnect::get_by('user_id', $user['id']);
         if ($connect) {
             _redirect('/');
         }
     }
     if (!$this->openid) {
         if (!$_GET['redirect']) {
             // 避免循环跳转
             UC::logout();
             // 使用域名 axelahome.com, 避免因为跨域导致 session 获取不到问题
             $jump = _url('https://axelahome.com/weixin/bind', array('redirect' => 1));
             $url = _url('https://axelahome.com/weixin/oauth', array('jump' => $jump));
             _redirect($url);
         }
         _throw("链接已经过期, 请重新获取微信消息!", 200);
     } else {
         $connect = WxConnect::get_by('wx_openid', $this->openid);
         if ($connect) {
             _throw('此微信号已经绑定过懒投资账号, 请先解绑!');
         }
     }
 }
示例#2
0
 function index($ctx)
 {
     $jump = htmlspecialchars(trim($_GET['jump']));
     $host = Html::host();
     if (!preg_match("/http(s)?:\\/\\/[^\\/]*{$host}\\//", $jump)) {
         $jump = '';
     }
     // 验证 token
     $token = htmlspecialchars(trim($_GET['token']));
     if (strlen($token) == 32) {
         $sess = WxTmpLogin::get_session($token);
         if ($sess) {
             WxTmpLogin::del_session($token);
         }
     }
     if (!$sess) {
         #if($token && !$_SESSION['wx_openid']){
         #	_throw("链接已经过期, 请重新获取微信消息!", 200);
         #}
         _redirect($jump);
     }
     session_start();
     $_SESSION['wx_openid'] = $sess['openid'];
     $connect = WxConnect::get_by('wx_openid', $sess['openid']);
     if (!$connect) {
         setcookie(WxTmpLogin::COOKIE_KEY_AUTO_BIND_WX, 1, time() + 3600 * 24, '/');
         Logger::info("not connected wx_openid: {$sess['openid']}");
         UC::logout();
     } else {
         $uid = $connect->user_id;
         $profile = Profile::get($uid);
         setcookie('ltz_wx_binded', 1, time() + 3600 * 24 * 365, "/");
         // 已经绑定了,直接删除该cookie
         if (isset($_COOKIE[WxTmpLogin::COOKIE_KEY_AUTO_BIND_WX])) {
             setcookie(WxTmpLogin::COOKIE_KEY_AUTO_BIND_WX, '', time() - 1, '/');
         }
         Logger::info("wx_openid[{$sess['openid']}] login, uid: {$uid}, {$profile->name}");
         UC::force_login($profile);
     }
     _redirect($jump);
 }