|
|
@ -17,7 +17,8 @@ class LoginService extends BaseService |
|
|
* 判断登录状态 |
|
|
* 判断登录状态 |
|
|
* @return bool |
|
|
* @return bool |
|
|
*/ |
|
|
*/ |
|
|
public function isLogin() { |
|
|
public function isLogin() |
|
|
|
|
|
{ |
|
|
if (!$this->user) { |
|
|
if (!$this->user) { |
|
|
return false; |
|
|
return false; |
|
|
} |
|
|
} |
|
|
@ -32,7 +33,8 @@ class LoginService extends BaseService |
|
|
* @return array |
|
|
* @return array |
|
|
* @throws \fast\FuncException |
|
|
* @throws \fast\FuncException |
|
|
*/ |
|
|
*/ |
|
|
public function code2session($code, $iv, $encryptedData){ |
|
|
public function code2session($code, $iv, $encryptedData) |
|
|
|
|
|
{ |
|
|
|
|
|
|
|
|
$http = new Http(); |
|
|
$http = new Http(); |
|
|
$url = "https://api.weixin.qq.com/sns/jscode2session?appid=" . env("app.appid") . "&secret=" . env("app.appsecret") . "&js_code={$code}&grant_type=authorization_code"; |
|
|
$url = "https://api.weixin.qq.com/sns/jscode2session?appid=" . env("app.appid") . "&secret=" . env("app.appsecret") . "&js_code={$code}&grant_type=authorization_code"; |
|
|
@ -63,7 +65,8 @@ class LoginService extends BaseService |
|
|
* @return false|string |
|
|
* @return false|string |
|
|
* @throws \fast\FuncException |
|
|
* @throws \fast\FuncException |
|
|
*/ |
|
|
*/ |
|
|
public function decodeWechatIv($iv, $encryptedData){ |
|
|
public function decodeWechatIv($iv, $encryptedData) |
|
|
|
|
|
{ |
|
|
$openid = session('app_openid'); |
|
|
$openid = session('app_openid'); |
|
|
$session_key = session('app_session_key'); |
|
|
$session_key = session('app_session_key'); |
|
|
if (!$openid || !$session_key) { |
|
|
if (!$openid || !$session_key) { |
|
|
@ -102,7 +105,8 @@ class LoginService extends BaseService |
|
|
* @throws \think\db\exception\DbException |
|
|
* @throws \think\db\exception\DbException |
|
|
* @throws \think\db\exception\ModelNotFoundException |
|
|
* @throws \think\db\exception\ModelNotFoundException |
|
|
*/ |
|
|
*/ |
|
|
public function userLogin($phone, $openid, $unionid) { |
|
|
public function userLogin($phone, $openid, $unionid) |
|
|
|
|
|
{ |
|
|
$field = 'id,openid,phone,nickname,sex,headimgurl'; |
|
|
$field = 'id,openid,phone,nickname,sex,headimgurl'; |
|
|
$user = WechatUser::where('phone', $phone)->where('openid', $openid)->where('delete_time', 0)->field($field)->find(); |
|
|
$user = WechatUser::where('phone', $phone)->where('openid', $openid)->where('delete_time', 0)->field($field)->find(); |
|
|
if ($user) { |
|
|
if ($user) { |
|
|
@ -112,12 +116,32 @@ class LoginService extends BaseService |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* |
|
|
|
|
|
* @param $phone |
|
|
|
|
|
* @return WechatUser|array|mixed |
|
|
|
|
|
* @throws \fast\FuncException |
|
|
|
|
|
* @throws \think\db\exception\DataNotFoundException |
|
|
|
|
|
* @throws \think\db\exception\DbException |
|
|
|
|
|
* @throws \think\db\exception\ModelNotFoundException |
|
|
|
|
|
*/ |
|
|
|
|
|
public function userPhoneLogin($phone) |
|
|
|
|
|
{ |
|
|
|
|
|
$field = 'id,openid,phone,nickname,sex,headimgurl'; |
|
|
|
|
|
$user = WechatUser::where('phone', $phone)->where('delete_time', 0)->field($field)->find(); |
|
|
|
|
|
if ($user) { |
|
|
|
|
|
return $this->userSuccess($user); |
|
|
|
|
|
} |
|
|
|
|
|
return $this->register($phone); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* 用户登录成功 |
|
|
* 用户登录成功 |
|
|
* @param WechatUser $user |
|
|
* @param WechatUser $user |
|
|
* @return array |
|
|
* @return array |
|
|
*/ |
|
|
*/ |
|
|
public function userSuccess(WechatUser $user) { |
|
|
public function userSuccess(WechatUser $user) |
|
|
|
|
|
{ |
|
|
session('user', $user->toArray()); |
|
|
session('user', $user->toArray()); |
|
|
$this->userKeeplogin($user->id,$user->openid,3600 * 24 * 7); |
|
|
$this->userKeeplogin($user->id,$user->openid,3600 * 24 * 7); |
|
|
// $user->visible(['id', 'name', 'logo']); |
|
|
// $user->visible(['id', 'name', 'logo']); |
|
|
@ -131,7 +155,8 @@ class LoginService extends BaseService |
|
|
* @param $keeptime |
|
|
* @param $keeptime |
|
|
* @return bool |
|
|
* @return bool |
|
|
*/ |
|
|
*/ |
|
|
protected function userKeeplogin($user_id,$token,$keeptime = 0) { |
|
|
protected function userKeeplogin($user_id, $token, $keeptime = 0) |
|
|
|
|
|
{ |
|
|
if ($keeptime) { |
|
|
if ($keeptime) { |
|
|
$expiretime = time() + $keeptime; |
|
|
$expiretime = time() + $keeptime; |
|
|
|
|
|
|
|
|
@ -149,15 +174,16 @@ class LoginService extends BaseService |
|
|
/** |
|
|
/** |
|
|
* 用户端注册 |
|
|
* 用户端注册 |
|
|
* @param $phone |
|
|
* @param $phone |
|
|
* @param $openid |
|
|
* @param string $openid |
|
|
* @param $unionid |
|
|
* @param string $unionid |
|
|
* @return WechatUser|mixed |
|
|
* @return WechatUser|mixed |
|
|
* @throws \fast\FuncException |
|
|
* @throws \fast\FuncException |
|
|
* @throws \think\db\exception\DataNotFoundException |
|
|
* @throws \think\db\exception\DataNotFoundException |
|
|
* @throws \think\db\exception\DbException |
|
|
* @throws \think\db\exception\DbException |
|
|
* @throws \think\db\exception\ModelNotFoundException |
|
|
* @throws \think\db\exception\ModelNotFoundException |
|
|
*/ |
|
|
*/ |
|
|
public function register($phone, $openid, $unionid) { |
|
|
public function register($phone, string $openid = '', string $unionid = '') |
|
|
|
|
|
{ |
|
|
|
|
|
|
|
|
$add = [ |
|
|
$add = [ |
|
|
'phone' => $phone, |
|
|
'phone' => $phone, |
|
|
|