Skip to content

Commit

Permalink
支持支付宝沙箱模式 (#224)
Browse files Browse the repository at this point in the history
* 支持支付宝沙箱模式

* 支持支付宝沙箱模式
  • Loading branch information
c4ys authored Aug 31, 2021
1 parent e331d3e commit 7605f43
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
3 changes: 3 additions & 0 deletions README_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -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,
]
...
];
Expand Down
22 changes: 17 additions & 5 deletions src/Providers/Alipay.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -29,7 +41,7 @@ protected function getTokenUrl(): string
}

/**
* @param string $token
* @param string $token
*
* @return array
* @throws \Overtrue\Socialite\Exceptions\InvalidArgumentException
Expand Down Expand Up @@ -78,7 +90,7 @@ protected function mapUserToObject(array $user): User
}

/**
* @param string $code
* @param string $code
*
* @return array
* @throws \GuzzleHttp\Exception\GuzzleException
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 7605f43

Please sign in to comment.