You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
58 lines
1.7 KiB
58 lines
1.7 KiB
<?php
|
|
|
|
namespace app\controller\wechat;
|
|
|
|
use app\service\user\LoginService;
|
|
use think\facade\Request;
|
|
|
|
class Login extends Base
|
|
{
|
|
/**
|
|
* @var
|
|
*/
|
|
public $auth;
|
|
protected $valid = \app\validate\Login::class;
|
|
|
|
/**
|
|
* @title 登录凭证校验
|
|
* @return \think\Response|void
|
|
*/
|
|
public function code2session(){
|
|
|
|
try {
|
|
validate($this->valid)->scene('code2session')->check(Request::post());
|
|
$code = $this->request->param('code');
|
|
$iv = $this->request->param('iv');
|
|
$encryptedData = $this->request->param('encryptedData');
|
|
$loginService = new LoginService();
|
|
$user = $loginService->code2session($code, $iv, $encryptedData);
|
|
return $this->buildSuccess($user);
|
|
} catch (\Exception $e) { //错误消息 $e->getMessage()
|
|
return $this->buildFailed($e->getCode() ?: 400,$e->getMessage());
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @title 登录
|
|
* @return \think\Response|void
|
|
*/
|
|
public function login(){
|
|
try {
|
|
validate($this->valid)->scene('login')->check(Request::post());
|
|
$phone = $this->request->post('phone');
|
|
$openid = $this->request->post('openid');
|
|
$unionid = $this->request->post('unionid');
|
|
$loginService = new LoginService();
|
|
$user = $loginService->userLogin($phone, $openid, $unionid);
|
|
$user['token'] = $this->signToken($user);
|
|
return $this->buildSuccess($user);
|
|
} catch (\Exception $e) { //错误消息 $e->getMessage()
|
|
return $this->buildFailed($e->getCode() ?: 400,$e->getMessage());
|
|
}
|
|
}
|
|
|
|
public function userLogout()
|
|
{
|
|
|
|
}
|
|
}
|