feat : wx login

This commit is contained in:
2024-11-27 15:20:46 +08:00
parent 9c175fdb78
commit 820b8d90dd
5 changed files with 170 additions and 5 deletions

View File

@@ -14,16 +14,31 @@ 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;
use GetUserInfoTrait,
WxMiniTrait;
public function handle()
/**
* @return array
* @throws ContainerExceptionInterface
* @throws NotFoundExceptionInterface
*/
public function handle(): array
{
$this->checkBindPhone($this->userId);
$wxPhone = $this->jsCodeGetPhoneNumber($this->request->input('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();
}