コード例 #1
0
 /**
  * 活动列表
  * @param int $user_id 用户id
  * @param int $page 页数
  * @param int $district 地区id
  * @param int $industry 分类id
  *
  * @return json
  * */
 public function actionActivitylist()
 {
     $param = Yii::$app->getRequest()->get();
     if (isset($param['user_id'])) {
         $user_id = intval($param['user_id']);
         $page = isset($param['page']) ? intval($param['page']) : 1;
         $activityurl = Yii::$app->params['iheima_api'] . '/?app=rss&controller=community&action=activity&page=' . $page;
         if (isset($param['district'])) {
             $activityurl .= '&district=' . intval($param['district']);
         }
         if (isset($param['industry'])) {
             $activityurl .= '&industry=' . intval($param['industry']);
         }
         $activitylist = Yii::$app->util->do_request($activityurl, '', 'GET');
         if ($activitylist['errcode'] == 1000) {
             $model = new UserBaseInfo();
             $user = $model->getUserById($user_id);
             $cyj_id = $user['open_id'];
             foreach ($activitylist['data']['list'] as $key => $value) {
                 $userinfo = array('open_id' => $cyj_id, 'timeline' => time(), 'sign' => 'ts');
                 $strinfo = $this->encrypt(json_encode($userinfo), '0e8357fd');
                 $activitylist['data']['list'][$key]['url'] = $value['url'] . '&from=group&act=' . $strinfo;
             }
             $return = array('status' => '0', 'msg' => 'success', 'data' => $activitylist['data']);
         } else {
             $return = array('status' => '4101', 'msg' => 'iheima_return_error');
         }
     } else {
         $return = array('status' => '1101', 'msg' => 'param_userid_missing');
     }
     return $return;
 }
コード例 #2
0
 /**
  * 用户简介
  */
 public function actionProfile()
 {
     $this->layout = 'sns';
     $mUser = new UserBaseInfo();
     $mInvest = new InvestTendency();
     $tmp = [];
     //从session中获取用户ID
     $uid = 7;
     $users = $mUser->getUserById($uid);
     $investStageSet = Yii::$app->util->loadConfig('user-invest-stage', '/platform_ep/config/');
     $invest = $mInvest->getInvestInfo($uid, $investStageSet);
     if ($invest) {
         if (isset($invest['invest_stage']) && is_array($invest['invest_stage'])) {
             foreach ($invest['invest_stage'] as $val) {
                 if (isset($investStageSet[$val]) && $investStageSet[$val]) {
                     $tmp[$val] = $investStageSet[$val];
                 } else {
                     throw new \Exception('error in user-invest-stage.config.php!!!');
                 }
             }
         }
         $invest['invest_stage'] = $tmp;
         $users['invest'] = $invest;
     }
     return $this->render('profile', ['users' => $users]);
 }
