scenario = get_params('_platform') ?: post_params('_platform'); $form->attributes = all_params(); $form->store_id = get_store_id(); return $this->asJson($form->login()); } public function actionEditPassword() { $form = new AuthLoginForm(); $form->attributes = all_params(); $form->store_id = get_store_id(); return $this->asJson($form->editPassword()); } //忘记密码 public function actionForgetPassword() { $form = new AuthLoginForm(); $form->attributes = all_params(); $form->store_id = get_store_id(); return $this->asJson($form->forgetPassword()); } //使用账户密码注册账户 public function actionUserPasswordRegedit() { $form = new AuthLoginForm(); $form->attributes = all_params(); $form->store_id = get_store_id(); return $this->asJson($form->userPasswordRegedit()); } public function actionCode() { $form = new AuthLoginForm(); $form->attributes = all_params(); $form->store_id = get_store_id(); return $this->asJson($form->code()); } public function actionGetUserInfoById() { $form = new AuthLoginForm(); $form->attributes = all_params(); $form->store_id = get_store_id(); return $this->asJson($form->getUserInfoById()); } public function actionGetUserInfoByMobile() { $form = new AuthLoginForm(); $form->attributes = all_params(); $form->store_id = get_store_id(); return $this->asJson($form->getUserInfoByMobile()); } /** * 发送验证码 * @return \yii\web\Response */ public function actionSendCode() { $form = new LoginForm(); $form->phone = post_params('phone'); $form->store_id = get_store_id(); if (trim(post_params('code_type')) == LoginForm::TYPE_VERIFY_CODE_LOGIN) { return $this->asJson($form->sendCode(LoginForm::CACHE_KEY_SMS_LOGIN)); } else if (trim(post_params('code_type')) == LoginForm::TYPE_VERIFY_CODE_BIND) { return $this->asJson($form->sendCode(LoginForm::CACHE_KEY_BIND_PHONE)); } else if (trim(post_params('code_type')) == LoginForm::TYPE_VERIFY_CODE_FORGET_PASSWORD) { return $this->asJson($form->sendCode(LoginForm::CACHE_KEY_SMS_FORGET_PASSWORD)); } else { return $this->asJson(['code' => 1, 'msg' => '参数不正确']); } } /** * 绑定手机号 * @return \yii\web\Response */ public function actionBindPhone() { $form = new LoginForm(); $form->attributes = post_params(); $form->user = get_user(); return $this->asJson($form->bindPhone()); } /** * 独立小程序登录手机号登录 */ public function actionAuthPhone() { $form = new AuthLoginForm(); $form->attributes = all_params(); $form->store_id = get_store_id(); return $this->asJson($form->phoneAuth()); } /** * 平台小程序手机号登录(平台个人中心,店铺个人中心) */ public function actionPlatformAuthPhone() { $form = new AuthLoginForm(); $form->attributes = all_params(); $form->store_id = get_store_id(); return $this->asJson($form->platformPhoneAuth()); } public function actionLoginByOpenid() { $form = new AuthLoginForm(); $form->attributes = all_params(); $form->store_id = get_store_id(); return $this->asJson($form->loginByOpenid()); } public function actionLoginByUserId() { $form = new AuthLoginForm(); $form->attributes = all_params(); $form->store_id = get_store_id(); return $this->asJson($form->loginByUserId()); } // 用于供应链小程序切换商城后自动登录 public function actionSwitchStoreAutoLogin() { $form = new AuthLoginForm(); $form->attributes = all_params(); $form->store_id = get_store_id(); return $this->asJson($form->loginByAuto()); } public function actionGetOptionByH5() { $form = new AuthLoginForm(); $form->attributes = all_params(); $form->store_id = get_store_id(); return $this->asJson($form->getOptionByH5()); } public function actionGetRedirectUri() { $form = new AuthLoginForm(); $form->attributes = all_params(); $form->store_id = get_store_id(); return $this->asJson($form->getRedirectUri()); } public function actionSetH5UserInfo() { $form = new AuthLoginForm(); $form->attributes = all_params(); $form->store_id = get_store_id(); return $this->asJson($form->setH5UserInfo()); } public function actionCaptchaGen() { $session = get_params('session'); $type = get_params('type'); $refresh = (bool)get_params('refresh', false); if (!$session) { return $this->asJson(['code' => 1, 'msg' => '参数错误']); } $key = 'captcha_' . $session; $data = cache()->get($key); if (!$data && !$refresh) { return $this->asJson(['code' => 1, 'msg' => '验证码已过期, 请刷新!']); } if ($refresh) { $data = [ 'x' => rand(130, 550), 'y' => rand(50, 260), 'img' => rand(1, 61) . '.jpg', 'template' => 'template/' . rand(1, 4) . '.png', 'opacity' => rand(30, 80), 'error' => 2, // 初始错误次数为2, 可失败3次, 超过就要刷新 ]; cache()->set($key, $data, 600); return $this->asJson(['code' => 0, 'msg' => '验证码已刷新']); } try { $x = $data['x']; $y = $data['y']; $img = $data['img']; $template = $data['template']; $opacity = $data['opacity']; $basePath = \Yii::$app->basePath . '/web/statics/captcha/'; $src = imagecreatefromjpeg($basePath . $img); $resImage = imagecreatetruecolor(90, 90); $transparent = imagecolorallocatealpha($resImage, 255, 255, 255, 127); imagecolortransparent($resImage, $transparent); imagefill($resImage, 0, 0, $transparent); $tempImage = @imagecreatefrompng($basePath . $template); for ($i = 0; $i < 90; $i++) { for ($j = 0; $j < 90; $j++) { if (imagecolorat($tempImage, $i, $j) !== 0) { $rgb = imagecolorat($src, $x + $i, $y + $j); imagesetpixel($resImage, $i, $j, $rgb); } } } if ($type == 'main') { $mengban = imagecreatetruecolor(90, 90); imagecolortransparent($mengban, $transparent); imagefill($mengban, 0, 0, $transparent); $huise = imagecolorallocatealpha($resImage, 255, 255, 255, $opacity); for ($i = 0; $i < 90; $i++) { for ($j = 0; $j < 90; $j++) { $rgb = imagecolorat($resImage, $i, $j); if ($rgb !== 2147483647) { imagesetpixel($mengban, $i, $j, $huise); } } } imagecopyresampled( $src, $resImage, $x, $y, 0,0, 90, 90, 90, 90 ); imagecopyresampled( $src, $mengban, $x + 1, $y + 1, 0,0, 90 - 2, 90 - 2, 90, 90 ); \ob_start(); imagejpeg($src); $data = \ob_get_clean(); \Yii::$app->response->headers->add('Content-Type', 'image/jpeg'); \Yii::$app->response->data = $data; } if ($type == 'secondary') { $white = imagecolorallocatealpha($resImage, 255, 255, 255, 1); for ($i = 0; $i < 90; $i++) { for ($j = 0; $j < 90; $j++) { if(imagecolorat($tempImage, $i, $j) === 0) { imagesetpixel($resImage, $i, $j, $white); } } } $resImage2 = imagecreatetruecolor(90, 382); imagecolortransparent($resImage2, $transparent); imagefill($resImage2, 0, 0, $transparent); imagecopyresampled( $resImage2, $resImage, 0, $y, 0, 0, 90, 90, 90, 90 ); \ob_start(); imagepng($resImage2); $data = ob_get_clean(); \Yii::$app->response->headers->add('Content-Type', 'image/png'); \Yii::$app->response->data = $data; } \Yii::$app->response->format = \yii\web\Response::FORMAT_RAW; return \Yii::$app->response; } catch (\Throwable $e) { return $this->asJson(['code' => 1, 'msg' => $e->getMessage()]); } } public function actionCaptchaCheck() { $session = get_params('session'); $touchX = get_params('touch_x'); $key = 'captcha_' . $session; if (!$session || !$touchX) { return $this->asJson(['code' => 1, 'msg' => '参数错误']); } $data = cache()->get($key); if (!$data) { return $this->asJson(['code' => 1, 'msg' => '验证码已过期, 请刷新']); } if ($data['error'] <= 0) { return $this->asJson(['code' => 1, 'msg' => '验证失败次数过多']); } if ($touchX < $data['x'] - 5 || $touchX > $data['x'] + 5) { $data['error']--; cache()->set($key, $data, 600); return $this->asJson(['code' => 1, 'msg' => '验证失败,请重试']); } cache()->delete($key); return $this->asJson(['code' => 0, 'msg' => '验证成功!']); } /** * 获取邀请码用户id */ public function actionGetUserInfoByInvite() { $invite_code = input_params('invite_code', ''); if(!$invite_code){ return $this->asJson(['code' => 1, 'msg' => '请填写邀请码']); } //邀请码解密 $uid = InviteCode::code2ID($invite_code); if(!$uid){ return $this->asJson(['code' => 1, 'msg' => '邀请码不存在']); } $user = User::findOne(['id'=>$uid,'is_delete' => 0]); if(!$user){ return $this->asJson(['code' => 1, 'msg' => '用户不存在']); } $data = [ 'id' => $user->id, 'avatar_url' => $user->avatar_url, 'nickname' => $user->nickname, 'mobile' => $user->binding, ]; $saasUser = SaasUser::find()->where(['mobile' => $user->binding])->one(); if ($saasUser) { $data['avatar_url'] = $saasUser->avatar; $data['nickname'] = $saasUser->name; $data['mobile'] = $saasUser->mobile; } return $this->asJson(['code' => 0, 'msg' => 'success', 'data' => $data]); } }