diff --git a/README.md b/README.md index eab2ad6cac85221825ffd7f3ddc3843a0edea3ed..be1cd123881dd0b07d6f0203c17906482a75e8d5 100644 --- a/README.md +++ b/README.md @@ -10,13 +10,15 @@ License

+**!注意:v1.x 版本将不做新功能开发,只进行 bug 维护!请大家尽快迁移到 v2 版本!** + 开发了多次支付宝与微信支付后,很自然产生一种反感,惰性又来了,想在网上找相关的轮子,可是一直没有找到一款自己觉得逞心如意的,要么使用起来太难理解,要么文件结构太杂乱,只有自己撸起袖子干了。 **说明,请先熟悉支付宝说明文档!!** 欢迎 Star,欢迎 PR! -laravel 扩展包请 [传送至这里](https://github.com/yansongda/laravel-pay) +laravel 扩展包请 [https://github.com/yansongda/laravel-pay](https://github.com/yansongda/laravel-pay) ## 特点 - 命名不那么乱七八糟 @@ -117,7 +119,7 @@ SDK 中对应的 driver 和 gateway 如下表所示: ## 安装 ```shell -composer require yansongda/pay +composer require "yansongda/pay:^1.0" ``` ## 使用说明 diff --git a/src/Gateways/Alipay/Alipay.php b/src/Gateways/Alipay/Alipay.php index 6d829fda714f494e13acd9b109ee9ab3139da3d9..2761e4eab1e38d1b9ed1930e0dad322d4802fbe2 100644 --- a/src/Gateways/Alipay/Alipay.php +++ b/src/Gateways/Alipay/Alipay.php @@ -15,7 +15,7 @@ abstract class Alipay implements GatewayInterface /** * @var string */ - protected $gateway = 'https://openapi.alipay.com/gateway.do'.'?charset=utf-8'; + protected $gateway = 'https://openapi.alipay.com/gateway.do?charset=UTF-8'; /** * alipay global config params. @@ -50,7 +50,7 @@ abstract class Alipay implements GatewayInterface 'app_id' => $this->user_config->get('app_id'), 'method' => '', 'format' => 'JSON', - 'charset' => 'utf-8', + 'charset' => 'UTF-8', 'sign_type' => 'RSA2', 'version' => '1.0', 'return_url' => $this->user_config->get('return_url', ''), @@ -194,11 +194,11 @@ abstract class Alipay implements GatewayInterface protected function buildPayHtml() { $sHtml = "
"; - while (list($key, $val) = each($this->config)) { + foreach ($this->config as $key => $val) { $val = str_replace("'", ''', $val); $sHtml .= ""; } - $sHtml .= "
"; + $sHtml .= ""; $sHtml .= ""; return $sHtml; @@ -220,6 +220,10 @@ abstract class Alipay implements GatewayInterface $this->config['method'] = $method; $this->config['sign'] = $this->getSign(); + $this->config = array_filter($this->config, function ($value) { + return $value !== '' && !is_null($value); + }); + $method = str_replace('.', '_', $method).'_response'; $data = json_decode($this->post($this->gateway, $this->config), true); diff --git a/src/Gateways/Alipay/AppGateway.php b/src/Gateways/Alipay/AppGateway.php index b1861bef7309eb3be164ab56b63ef195c653cc71..1e2940b75016301cfd72ceb18b5011e56a0f3005 100644 --- a/src/Gateways/Alipay/AppGateway.php +++ b/src/Gateways/Alipay/AppGateway.php @@ -41,6 +41,16 @@ class AppGateway extends Alipay { parent::pay($config_biz); + + /** + * 支付宝支付报错 alin10146,原因支付宝不允许传空值,如return_url或notify_url有时为空,造成签名错误 + * @author kingofzihua + * @link https://github.com/yansongda/pay/issues/119#ref-commit-bb4abeb + */ + $this->config = array_filter($this->config, function ($value) { + return $value !== '' && !is_null($value); + }); + return http_build_query($this->config); } } diff --git a/src/Gateways/Wechat/Wechat.php b/src/Gateways/Wechat/Wechat.php index f63bb7403f244e0a3fd609e457d16338f93fa2a1..9b1d04ab8adc36a279da60bbc8ea79257e147837 100644 --- a/src/Gateways/Wechat/Wechat.php +++ b/src/Gateways/Wechat/Wechat.php @@ -92,8 +92,12 @@ abstract class Wechat implements GatewayInterface */ public function refund($config_biz = []) { + if (isset($config_biz['miniapp'])) { + $this->config['appid'] = $this->user_config->get('miniapp_id'); + unset($config_biz['miniapp']); + } + $this->config = array_merge($this->config, $config_biz); - $this->config['op_user_id'] = isset($this->config['op_user_id']) ?: $this->user_config->get('mch_id', ''); $this->unsetTradeTypeAndNotifyUrl();