From 7605f4370a92ea4811cc5016d4709ef3d545f51c Mon Sep 17 00:00:00 2001 From: ning <1298951+c4ys@users.noreply.github.com> Date: Tue, 31 Aug 2021 15:32:54 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=AF=E6=8C=81=E6=94=AF=E4=BB=98=E5=AE=9D?= =?UTF-8?q?=E6=B2=99=E7=AE=B1=E6=A8=A1=E5=BC=8F=20(#224)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 支持支付宝沙箱模式 * 支持支付宝沙箱模式 --- README_CN.md | 3 +++ src/Providers/Alipay.php | 22 +++++++++++++++++----- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/README_CN.md b/README_CN.md index 34ba30f..2885224 100644 --- a/README_CN.md +++ b/README_CN.md @@ -252,6 +252,9 @@ $config = [ // 确保这里的值与你在服务后台绑定的地址值一致 // 这个键名还能像官方文档那样叫做 'redirect_url' 'redirect' => 'http://localhost/socialite/callback.php', + + // 沙箱模式接入地址见 https://opendocs.alipay.com/open/220/105337#%E5%85%B3%E4%BA%8E%E6%B2%99%E7%AE%B1 + 'sandbox' => false, ] ... ]; diff --git a/src/Providers/Alipay.php b/src/Providers/Alipay.php index 99ed11b..9b91867 100644 --- a/src/Providers/Alipay.php +++ b/src/Providers/Alipay.php @@ -12,15 +12,27 @@ class Alipay extends Base { public const NAME = 'alipay'; protected string $baseUrl = 'https://openapi.alipay.com/gateway.do'; + protected string $authUrl = 'https://openauth.alipay.com/oauth2/publicAppAuthorize.htm'; protected array $scopes = ['auth_user']; protected string $apiVersion = '1.0'; protected string $signType = 'RSA2'; protected string $postCharset = 'UTF-8'; protected string $format = 'json'; + protected bool $sandbox = false; + + public function __construct(array $config) + { + parent::__construct($config); + $this->sandbox = $this->config->get('sandbox', false); + if ($this->sandbox) { + $this->baseUrl = 'https://openapi.alipaydev.com/gateway.do'; + $this->authUrl = 'https://openauth.alipaydev.com/oauth2/publicAppAuthorize.htm'; + } + } protected function getAuthUrl(): string { - return $this->buildAuthUrlFromBase('https://openauth.alipay.com/oauth2/publicAppAuthorize.htm'); + return $this->buildAuthUrlFromBase($this->authUrl); } protected function getTokenUrl(): string @@ -29,7 +41,7 @@ protected function getTokenUrl(): string } /** - * @param string $token + * @param string $token * * @return array * @throws \Overtrue\Socialite\Exceptions\InvalidArgumentException @@ -78,7 +90,7 @@ protected function mapUserToObject(array $user): User } /** - * @param string $code + * @param string $code * * @return array * @throws \GuzzleHttp\Exception\GuzzleException @@ -205,8 +217,8 @@ protected function signWithSHA256RSA(string $signContent, string $key) } /** - * @param array $params - * @param bool $urlencode + * @param array $params + * @param bool $urlencode * @param array|string[] $except * * @return string