コード例 #3
0
ファイル: UserService.php プロジェクト: songhongyu/datecenter
 /**
  * 获取个应用系统登录接口地址
  *
  * @param bool $is_register true 表示注册
  * @return array|null
  * @throws \yii\base\Exception
  */
 public function getCookieUrl($is_register = false)
 {
     $cookieUrl = null;
     $appId = null;
     $info = null;
     $userModel = new UserBaseInfo();
     $userInfo = $userModel->getUserInfoCache();
     $sso = SsoSettingInfo::findAll();
     if ($sso) {
         foreach ($sso as $k => $val) {
             if (isset($val['log_out']['sign_in']) && $val['log_out']['sign_in']) {
                 $cookieUrl[] = $val['log_out']['sign_in'];
                 $appId[] = $val['app_id'];
             }
         }
     }
     if (isset($userInfo['id']) && $userInfo['id'] && $cookieUrl) {
         $user = $userModel->getUserById($userInfo['id']);
         $info['openid'] = $user['open_id'];
         $info['mobile'] = $user['mobile'];
         $info['email'] = $user['email'];
         if ($is_register) {
             $info['is_register'] = $is_register;
             $info['salt'] = $user['password_salt'];
             $info['password'] = $user['password'];
         }
         $info = json_encode($info);
         foreach ($cookieUrl as $key => &$url) {
             $appDir = $appId[$key];
             $encrypt = AsymmetryCrypt::opensslPublicEncrypt($info, dirname(Yii::$app->getBasePath()) . '/common/rsa_key/' . $appDir . '/rsa_public_key.pem');
             // TODO:: 为解决 +/ 丢失 / bug,临时解决方案
             $encrypt = str_replace('+/', '+_', $encrypt);
             $encrypt = rawurlencode($encrypt);
             $bool = filter_var($url, FILTER_VALIDATE_URL);
             if ($bool === false) {
                 unset($cookieUrl[$key]);
                 continue;
             }
             $path = parse_url($url);
             if (!isset($path['query'])) {
                 $url .= '?c=' . $encrypt;
                 continue;
             }
             $query = queryToArray($path['query']);
             $query['c'] = $encrypt;
             $query_params = arrayToQuery($query);
             $url = $path['scheme'] . '://' . $path['host'] . '?' . $query_params;
         }
         shuffle($cookieUrl);
         return $cookieUrl;
     } else {
         return null;
     }
 }
コード例 #4
0
 /**
  * 获取创业家下所有应用系统设置COOKIE接口地址
  */
 public function actionAppCookie()
 {
     // 获取JS回调函数
     $callback = Yii::$app->getRequest()->get('callback');
     $is_register = Yii::$app->getRequest()->get('is_register') ?: 0;
     try {
         $info = null;
         $userModel = new UserBaseInfo();
         $userInfo = $userModel->getUserInfoCache();
         if (isset($userInfo['id']) && $userInfo['id']) {
             $user = $userModel->getUserById($userInfo['id']);
             $info['openid'] = $user['open_id'];
             $info['mobile'] = $user['mobile'];
             $info['email'] = $user['email'];
             $info['password_salt'] = $user['password_salt'];
             $info['password'] = $user['password'];
             $info['username'] = $user['username'];
             if ($is_register) {
                 $info['is_register'] = $is_register;
                 $info['salt'] = $user['password_salt'];
                 $info['password'] = $user['password'];
             }
             $json = json_encode($info);
             // 记录日志
             $logger = FileLogger::getInstance('sso_' . date('Ymd') . '.log');
             $encrypt = AsymmetryCrypt::opensslPublicEncrypt($json, dirname(Yii::$app->getBasePath()) . '/common/rsa_public_key.pem');
             // $logger->writeOne($json . '====' . $encrypt, Logger::LEVEL_INFO,'SSO-IHEIMA');
             // TODO:: +/ 替换成 +_
             $encrypt = str_replace('+/', '+_', $encrypt);
             $encrypt = rawurlencode($encrypt);
             $logger->writeOne($json . '====' . $encrypt, Logger::LEVEL_INFO, 'SSO-IHEIMA');
             $thinksns = AsymmetryCrypt::opensslPublicEncrypt($json, dirname(Yii::$app->getBasePath()) . '/common/rsa_key/100003/rsa_public_key.pem');
             $thinksns = rawurlencode($thinksns);
             // TODO:: 获取应用系统COOKIE接口地址
             $appCookie = ['code' => 0, 'sso' => [Url::toRoute(['sso/index'], true), 'http://app.iheima.net/?app=ihminterface&controller=index&action=ihmlogin&c=' . $encrypt, 'http://dev-group.chuangyejia.com/index.php?app=public&mod=Passport&act=grouplogin&c=' . $thinksns, 'http://test-group.chuangyejia.com/index.php?app=public&mod=Passport&act=grouplogin&c=' . $thinksns, 'http://group.chuangyejia.com/index.php?app=public&mod=Passport&act=grouplogin&c=' . $thinksns, 'http://cyj.zhiyicx.com/index.php?app=public&mod=Passport&act=grouplogin&c=' . $thinksns, 'http://group-t.chuangyejia.com/index.php?app=public&mod=Passport&act=grouplogin&c=' . $thinksns], 'msg' => []];
             echo $callback . '(' . json_encode($appCookie) . ')';
         } else {
             echo $callback . '(' . json_encode(['code' => 1, 'msg' => '用户未登录']) . ')';
         }
     } catch (Exception $ex) {
         // TODO:: 异常处理
         echo $callback . '(' . json_encode(['code' => 2, 'msg' => '系统繁忙,请稍后重试']) . ')';
     }
 }
