Ejemplo n.º 1
0
 function mw_sub_domain_only($sub_domain = "")
 {
     global $g4;
     global $is_admin;
     if (!$_SERVER[HTTP_HOST]) {
         return false;
     }
     if (@is_file($g4['path'] . "/plugin/mobile/_config.php")) {
         include_once $g4['path'] . "/plugin/mobile/_config.php";
     }
     if ($mw_mobile['m_subdomain'] and mw_get_sub_domain() == 'm') {
         return;
     }
     if (!$g4[cookie_domain] and G5_COOKIE_DOMAIN) {
         $g4[cookie_domain] = G5_COOKIE_DOMAIN;
     }
     if (!$g4[cookie_domain]) {
         $g4[cookie_domain] = '.' . get_top_domain();
     }
     if (!$g4[cookie_domain]) {
         return;
     }
     if ($_SERVER[HTTP_HOST] != $sub_domain . $g4[cookie_domain]) {
         goto_url2("http://" . $sub_domain . $g4[cookie_domain] . $_SERVER[REQUEST_URI]);
     }
 }
Ejemplo n.º 2
0
 /**
  * 第三方登录
  */
 public function third_login()
 {
     $type = I('get.type');
     $file = ROOT_PATH . 'plugins/connect/' . $type . '.php';
     if (file_exists($file)) {
         include_once $file;
     } else {
         show_message(L('process_false'), L('relogin_lnk'), url('login', array('referer' => urlencode($this->back_act))), 'error');
     }
     $url = __URL__ . '/index.php?m=default&c=user&a=third_login&type=' . $type;
     $info = model('ClipsBase')->get_third_user_info($type);
     // 判断是否安装
     if (!$info) {
         show_message(L('no_register_auth'), L('relogin_lnk'), url('login', array('referer' => urlencode($this->back_act))), 'error');
     }
     $obj = new $type($info);
     if ($_GET['code'] && $_GET['code'] != '') {
         // 授权成功 返回登录
         if ($obj->call_back($info, $url, $_GET['code'])) {
             if ($_SESSION['access_token']) {
                 $res = new $type($info, $_SESSION['access_token']);
                 $openid = $res->get_openid();
                 // 获取用户信息
                 $userinfo = $res->get_user_info($openid);
                 // 处理数据
                 $userinfo['aite_id'] = $type . '_' . $openid;
                 // 添加登录标示
                 if ($userinfo['user_name'] = model('Users')->get_one_user($userinfo['aite_id'])) {
                     // 已有记录
                     self::$user->set_session($userinfo['user_name']);
                     self::$user->set_cookie($userinfo['user_name']);
                     model('Users')->update_user_info();
                     model('Users')->recalculate_price();
                     $jump_url = empty($this->back_act) ? url('index') : $this->back_act;
                     $this->redirect($jump_url);
                 }
                 $userinfo['user_name'] = substr($openid, -6);
                 if (self::$user->check_user($userinfo['user_name'])) {
                     $userinfo['user_name'] = $userinfo['user_name'] . rand(1000, 9999);
                     // 重名处理
                 }
                 $userinfo['email'] = empty($userinfo['email']) ? $userinfo['user_name'] . '@' . get_top_domain() : $userinfo['email'];
                 // 插入数据库
                 model('Users')->third_reg($userinfo);
                 self::$user->set_session($userinfo['user_name']);
                 self::$user->set_cookie($userinfo['user_name']);
                 model('Users')->update_user_info();
                 model('Users')->recalculate_price();
                 $jump_url = empty($this->back_act) ? url('index') : $this->back_act;
                 $this->redirect($jump_url);
             }
         } else {
             show_message(L('process_false'), L('relogin_lnk'), url('login', array('referer' => urlencode($this->back_act))), 'error');
         }
     } else {
         // 开始授权登录
         $url = $obj->act_login($info, $url);
         ecs_header("Location: " . $url . "\n");
         exit;
     }
 }
