45 lines
1.2 KiB
PHP
45 lines
1.2 KiB
PHP
<?php
|
|
/**
|
|
* This service file is part of item.
|
|
*
|
|
* @author ctexthuang
|
|
* @contact ctexthuang@qq.com
|
|
*/
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Service\Api\User;
|
|
|
|
use App\Exception\ErrException;
|
|
use App\Service\Api\BaseService;
|
|
use App\Service\ServiceTrait\Api\GetUserInfoTrait;
|
|
use App\Service\ServiceTrait\Api\WxMiniTrait;
|
|
use Psr\Container\ContainerExceptionInterface;
|
|
use Psr\Container\NotFoundExceptionInterface;
|
|
|
|
class BindPhoneByWxService extends BaseService
|
|
{
|
|
use GetUserInfoTrait,
|
|
WxMiniTrait;
|
|
|
|
/**
|
|
* @return array
|
|
* @throws ContainerExceptionInterface
|
|
* @throws NotFoundExceptionInterface
|
|
*/
|
|
public function handle(): array
|
|
{
|
|
$this->checkBindPhone($this->userId);
|
|
|
|
$wxPhone = $this->jsCodeGetPhoneNumber($this->request->input('js_code'));
|
|
|
|
if (empty($wxPhone['phone_info']['purePhoneNumber'])) throw new ErrException('微信手机号查询失败,请联系人工客服处理');
|
|
|
|
$userInfo = $this->getUserInfo($this->userId);
|
|
|
|
$userInfo->phone = $wxPhone['phone_info']['purePhoneNumber'];
|
|
if (!$userInfo->save()) throw new ErrException('绑定手机号失败,请联系人工客服处理');
|
|
|
|
return $this->return->success();
|
|
}
|
|
} |