コード例 #5
0
 /**
  * 同步个人信息
  *
  * @param array $data 变更数据
  *  $data中必须包含为id的Key
  * @return boolean
  */
 protected function syncProfile($data)
 {
     $res = false;
     $mUser = new UserBaseInfo();
     $uid = isset($data['id']) && $data['id'] ? $data['id'] : false;
     if (!$uid) {
         return $uid;
     }
     unset($data['id']);
     $user = $mUser->getUserById($uid);
     if ($user) {
         $industry = Yii::$app->util->loadConfig('user-industry', '/platform_i/config/');
         $user = array_merge($user, $data);
         // 设置默认同步数据
         $data = ['open_id' => $user['open_id'], 'name' => $user['username'], 'password' => $user['password'], 'salt' => $user['password_salt'], 'birthday' => $user['birthday'], 'city' => $user['city'], 'industry' => $user['industry'], 'company' => $user['company'], 'position' => $user['position'], 'dc_avatar' => $user['avatar']];
         // $data = array_merge($defData, $data);
         $data['industry'] = !$industry || !$data['industry'] || !isset($industry[$data['industry']]) ? '' : $industry[$data['industry']];
         $data['user_trade'] = $data['industry'];
         $data['job'] = $data['position'];
         unset($data['industry']);
         unset($data['position']);
         $mDistrict = new District();
         $city = $mDistrict->getByCity($data['city']);
         $data['city'] = (!isset($city['parent']) ? '' : $city['parent']['name']) . ' ' . $city['name'];
         try {
             $sso = Yii::$app->sso;
             $res = $sso->sync('profile', $data);
             $sso->syncProfileLog($res, json_encode($data), 'profile');
         } catch (\Exception $e) {
         }
         // TODO: 针对同步结果进行相关操作
         if ($res) {
         } else {
         }
     }
     return $res;
 }
コード例 #6
0
 public function modifyEmail($params = array())
 {
     $email = isset($params['mobile']) && $params['mobile'] ? $params['mobile'] : '';
     $id = isset($params['id']) && $params['id'] ? $params['id'] : 0;
     if ($id && $email) {
         $mUserOpLog = new UserOperateLog();
         $mUser = new UserBaseInfo();
         $preg = '/^([a-zA-Z0-9_\\.\\-])+\\@(([a-zA-Z0-9\\-])+\\.)+([a-zA-Z]{2,5})$/';
         if (!preg_match($preg, $email)) {
             Yii::$app->util->formatResData(1107, '', ['msg' => '邮箱格式有误']);
         }
         $data = ['id' => $id, 'email' => $email];
         $user = $mUser->getUserById($id);
         $result = $mUser->updateUserById($data);
         $opMsg = empty($user['email']) ? '安全邮箱绑定' : '安全邮箱修改';
         $mUserOpLog->store($opMsg, $user['email'], $email, $result);
         if (!$result) {
             Yii::$app->util->formatResData(1302, 'error_update_email', ['msg' => '更新邮箱失败']);
         }
         $data = ['open_id' => $user['open_id'], 'email' => $email];
         // 针对SSO用户同步相关信息
         try {
             $sso = Yii::$app->sso;
             $res = $sso->sync('email', $data);
             $sso->syncProfileLog($res, json_encode($data), 'email');
         } catch (\Exception $e) {
         }
     }
 }