feat: 微信登录调整

This commit is contained in:
苟川东 2025-04-22 22:16:51 +08:00
parent 5ca1cf83f2
commit fb0c43e309

View File

@ -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);