コード例 #1
0
ファイル: UserEmblem.php プロジェクト: diandianxiyu/Yii2Api
 /**
  * 写入登录标识
  * @param int $user_id 用户的user_id
  * @param string $value 
  * @param int $type 登录的类型 1设备 2手机 3QQ 4微博 5微信
  * @return  int 主键
  */
 public static function add($user_id, $value, $type = 1)
 {
     $model = new UserEmblem();
     $model->create_time = time();
     $model->login_type = $type;
     $model->login_value = $value;
     $model->user_id = $user_id;
     $model->insert();
     return $model->id;
 }
コード例 #2
0
 /**
  * 验证手机号是不是已经被注册了
  */
 public function actionCheckMobile()
 {
     $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_os = (int) $request->post("os");
     //设备终端
     $param_mobile = $request->post("mobile");
     //手机号
     //获取token
     $headers = $request->headers;
     $header_openid = $headers->get('Openid') ? $headers->get('Openid') : $request->post("openid");
     //加密之后的设备号,做到兼容post的方式
     //验证参数是不是有空的
     $check_null = Validators::validateAllNull([$param_deviceid, $param_mobile, $header_openid, $param_os]);
     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);
     }
     //验证通过,证明了合法性
     //测试数据 18312376990  123123
     $decode_mobile = RsaDecode::rsa_decode($param_mobile);
     //验证手机号是不是进行过注册的操作
     $user_id = UserEmblem::checkExist($decode_mobile, 2);
     if ($user_id == 0) {
         //手机号不存在
         $check = 0;
     } else {
         $check = 1;
     }
     //返回对应的结果
     $return_json = ['request' => $this_path, 'info' => ['mobile' => $decode_mobile, 'check' => $check], 'version' => $this_allow_version, 'error_code' => 0, 'error' => ""];
     //接口访问记录
     CensusApi::add($user_id, $this_path);
     return $response->data = $return_json;
 }