Example #1
0
 public function redirect_action()
 {
     if (!in_weixin() or get_setting('weixin_account_role') != 'service') {
         //HTTP::redirect(base64_decode($_GET['redirect']));
     }
     if ($_GET['code'] and get_setting('weixin_app_id') and get_setting('weixin_app_secret')) {
         if (!$_GET['thirdlogin'] || !$_GET['state']) {
             H::redirect_msg('授权失败: Redirect 微信三方登录发起的来源ID错误, Code: ' . htmlspecialchars($_GET['code']));
         }
         $thirdlogin = $_GET['thirdlogin'];
         $third_info = $this->model('openid_weixin_thirdlogin')->get_third_party_login_by_name($thirdlogin);
         if (!$third_info || $_GET['state'] != $third_info['token']) {
             H::redirect_msg('授权失败: Redirect 微信三方登录发起的来源ID错误, Code: ' . htmlspecialchars($_GET['code']));
         }
         if ($access_token = $this->model('openid_weixin_weixin')->get_sns_access_token_by_authorization_code($_GET['code'])) {
             if ($access_token['errcode']) {
                 H::redirect_msg('授权失败: Redirect ' . $access_token['errcode'] . ' ' . $access_token['errmsg'] . ', Code: ' . htmlspecialchars($_GET['code']));
             }
             if ($weixin_user = $this->model('openid_weixin_weixin')->get_user_info_by_openid($access_token['openid'])) {
                 //已有用户
                 $user_info = $this->model('account')->get_user_info_by_uid($weixin_user['uid']);
                 HTTP::set_cookie('_user_login', get_login_cookie_hash($user_info['user_name'], $user_info['password'], $user_info['salt'], $user_info['uid'], false));
             } else {
                 $access_user = $this->model('openid_weixin_weixin')->get_user_info_by_oauth_openid($access_token['access_token'], $access_token['openid']);
                 if ($access_user) {
                     if ($user_info = $this->model('openid_weixin_weixin')->weixin_auto_register($access_token, $access_user)) {
                         HTTP::set_cookie('_user_login', get_login_cookie_hash($user_info['user_name'], $user_info['password'], $user_info['salt'], $user_info['uid'], false));
                     } else {
                         H::redirect_msg('用户注册失效,请重试!, State: ' . htmlspecialchars($_GET['state']) . ', Code: ' . htmlspecialchars($_GET['code']));
                     }
                 } else {
                     H::redirect_msg('远程服务器忙,请稍后再试, State: ' . htmlspecialchars($_GET['state']) . ', Code: ' . htmlspecialchars($_GET['code']));
                 }
             }
             $callback_url = $third_info['url'];
             $query = array();
             $query['state'] = $third_info['token'];
             $query['openid'] = $access_token['openid'];
             $query['name'] = $third_info['name'];
             $callback_url = $callback_url . '?' . http_build_query($query);
             H::redirect_msg('授权成功,正在跳转...', $callback_url);
         } else {
             H::redirect_msg('远程服务器忙,请稍后再试, State: ' . htmlspecialchars($_GET['state']) . ', Code: ' . htmlspecialchars($_GET['code']));
         }
     } else {
         H::redirect_msg('授权失败, 请返回重新操作, URI: ' . $_SERVER['REQUEST_URI']);
     }
 }
Example #2
0
 public function login_action()
 {
     $url = base64_decode($_GET['url']);
     if ($this->user_id) {
         if ($url) {
             header('Location: ' . $url);
         } else {
             HTTP::redirect('/m/');
         }
     }
     if ($url) {
         $return_url = $url;
     } else {
         if (strstr($_SERVER['HTTP_REFERER'], '/m/')) {
             $return_url = $_SERVER['HTTP_REFERER'];
         } else {
             $return_url = get_js_url('/m/');
         }
     }
     if (in_weixin() and get_setting('weixin_app_id') and get_setting('weixin_account_role') == 'service') {
         HTTP::redirect($this->model('openid_weixin_weixin')->redirect_url($return_url));
     }
     TPL::assign('body_class', 'explore-body');
     TPL::assign('return_url', strip_tags($return_url));
     $this->crumb(AWS_APP::lang()->_t('登录'), '/m/login/');
     TPL::output('m/login');
 }
 public function oauth_redirect_action()
 {
     if (strstr($_GET['uri'], '%')) {
         $_GET['uri'] = urldecode($_GET['uri']);
     }
     if (!$_GET['uri']) {
         $redirect_uri = $_SERVER['HTTP_REFERER'];
     } else {
         $redirect_uri = get_js_url($_GET['uri']);
     }
     if (!in_weixin() or get_setting('weixin_account_role') != 'service') {
         HTTP::redirect($redirect_uri);
     }
     $redirect_info = parse_url($redirect_uri);
     $this->model('account')->logout();
     HTTP::redirect('https://open.weixin.qq.com/connect/oauth2/authorize?appid=' . get_setting('weixin_app_id') . '&redirect_uri=' . urlencode($redirect_uri) . '&response_type=code&scope=' . urlencode($_GET['scope']) . '&state=' . urlencode($_GET['state']) . '#wechat_redirect');
 }
Example #4
0
 public function save_ticket($title, $message, $uid, $attach_access_key = null, $from = null)
 {
     $to_save_ticket = array('title' => htmlspecialchars($title), 'message' => htmlspecialchars($message), 'time' => time(), 'uid' => intval($uid), 'ip' => ip2long(fetch_ip()), 'priority' => 'normal', 'status' => 'pending');
     if ($from and is_array($from)) {
         foreach ($from as $type => $from_id) {
             if (!is_digits($from_id)) {
                 continue;
             }
             $to_save_ticket['source'] = $type;
             $to_save_ticket[$type . '_id'] = $from_id;
         }
     } else {
         if (in_weixin()) {
             $to_save_ticket['source'] = 'weixin';
         }
     }
     $ticket_id = $this->insert('ticket', $to_save_ticket);
     if ($ticket_id) {
         set_human_valid('question_valid_hour');
         if ($attach_access_key) {
             $this->model('publish')->update_attach('ticket', $ticket_id, $attach_access_key);
         }
         if ($from and is_array($from)) {
             foreach ($from as $type => $from_id) {
                 if (!is_digits($from_id)) {
                     continue;
                 }
                 $this->update($type, array('ticket_id' => $question_id), 'id = ' . $from_id);
             }
         }
     }
     return $ticket_id;
 }