diff --git a/README.md b/README.md index 707b8d447..cb8a9e39a 100644 --- a/README.md +++ b/README.md @@ -51,6 +51,7 @@ QQ交流群:690027516 - 刷卡支付 - 扫码支付 - 账户转账 +- 小程序支付 | method | 描述 | | :-------: | :-------: | @@ -60,6 +61,7 @@ QQ交流群:690027516 | pos | 刷卡支付 | | scan | 扫码支付 | | transfer | 帐户转账 | +| mini | 小程序支付 | ### 2、微信 - 公众号支付 diff --git a/src/Gateways/Alipay.php b/src/Gateways/Alipay.php index 632252fa6..e6621f782 100644 --- a/src/Gateways/Alipay.php +++ b/src/Gateways/Alipay.php @@ -21,6 +21,7 @@ * @method Collection transfer(array $config) 帐户转账 * @method Response wap(array $config) 手机网站支付 * @method Response web(array $config) 电脑支付 + * @method Collection mini(array $config) 小程序支付 */ class Alipay implements GatewayApplicationInterface { diff --git a/src/Gateways/Alipay/MiniGateway.php b/src/Gateways/Alipay/MiniGateway.php new file mode 100644 index 000000000..92b9f849e --- /dev/null +++ b/src/Gateways/Alipay/MiniGateway.php @@ -0,0 +1,53 @@ + + * + * @param string $endpoint + * @param array $payload + * + * @throws \Yansongda\Pay\Exceptions\GatewayException + * @throws \Yansongda\Pay\Exceptions\InvalidArgumentException + * @throws \Yansongda\Pay\Exceptions\InvalidConfigException + * @throws \Yansongda\Pay\Exceptions\InvalidSignException + * + * @link https://docs.alipay.com/mini/introduce/pay + * + * @return Collection + */ + public function pay($endpoint, array $payload): Collection + { + if (empty(json_decode($payload['biz_content'], true)['buyer_id'])) { + throw new \Yansongda\Pay\Exceptions\InvalidArgumentException('buyer_id required'); + } + + $payload['method'] = $this->getMethod(); + $payload['sign'] = Support::generateSign($payload); + + Events::dispatch(Events::PAY_STARTED, new Events\PayStarted('Alipay', 'Mini', $endpoint, $payload)); + + return Support::requestApi($payload); + } + + /** + * Get method config. + * + * @author yansongda + * + * @return string + */ + protected function getMethod(): string + { + return 'alipay.trade.create'; + } +}