Ejemplo n.º 3
0
 /**
  * 更新微信用户信息
  *
  * @param unknown $userinfo            
  * @param unknown $wechat_id            
  * @param unknown $weObj            
  */
 static function update_weixin_user($userinfo, $wechat_id, $weObj)
 {
     $time = time();
     $ret = model('Base')->model->table('wechat_user')->field('openid, ect_uid')->where('openid = "' . $userinfo['openid'] . '"')->find();
     if (empty($ret)) {
         // 获取用户所在分组ID
         $group_id = $weObj->getUserGroup($userinfo['openid']);
         $group_id = $group_id ? $group_id : 0;
         //微信用户绑定会员id
         $ect_uid = 0;
         //查看公众号是否绑定
         if ($userinfo['unionid']) {
             $ect_uid = model('Base')->model->table('wechat_user')->field('ect_uid')->where(array('unionid' => $userinfo['unionid']))->getOne();
         }
         //未绑定
         if (empty($ect_uid)) {
             // 设置的用户注册信息
             $register = model('Base')->model->table('wechat_extend')->field('config')->where('enable = 1 and command = "register_remind" and wechat_id = ' . $wechat_id)->find();
             if (!empty($register)) {
                 $reg_config = unserialize($register['config']);
                 $username = msubstr($reg_config['user_pre'], 3, 0, 'utf-8', false) . time() . mt_rand(1, 99);
                 // 密码随机数
                 $rs = array();
                 $arr = range(0, 9);
                 $reg_config['pwd_rand'] = $reg_config['pwd_rand'] ? $reg_config['pwd_rand'] : 3;
                 for ($i = 0; $i < $reg_config['pwd_rand']; $i++) {
                     $rs[] = array_rand($arr);
                 }
                 $pwd_rand = implode('', $rs);
                 // 密码
                 $password = $reg_config['pwd_pre'] . $pwd_rand;
                 // 通知模版
                 $template = str_replace(array('[$username]', '[$password]'), array($username, $password), $reg_config['template']);
             } else {
                 $username = '******' . time() . mt_rand(1, 99);
                 $password = '******';
                 // 通知模版
                 $template = '默认用户名:' . $username . "\r\n" . '默认密码:' . $password;
             }
             // 会员注册
             $domain = get_top_domain();
             if (model('Users')->register($username, $password, $username . '@' . $domain) !== false) {
                 $data['user_rank'] = 99;
                 if (session('sale_id')) {
                     $data['parent_id'] = session('sale_id');
                 }
                 model('Base')->model->table('users')->data($data)->where('user_name = "' . $username . '"')->update();
             } else {
                 die('授权失败,如重试一次还未解决问题请联系管理员');
             }
             $data1['ect_uid'] = $_SESSION['user_id'];
         } else {
             //已绑定
             $username = model('Base')->model->table('users')->field('user_name')->where(array('user_id' => $ect_uid))->getOne();
             $template = '您已拥有帐号,用户名为' . $username;
             $data1['ect_uid'] = $ect_uid;
         }
         $data1['wechat_id'] = $wechat_id;
         $data1['subscribe'] = 1;
         $data1['openid'] = $userinfo['openid'];
         $data1['nickname'] = $userinfo['nickname'];
         $data1['sex'] = $userinfo['sex'];
         $data1['city'] = $userinfo['city'];
         $data1['country'] = $userinfo['country'];
         $data1['province'] = $userinfo['province'];
         $data1['language'] = $userinfo['country'];
         $data1['headimgurl'] = $userinfo['headimgurl'];
         $data1['subscribe_time'] = $time;
         $data1['group_id'] = $group_id;
         $data1['unionid'] = $userinfo['unionid'];
         model('Base')->model->table('wechat_user')->data($data1)->insert();
         // 微信端发送消息
         $msg = array('touser' => $userinfo['openid'], 'msgtype' => 'text', 'text' => array('content' => $template));
         $weObj->sendCustomMessage($msg);
     } else {
         //开放平台有privilege字段,公众平台没有
         unset($userinfo['privilege']);
         $userinfo['subscribe'] = 1;
         model('Base')->model->table('wechat_user')->data($userinfo)->where('openid = "' . $userinfo['openid'] . '"')->update();
         $new_user_name = model('Base')->model->table('users')->field('user_name')->where('user_id = "' . $ret['ect_uid'] . '"')->getOne();
         ECTouch::user()->set_session($new_user_name);
         ECTouch::user()->set_cookie($new_user_name);
         model('Users')->update_user_info();
     }
     // 推送量
     model('Base')->model->table('wechat')->data('oauth_count = oauth_count + 1')->where('default_wx = 1 and status = 1')->update();
     session('openid', $userinfo['openid']);
 }