点赞,收藏,消息,分类图标

This commit is contained in:
2025-11-25 15:39:16 +08:00
parent 48a77a09b0
commit 71c7d886cf
26 changed files with 1055 additions and 79 deletions
+43 -2
View File
@@ -3,7 +3,6 @@
namespace app\common\service;
use app\common\logic\AuthLogic;
use app\common\model\Corp;
use app\common\validate\UserValidate;
use app\common\traits\crud\CrudServiceTrait;
use app\common\model\User;
@@ -178,7 +177,7 @@ class UserService
/**
* 获取微信小程序用户信息
* 获取微信小程序用户信息(登录及获取手机号)
*/
public function wechatLogin(string $loginCode, string $phoneCode)
{
@@ -228,4 +227,46 @@ class UserService
$refreshToken = (new AuthLogic())->generateRefreshToken($user->id, 'info');
return array_merge($user->toArray(), ['access_token' => $token, 'is_bind' => true, 'refresh_token'=> $refreshToken, 'expires_in' => config('jwt.jwt_expiration')]);
}
/**
* 小程序登录
*/
public function miniappLogin(array $data)
{
$logic = new UserLogic();
$wechatService = new WechatService();
$wxinfo = $wechatService->xcxOpenid($data['code']);
// 用户信息
$user = User::firstOrCreate(
['openid' => $wxinfo['openid']],
['nickname' => '微信用户_'.$wxinfo['openid'], 'avatar' => getenv('MAIN_DOMAIN').'/avatar.png']
);
$jwt = new Jwt();
$JwtPayload = $logic->buildJwtPayload($user);
$JwtPayload['exp'] = $JwtPayload['exp'] + (86400 * 30);
$token = $jwt->generateToken($JwtPayload);
$refreshToken = (new AuthLogic())->generateRefreshToken($user->id, 'info');
return array_merge($user->toArray(), ['token' => $token, 'is_bind' => true, 'refresh_token'=> $refreshToken, 'expires_in' => config('jwt.jwt_expiration')]);
}
/**
* 获取手机号
*/
public function miniappPhoneNumber(array $data)
{
// 手机号
$wechatService = new WechatService();
$wxinfo = $wechatService->xcxPhoneNumber($data['phone_code']);
$uinfo = User::where('id', $data['user_id'])->first();
$uinfo->phone = $wxinfo['phone_info']['phoneNumber'];
$uinfo->save();
return $wxinfo;
}
}