Example #1
0
 /**
  * 1.3版本的通过用户的 user_id获取用户的基本信息
  * @param  int $user_id 用户的 id
  */
 public static function getUserProfileVer13($user_id)
 {
     //获取用户的昵称性别头像
     $user_avatar = UserAvatar::get($user_id);
     //用户基本信息
     $user_profile = UserProfile::getProfile($user_id);
     //认证状态
     $sign_status = UserStatus::checkSignStatus($user_id) ? 1 : 0;
     //禁言状态
     $nosay_status = UserStatus::checkPressContentStatus($user_id) ? 1 : 0;
     //返回签到天数
     $sign_count = SignRecord::getSignCount($user_id);
     //获取 uid
     $uid = UserAccount::getUid($user_id);
     //被点赞的总数,获取的顺序,发布中的数量,对应的使用的标签的数量,->太麻烦,临时增加数据表,做点赞总数的记录,用user_status的字段吧 = =
     $like_count = UserStatus::getUserLikeCount($user_id);
     //验证身份的数组
     $auth_user_arr = Yii::$app->params['auth_account'];
     //组合数据
     $user_status = ['uid' => $uid, 'avatar' => $user_avatar, 'sign_count' => $sign_count, 'banned_status' => $nosay_status, 'sign_status' => $sign_status, 'like_count' => $like_count, 'access_status' => 1, 'account_status' => (int) in_array($uid, $auth_user_arr)];
     $user_info = array_merge($user_status, $user_profile);
     return $user_info;
 }
 /**
  * 第三方账户登录
  */
 public function actionTriLogin()
 {
     $response = Yii::$app->response;
     $response->format = \yii\web\Response::FORMAT_JSON;
     $request = Yii::$app->request;
     $this_path = $this->modules_name . "/" . lcfirst($this->class_name) . "/" . lcfirst(str_replace('action', "", __FUNCTION__));
     $this_allow_version = "1.1";
     //获取参数
     $param_deviceid = $request->post("deviceid");
     //设备id
     $param_clienttime = (int) $request->post("clienttime");
     //客户端时间
     $param_os = (int) $request->post("os");
     //设备终端
     $param_channel = $request->post("channel");
     //渠道
     $param_emblem = $request->post("emblem");
     //第三方的标识
     $param_type = (int) $request->post("type");
     //登录类型
     $param_gender = (int) $request->post("gender");
     //性别
     $param_nikename = $request->post("nikename");
     //昵称
     $param_avatar = $request->post("avatar");
     //头像地址
     //获取token
     $headers = $request->headers;
     $header_openid = $headers->get('Openid') ? $headers->get('Openid') : $request->post("openid");
     //加密之后的设备号,做到兼容post的方式
     //验证参数是不是有空的
     $check_null = Validators::validateAllNull([$param_deviceid, $param_channel, $param_clienttime, $header_openid, $param_os, $param_emblem, $param_type, $param_gender, $param_nikename, $param_avatar]);
     if ($check_null === FALSE) {
         //错误信息,参数不全
         return $response->data = Error::errorJson($this_path, 1001);
     }
     //验证加密
     $decode_hear_openid = RsaDecode::rsa_decode($header_openid);
     if ($decode_hear_openid !== $param_deviceid) {
         return $response->data = Error::errorJson($this_path, 9001);
     }
     //验证通过,证明了合法性
     //验证性别
     if (!in_array($param_gender, [1, 2, 3])) {
         //性别输入不符
         return $response->data = Error::errorJson($this_path, 9001);
     }
     //验证登录方式
     $login_type = $param_type + 2;
     if ($login_type < 3 || $login_type > 7) {
         //返回错误信息,错误的登录方式
         return $response->data = Error::errorJson($this_path, 4003);
     }
     //验证手机号是不是进行过注册的操作
     $user_id = UserEmblem::checkExist($param_emblem, $login_type);
     if ($user_id == 0) {
         //注册新用户
         // 获取新的uid,写入 用户基础表,写入 用户标识表 ,写入 用户头像表
         $uid = NumberOrder::getNewid(1);
         $user_id = UserAccount::add($uid, $param_channel, $param_os);
         //用户相关的标识
         UserEmblem::add($user_id, $param_emblem, $login_type);
         //获取用户的头像
         $avatar_url = WebImgToLocal::web2oss($param_avatar);
         UserAvatar::add($user_id, $avatar_url);
         //用户的基本信息
         UserProfile::add($user_id, $param_nikename, $param_gender);
         //新的
         $login_type = 1;
         //新增用户的统计
         CensusApp::addUser();
     } else {
         //获取老用户的 id
         $uid = UserAccount::getUid($user_id);
         //以前的
         $login_type = 2;
     }
     //写入token
     TokenUser::joinToken($uid, $param_deviceid, $param_clienttime, time(), time());
     //返回对应的token
     $token = RsaDecode::tokenMake($uid);
     //返回对应的结果
     $return_json = ['request' => $this_path, 'info' => ['login_type' => $login_type, 'token' => $token, 'user_info' => App::getUserProfile($user_id)], 'version' => $this_allow_version, 'error_code' => 0, 'error' => ""];
     //接口访问记录
     CensusApi::add($user_id, $this_path);
     return $response->data = $return_json;
 }