获取手机号
This commit is contained in:
@@ -164,7 +164,7 @@ class UserController extends BaseController
|
|||||||
public function miniappPhoneNumber(Request $request): Response
|
public function miniappPhoneNumber(Request $request): Response
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
$result = $this->service->miniappPhoneNumber($request->all());
|
$result = $this->service->miniappPhoneNumber($request->all(),$request);
|
||||||
return $this->success($result);
|
return $this->success($result);
|
||||||
} catch (\Throwable $th) {
|
} catch (\Throwable $th) {
|
||||||
return $this->error($th->getMessage());
|
return $this->error($th->getMessage());
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ use app\common\model\User;
|
|||||||
use app\common\logic\UserLogic;
|
use app\common\logic\UserLogic;
|
||||||
use app\common\utils\Jwt;
|
use app\common\utils\Jwt;
|
||||||
use support\exception\BusinessException;
|
use support\exception\BusinessException;
|
||||||
|
use support\Request;
|
||||||
|
|
||||||
class UserService
|
class UserService
|
||||||
{
|
{
|
||||||
@@ -237,12 +238,11 @@ class UserService
|
|||||||
$logic = new UserLogic();
|
$logic = new UserLogic();
|
||||||
$wechatService = new WechatService();
|
$wechatService = new WechatService();
|
||||||
$wxinfo = $wechatService->xcxOpenid($data['code']);
|
$wxinfo = $wechatService->xcxOpenid($data['code']);
|
||||||
var_dump($wxinfo);
|
|
||||||
|
|
||||||
// 用户信息
|
// 用户信息
|
||||||
$user = User::firstOrCreate(
|
$user = User::firstOrCreate(
|
||||||
['openid' => $wxinfo['openid']],
|
['openid' => $wxinfo['openid']],
|
||||||
['nickname' => '微信用户_'.$wxinfo['openid'], 'name' => '', 'avatar' => getenv('MAIN_DOMAIN').'/avatar.png']
|
['nickname' => '微信用户_'.$wxinfo['openid'], 'unionid' => $wxinfo['unionid'], 'name' => '', 'avatar' => getenv('MAIN_DOMAIN').'/avatar.png']
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
@@ -258,13 +258,13 @@ class UserService
|
|||||||
/**
|
/**
|
||||||
* 获取手机号
|
* 获取手机号
|
||||||
*/
|
*/
|
||||||
public function miniappPhoneNumber(array $data)
|
public function miniappPhoneNumber(array $data,Request $request)
|
||||||
{
|
{
|
||||||
// 手机号
|
// 手机号
|
||||||
$wechatService = new WechatService();
|
$wechatService = new WechatService();
|
||||||
$wxinfo = $wechatService->xcxPhoneNumber($data['phone_code']);
|
$wxinfo = $wechatService->xcxPhoneNumber($data['phone_code']);
|
||||||
|
|
||||||
$uinfo = User::where('id', $data['user_id'])->first();
|
$uinfo = User::where('id', $request->user->uid)->first();
|
||||||
$uinfo->phone = $wxinfo['phone_info']['phoneNumber'];
|
$uinfo->phone = $wxinfo['phone_info']['phoneNumber'];
|
||||||
$uinfo->save();
|
$uinfo->save();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user