commit 12184354482cf1b2f7eb57dd9cd281b099b04a30 Author: liuzhaobo Date: Mon Dec 4 16:04:51 2023 +0800 one diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..61064cb --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +vendor/ +composer.lock +.idea diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..6ceb153 --- /dev/null +++ b/LICENSE @@ -0,0 +1,20 @@ +The MIT License (MIT) + +Copyright (c) 2017 yansongda + +Permission is hereby granted, free of charge, to any person obtaining a copy of +this software and associated documentation files (the "Software"), to deal in +the Software without restriction, including without limitation the rights to +use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of +the Software, and to permit persons to whom the Software is furnished to do so, +subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS +FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR +COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER +IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..db2e516 --- /dev/null +++ b/README.md @@ -0,0 +1,96 @@ +该文档为 v2.x 版本 + +## 运行环境 + +- php >= 7.0 +- composer +- laravel || lumen >= 5.1 + +## 安装 + +```Shell +$ composer require yansongda/laravel-pay +``` + +### 添加 service provider(optional. if laravel < 5.5 || lumen) + +```PHP +// laravel < 5.5 +Yansongda\LaravelPay\PayServiceProvider::class, + +// lumen +$app->register(Yansongda\LaravelPay\PayServiceProvider::class); +``` + +### 添加 alias(optional. if laravel < 5.5) + +```PHP +'Pay' => Yansongda\LaravelPay\Facades\Pay::class, +``` + +### 配置文件 + +```Shell +$ php artisan vendor:publish --provider="Yansongda\LaravelPay\PayServiceProvider" --tag=laravel-pay +``` + +**lumen 用户请手动复制** + +随后,请在 `config` 文件夹中完善配置信息。 + +`.env` 文件里面配置 + +```PHP +# alipay 配置 +ALI_APP_ID= +ALI_PUBLIC_KEY= +ALI_PRIVATE_KEY= + +# wechat 配置 +WECHAT_APP_ID= +WECHAT_MINIAPP_ID= +WECHAT_APPID= +WECHAT_MCH_ID= +WECHAT_KEY= +``` + +## 使用方法 + +### 支付宝 + +```PHP +use Pay; + +$order = [ + 'out_trade_no' => time(), + 'total_amount' => '1', + 'subject' => 'test subject - 测试', +]; + +return Pay::alipay()->web($order); + +// 下面这个方法也可以 +// return Pay::web($order); +``` + +### 微信 + +```PHP +use Pay; + +$order = [ + 'out_trade_no' => time(), + 'body' => 'subject-测试', + 'total_fee' => '1', + 'openid' => 'onkVf1FjWS5SBIixxxxxxxxx', +]; + +$result = Pay::wechat()->mp($order); + +``` + +具体使用说明请传送至 [https://github.com/yansongda/pay](https://github.com/yansongda/pay) + +## License + +MIT diff --git a/composer.json b/composer.json new file mode 100644 index 0000000..b9f268a --- /dev/null +++ b/composer.json @@ -0,0 +1,35 @@ +{ + "name": "feizhiyi/pay", + "description": "专注 Alipay 和 WeChat 的 laravel 支付扩展包", + "keywords": ["alipay", "wechat", "pay", "laravel", "package"], + "support": { + "issues": "https://github.com/yansongda/laravel-pay/issues", + "source": "https://github.com/yansongda/laravel-pay" + }, + "authors": [ + { + "name": "feizhiyi", + "email": "me@feizhiyi.cn" + } + ], + "require": { + "illuminate/support": "^5.1 || ^6.0 || ^7.0 || ^8.0 || ^9.0 || ^10.0", + "yansongda/pay": "^2.0" + }, + "autoload": { + "psr-4": { + "Yansongda\\LaravelPay\\": "src" + } + }, + "extra": { + "laravel": { + "providers": [ + "Yansongda\\LaravelPay\\PayServiceProvider" + ], + "aliases": { + "Pay": "Yansongda\\LaravelPay\\Facades\\Pay" + } + } + }, + "license": "MIT" +} diff --git a/config/pay.php b/config/pay.php new file mode 100644 index 0000000..25504e9 --- /dev/null +++ b/config/pay.php @@ -0,0 +1,77 @@ + [ + // 支付宝分配的 APPID + 'app_id' => env('ALI_APP_ID', ''), + + // 支付宝异步通知地址 + 'notify_url' => '', + + // 支付成功后同步通知地址 + 'return_url' => '', + + // 阿里公共密钥,验证签名时使用 + 'ali_public_key' => env('ALI_PUBLIC_KEY', ''), + + // 自己的私钥,签名时使用 + 'private_key' => env('ALI_PRIVATE_KEY', ''), + + // 使用公钥证书模式,请配置下面两个参数,同时修改 ali_public_key 为以 .crt 结尾的支付宝公钥证书路径,如(./cert/alipayCertPublicKey_RSA2.crt) + // 应用公钥证书路径 + // 'app_cert_public_key' => './cert/appCertPublicKey.crt', + + // 支付宝根证书路径 + // 'alipay_root_cert' => './cert/alipayRootCert.crt', + + // optional,默认 warning;日志路径为:sys_get_temp_dir().'/logs/yansongda.pay.log' + 'log' => [ + 'file' => storage_path('logs/alipay.log'), + // 'level' => 'debug' + // 'type' => 'single', // optional, 可选 daily. + // 'max_file' => 30, + ], + + // optional,设置此参数,将进入沙箱模式 + // 'mode' => 'dev', + ], + + 'wechat' => [ + // 公众号 APPID + 'app_id' => env('WECHAT_APP_ID', ''), + + // 小程序 APPID + 'miniapp_id' => env('WECHAT_MINIAPP_ID', ''), + + // APP 引用的 appid + 'appid' => env('WECHAT_APPID', ''), + + // 微信支付分配的微信商户号 + 'mch_id' => env('WECHAT_MCH_ID', ''), + + // 微信支付异步通知地址 + 'notify_url' => '', + + // 微信支付签名秘钥 + 'key' => env('WECHAT_KEY', ''), + + // 客户端证书路径,退款、红包等需要用到。请填写绝对路径,linux 请确保权限问题。pem 格式。 + 'cert_client' => '', + + // 客户端秘钥路径,退款、红包等需要用到。请填写绝对路径,linux 请确保权限问题。pem 格式。 + 'cert_key' => '', + + // optional,默认 warning;日志路径为:sys_get_temp_dir().'/logs/yansongda.pay.log' + 'log' => [ + 'file' => storage_path('logs/wechat.log'), + // 'level' => 'debug' + // 'type' => 'single', // optional, 可选 daily. + // 'max_file' => 30, + ], + + // optional + // 'dev' 时为沙箱模式 + // 'hk' 时为东南亚节点 + // 'mode' => 'dev', + ], +]; diff --git a/src/Facades/Pay.php b/src/Facades/Pay.php new file mode 100644 index 0000000..a460e55 --- /dev/null +++ b/src/Facades/Pay.php @@ -0,0 +1,40 @@ + + */ + public function boot() + { + if ($this->app instanceof LaravelApplication && $this->app->runningInConsole()) { + $this->publishes([ + dirname(__DIR__).'/config/pay.php' => config_path('pay.php'), ], + 'laravel-pay' + ); + } elseif ($this->app instanceof LumenApplication) { + $this->app->configure('pay'); + } + } + + /** + * Register the service. + * + * @author yansongda + * + * @return void + */ + public function register() + { + $this->mergeConfigFrom(dirname(__DIR__).'/config/pay.php', 'pay'); + + $this->app->singleton('pay.alipay', function () { + return Pay::alipay(config('pay.alipay')); + }); + $this->app->singleton('pay.wechat', function () { + return Pay::wechat(config('pay.wechat')); + }); + } + + /** + * Get services. + * + * @author yansongda + * + * @return array + */ + public function provides() + { + return ['pay.alipay', 'pay.wechat']; + } +}