コード例 #1
0
ファイル: bind.php プロジェクト: zxw5775/yuhunclub
 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
ファイル: oauth.php プロジェクト: zxw5775/yuhunclub
 function callback($ctx)
 {
     $jump = htmlspecialchars(trim($_GET['jump']));
     self::validate_url($jump);
     if (!$this->appid || !$this->secret) {
         _redirect($jump);
     }
     $code = urlencode(htmlspecialchars(trim($_GET['code'])));
     if (!$code) {
         _redirect($jump);
     }
     $wx_url = 'https://api.weixin.qq.com/sns/oauth2/access_token';
     $wx_url = "{$wx_url}?appid={$this->appid}&secret={$this->secret}&code={$code}&grant_type=authorization_code";
     $resp = Http::get($wx_url);
     $ret = @json_decode($resp, true);
     if (is_array($ret) && $ret['openid']) {
         $connect = WxConnect::get_by('wx_openid', $ret['openid']);
         if ($connect) {
             Logger::info("wx_openid[{$ret['openid']}] oauth login, uid: {$connect->user_id}");
             $profile = Profile::get($connect->user_id);
             if ($profile && $profile->status != Profile::STATUS_LOCK) {
                 UC::force_login($profile);
             }
         } else {
             // 兼容 /weixin/bind, 因为它依赖 session 中的 openid, 所以这里设置
             session_start();
             $_SESSION['wx_openid'] = $ret['openid'];
         }
     } else {
         Logger::info("weixin oauth, code: {$code}, resp: {$resp}, " . Http::$error);
     }
     _redirect($jump);
 }
コード例 #3
0
ファイル: WxConnect.php プロジェクト: zxw5775/yuhunclub
 static function bind($uid, $wx_openid)
 {
     if (!$uid || !$wx_openid) {
         return;
     }
     $wx_user_connect = WxConnect::get_by('user_id', $uid);
     if ($wx_user_connect) {
         return;
     }
     $connect = WxConnect::get_by('wx_openid', $wx_openid);
     if ($connect) {
         return;
     }
     $attrs = array('time' => date('Y-m-d H:i:s'), 'user_id' => $uid, 'wx_openid' => $wx_openid, 'prj_subscribe' => WxConnect::PRJ_SUBSCRIBED, 'wx_subscribe' => WxConnect::WX_SUBSCRIBED);
     WxConnect::save($attrs);
     Logger::info("自动绑定微信账号成功 uid : {$uid} openid : {$wx_openid}");
     return true;
 }
コード例 #4
0
ファイル: jump.php プロジェクト: zxw5775/yuhunclub
 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);
 }
コード例 #5
0
ファイル: msg.php プロジェクト: zxw5775/yuhunclub
 private function projects_unsubscribe($xml)
 {
     $from = $xml->FromUserName;
     $to = $xml->ToUserName;
     if (!$this->bind_check($xml)) {
         return;
     }
     $uid = $this->user_profile->id;
     $connect = WxConnect::get_by('wx_openid', $from);
     if ($connect->prj_subscribe !== WxConnect::PRJ_UNSUBSCRIBED) {
         try {
             $connect->update(array('prj_subscribe' => WxConnect::PRJ_UNSUBSCRIBED));
             $this->wx_reply->imm_reply_text($to, $from, '您已经成功退订新项目通知,如需再次订阅可点击【我的账户-订阅项目通知】。');
         } catch (Exception $e) {
             $this->wx_reply->imm_reply_text($to, $from, '抱歉,退订出错,请稍后重试。');
         }
     } else {
         $this->wx_reply->imm_reply_text($to, $from, '您已经成功退订新项目通知,如需再次订阅可点击【我的账户-订阅项目通知】。');
     }
 }