feat: 微信登录兼容 "w7corp/easywechat": "^6.17"

This commit is contained in:
gcd 2025-04-22 23:07:30 +08:00
parent fb0c43e309
commit 3bc66da95a

View File

@ -86,16 +86,27 @@ class WorkerService extends BaseService
}
/**
* 解密微信手机号
* 通过 code 获取用户手机号
* @param string $code
* @return array
*/
private function code2PhoneNumberInfo(string $code): array
{
$app = $this->getMiniProgramApp();
$phoneInfo = $app->getClient()->postJson('wxa/business/getuserphonenumber', ['code' => $code]);
return $phoneInfo->toArray();
}
/**
* 获取用户手机号
* @param string $code
* @return mixed
*/
public function getPhoneNumber(string $code)
{
$app = $this->getMiniProgramApp();
$app->phone_number->getUserPhoneNumber(string $code);
$phoneInfo = $app->getClient()->postJson('wxa/business/getuserphonenumber', ['code' => $code]);
dd($phoneInfo);
//通过 code 获取手机号信息
$phoneInfo = $this->code2PhoneNumberInfo($code);
if (empty($phoneInfo)) {
$this->apiError('获取手机号失败', 0, $phoneInfo);