From fb0c43e3096b47cd5abe7de5da5ef9f25e00ac7b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=8B=9F=E5=B7=9D=E4=B8=9C?= Date: Tue, 22 Apr 2025 22:16:51 +0800 Subject: [PATCH 1/3] =?UTF-8?q?feat:=20=E5=BE=AE=E4=BF=A1=E7=99=BB?= =?UTF-8?q?=E5=BD=95=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/services/WorkerService.php | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/application/services/WorkerService.php b/application/services/WorkerService.php index a98feb5..23cf5f2 100644 --- a/application/services/WorkerService.php +++ b/application/services/WorkerService.php @@ -3,9 +3,8 @@ namespace app\services; use app\common\library\Token; -use EasyWeChat\Factory; use EasyWeChat\Kernel\Exceptions\InvalidConfigException; -use EasyWeChat\MiniProgram\Application; +use EasyWeChat\MiniApp\Application; class WorkerService extends BaseService { @@ -47,8 +46,9 @@ class WorkerService extends BaseService { $app = $this->getMiniProgramApp(); try { - $info = $app->auth->session($code); - } catch (InvalidConfigException $e) { + $utils = $app->getUtils(); + $info = $utils->codeToSession($code); + } catch (\Exception $e) { $this->apiError('登录失败', $e); } @@ -82,7 +82,7 @@ class WorkerService extends BaseService 'app_id' => config('mini_program.app_id'), 'secret' => config('mini_program.secret'), ]; - return Factory::miniProgram($config); + return new Application($config); } /** @@ -92,8 +92,10 @@ class WorkerService extends BaseService */ public function getPhoneNumber(string $code) { - //getPhoneNumber 方法通过魔术方法 __call 获取 - $phoneInfo = $this->getMiniProgramApp()->getPhoneNumber($code); + $app = $this->getMiniProgramApp(); + $app->phone_number->getUserPhoneNumber(string $code); + $phoneInfo = $app->getClient()->postJson('wxa/business/getuserphonenumber', ['code' => $code]); + dd($phoneInfo); if (empty($phoneInfo)) { $this->apiError('获取手机号失败', 0, $phoneInfo); From 3bc66da95a34f735850b2067210e0481edc9a4cc Mon Sep 17 00:00:00 2001 From: gcd Date: Tue, 22 Apr 2025 23:07:30 +0800 Subject: [PATCH 2/3] =?UTF-8?q?feat:=20=E5=BE=AE=E4=BF=A1=E7=99=BB?= =?UTF-8?q?=E5=BD=95=E5=85=BC=E5=AE=B9=20"w7corp/easywechat":=20"^6.17"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/services/WorkerService.php | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/application/services/WorkerService.php b/application/services/WorkerService.php index 23cf5f2..b01c90c 100644 --- a/application/services/WorkerService.php +++ b/application/services/WorkerService.php @@ -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); From 97a8e526daef0de5c2b0077074abb9b935c48bc8 Mon Sep 17 00:00:00 2001 From: gcd Date: Tue, 22 Apr 2025 23:09:16 +0800 Subject: [PATCH 3/3] =?UTF-8?q?feat:=20=E5=BE=AE=E4=BF=A1=E7=99=BB?= =?UTF-8?q?=E5=BD=95=E5=85=BC=E5=AE=B9=20"w7corp/easywechat":=20"^6.17"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/services/WorkerService.php | 1 - 1 file changed, 1 deletion(-) diff --git a/application/services/WorkerService.php b/application/services/WorkerService.php index b01c90c..80587f6 100644 --- a/application/services/WorkerService.php +++ b/application/services/WorkerService.php @@ -3,7 +3,6 @@ namespace app\services; use app\common\library\Token; -use EasyWeChat\Kernel\Exceptions\InvalidConfigException; use EasyWeChat\MiniApp\Application; class WorkerService extends BaseService