{"id":14966501,"url":"https://github.com/guanguans/yii-pay","last_synced_at":"2025-04-05T20:08:17.861Z","repository":{"id":39789054,"uuid":"247638891","full_name":"guanguans/yii-pay","owner":"guanguans","description":"适配于 Yii 的 alipay 和 wechat 的支付扩展包","archived":false,"fork":false,"pushed_at":"2025-01-29T03:32:14.000Z","size":458,"stargazers_count":49,"open_issues_count":0,"forks_count":4,"subscribers_count":2,"default_branch":"1.x","last_synced_at":"2025-04-05T00:32:48.092Z","etag":null,"topics":["alipay","pay","wechat","yii"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/guanguans.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":".github/CONTRIBUTING.md","funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":".github/SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"patreon":"guanguans","custom":"https://www.guanguans.cn/images/wechat.jpeg"}},"created_at":"2020-03-16T07:35:17.000Z","updated_at":"2025-01-29T03:32:11.000Z","dependencies_parsed_at":"2025-02-13T13:11:41.437Z","dependency_job_id":"5cb6efa7-78ef-4baa-b085-d28d37e1ab42","html_url":"https://github.com/guanguans/yii-pay","commit_stats":null,"previous_names":[],"tags_count":12,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/guanguans%2Fyii-pay","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/guanguans%2Fyii-pay/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/guanguans%2Fyii-pay/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/guanguans%2Fyii-pay/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/guanguans","download_url":"https://codeload.github.com/guanguans/yii-pay/tar.gz/refs/heads/1.x","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247393570,"owners_count":20931813,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["alipay","pay","wechat","yii"],"created_at":"2024-09-24T13:36:29.504Z","updated_at":"2025-04-05T20:08:17.838Z","avatar_url":"https://github.com/guanguans.png","language":"PHP","funding_links":["https://patreon.com/guanguans","https://www.guanguans.cn/images/wechat.jpeg"],"categories":[],"sub_categories":[],"readme":"\u003ch1 align=\"center\"\u003eyii-pay\u003c/h1\u003e\n\n\u003e 基于 [yansongda/pay](https://github.com/yansongda/pay) 开发的适配于 Yii 的 alipay 和 wechat 的支付扩展包。\n\n\u003cp align=\"center\"\u003e\u003cimg src=\"./docs/usage.png\"\u003e\u003c/p\u003e\n\n[![tests](https://github.com/guanguans/yii-pay/actions/workflows/run-tests.yml/badge.svg)](https://github.com/guanguans/yii-pay/actions/workflows/run-tests.yml)\n[![check \u0026 fix styling](https://github.com/guanguans/yii-pay/actions/workflows/php-cs-fixer.yml/badge.svg)](https://github.com/guanguans/yii-pay/actions/workflows/php-cs-fixer.yml)\n[![codecov](https://codecov.io/gh/guanguans/yii-pay/branch/master/graph/badge.svg)](https://codecov.io/gh/guanguans/yii-pay)\n[![Latest Stable Version](https://poser.pugx.org/guanguans/yii-pay/v/stable)](https://packagist.org/packages/guanguans/yii-pay)\n[![Total Downloads](https://poser.pugx.org/guanguans/yii-pay/downloads)](https://packagist.org/packages/guanguans/yii-pay)\n[![License](https://poser.pugx.org/guanguans/yii-pay/license)](https://packagist.org/packages/guanguans/yii-pay)\n\n## 环境要求\n\n* Yii \u003e= 2.0\n\n## 安装\n\n```shell\n$ composer require guanguans/yii-pay --prefer-dist -v\n```\n\n## 配置\n\nYii2 配置文件 `config/main.php` 的 components 中添加:\n\n```php\n'components' =\u003e [\n\t// ...\n\t'pay' =\u003e [\n        'class' =\u003e 'Guanguans\\YiiPay\\Pay',\n        // 'defaultDriver' =\u003e 'wechat', // 默认支付驱动[wechat, alipay] 若配置为 wechat：`Yii::$app-\u003epay-\u003ewap();` 等效于 `Yii::$app-\u003epay-\u003ewechat-\u003ewap();` \n        'wechatOptions' =\u003e [\n            'appid' =\u003e 'wxb3fxxxxxxxxxxx', // APP APPID\n            'app_id' =\u003e 'wxb3fxxxxxxxxxxx', // 公众号 APPID\n            'miniapp_id' =\u003e 'wxb3fxxxxxxxxxxx', // 小程序 APPID\n            'mch_id' =\u003e '14577xxxx',\n            'key' =\u003e 'mF2suE9sU6Mk1Cxxxxxxxxxxx',\n            'notify_url' =\u003e 'http://xxxxxx.cn/notify.php',\n            'cert_client' =\u003e './cert/apiclient_cert.pem', // optional，退款等情况时用到\n            'cert_key' =\u003e './cert/apiclient_key.pem',// optional，退款等情况时用到\n            'log' =\u003e [ // optional\n                'file' =\u003e './logs/wechat.log',\n                'level' =\u003e 'info', // 建议生产环境等级调整为 info，开发环境为 debug\n                'type' =\u003e 'single', // optional, 可选 daily.\n                'max_file' =\u003e 30, // optional, 当 type 为 daily 时有效，默认 30 天\n            ],\n            'http' =\u003e [ // optional\n                'timeout' =\u003e 5.0,\n                'connect_timeout' =\u003e 5.0,\n                // 更多配置项请参考 [Guzzle](https://guzzle-cn.readthedocs.io/zh_CN/latest/request-options.html)\n            ],\n            // 'mode' =\u003e 'dev', // optional, dev/hk;当为 `hk` 时，为香港 gateway。\n        ],\n        'alipayOptions' =\u003e [\n            'app_id' =\u003e '2016082000295641',\n            'notify_url' =\u003e 'http://xxxxxx.cn/notify.php',\n            'return_url' =\u003e 'http://xxxxxx.cn/return.php',\n            'ali_public_key' =\u003e 'MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAuWJKrQ6SWvS6niI+4vEVZiYfjkCfLQfoFI2nCp9ZLDS42QtiL4Ccyx8scgc3nhVwmVRte8f57TFvGhvJD0upT4O5O/lRxmTjechXAorirVdAODpOu0mFfQV9y/T9o9hHnU+VmO5spoVb3umqpq6D/Pt8p25Yk852/w01VTIczrXC4QlrbOEe3sr1E9auoC7rgYjjCO6lZUIDjX/oBmNXZxhRDrYx4Yf5X7y8FRBFvygIE2FgxV4Yw+SL3QAa2m5MLcbusJpxOml9YVQfP8iSurx41PvvXUMo49JG3BDVernaCYXQCoUJv9fJwbnfZd7J5YByC+5KM4sblJTq7bXZWQIDAQAB',\n            // 加密方式： **RSA2**  \n            'private_key' =\u003e 'MIIEpAIBAAKCAQEAs6+F2leOgOrvj9jTeDhb5q46GewOjqLBlGSs/bVL4Z3fMr3p+Q1Tux/6uogeVi/eHd84xvQdfpZ87A1SfoWnEGH5z15yorccxSOwWUI+q8gz51IWqjgZxhWKe31BxNZ+prnQpyeMBtE25fXp5nQZ/pftgePyUUvUZRcAUisswntobDQKbwx28VCXw5XB2A+lvYEvxmMv/QexYjwKK4M54j435TuC3UctZbnuynSPpOmCu45ZhEYXd4YMsGMdZE5/077ZU1aU7wx/gk07PiHImEOCDkzqsFo0Buc/knGcdOiUDvm2hn2y1XvwjyFOThsqCsQYi4JmwZdRa8kvOf57nwIDAQABAoIBAQCw5QCqln4VTrTvcW+msB1ReX57nJgsNfDLbV2dG8mLYQemBa9833DqDK6iynTLNq69y88ylose33o2TVtEccGp8Dqluv6yUAED14G6LexS43KtrXPgugAtsXE253ZDGUNwUggnN1i0MW2RcMqHdQ9ORDWvJUCeZj/AEafgPN8AyiLrZeL07jJz/uaRfAuNqkImCVIarKUX3HBCjl9TpuoMjcMhz/MsOmQ0agtCatO1eoH1sqv5Odvxb1i59c8Hvq/mGEXyRuoiDo05SE6IyXYXr84/Nf2xvVNHNQA6kTckj8shSi+HGM4mO1Y4Pbb7XcnxNkT0Inn6oJMSiy56P+CpAoGBAO1O+5FE1ZuVGuLb48cY+0lHCD+nhSBd66B5FrxgPYCkFOQWR7pWyfNDBlmO3SSooQ8TQXA25blrkDxzOAEGX57EPiipXr/hy5e+WNoukpy09rsO1TMsvC+v0FXLvZ+TIAkqfnYBgaT56ku7yZ8aFGMwdCPL7WJYAwUIcZX8wZ3dAoGBAMHWplAqhe4bfkGOEEpfs6VvEQxCqYMYVyR65K0rI1LiDZn6Ij8fdVtwMjGKFSZZTspmsqnbbuCE/VTyDzF4NpAxdm3cBtZACv1Lpu2Om+aTzhK2PI6WTDVTKAJBYegXaahBCqVbSxieR62IWtmOMjggTtAKWZ1P5LQcRwdkaB2rAoGAWnAPT318Kp7YcDx8whOzMGnxqtCc24jvk2iSUZgb2Dqv+3zCOTF6JUsV0Guxu5bISoZ8GdfSFKf5gBAo97sGFeuUBMsHYPkcLehM1FmLZk1Q+ljcx3P1A/ds3kWXLolTXCrlpvNMBSN5NwOKAyhdPK/qkvnUrfX8sJ5XK2H4J8ECgYAGIZ0HIiE0Y+g9eJnpUFelXvsCEUW9YNK4065SD/BBGedmPHRC3OLgbo8X5A9BNEf6vP7fwpIiRfKhcjqqzOuk6fueA/yvYD04v+Da2MzzoS8+hkcqF3T3pta4I4tORRdRfCUzD80zTSZlRc/h286Y2eTETd+By1onnFFe2X01mwKBgQDaxo4PBcLL2OyVT5DoXiIdTCJ8KNZL9+kV1aiBuOWxnRgkDjPngslzNa1bK+klGgJNYDbQqohKNn1HeFX3mYNfCUpuSnD2Yag53Dd/1DLO+NxzwvTu4D6DCUnMMMBVaF42ig31Bs0jI3JQZVqeeFzSET8fkoFopJf3G6UXlrIEAQ==',\n            // 使用公钥证书模式，请配置下面两个参数，同时修改ali_public_key为以.crt结尾的支付宝公钥证书路径，如（./cert/alipayCertPublicKey_RSA2.crt）\n            // 'app_cert_public_key' =\u003e './cert/appCertPublicKey.crt', //应用公钥证书路径\n            // 'alipay_root_cert' =\u003e './cert/alipayRootCert.crt', //支付宝根证书路径\n            'log' =\u003e [ // optional\n                'file' =\u003e './logs/alipay.log',\n                'level' =\u003e 'info', // 建议生产环境等级调整为 info，开发环境为 debug\n                'type' =\u003e 'single', // optional, 可选 daily.\n                'max_file' =\u003e 30, // optional, 当 type 为 daily 时有效，默认 30 天\n            ],\n            'http' =\u003e [ // optional\n                'timeout' =\u003e 5.0,\n                'connect_timeout' =\u003e 5.0,\n                // 更多配置项请参考 [Guzzle](https://guzzle-cn.readthedocs.io/zh_CN/latest/request-options.html)\n            ],\n            // 'mode' =\u003e 'dev', // optional,设置此参数，将进入沙箱模式\n        ],\n    ],\n\t// ...\n]\n```\n\n## 使用\n\n### 获取 alipay 实例\n\n```php\nYii::$app-\u003epay-\u003egetAlipay();\n// or\nYii::$app-\u003epay-\u003ealipay;\n```\n\n### 支付宝使用示例，更多详细文档请参考 [yansongda/pay](https://github.com/yansongda/pay)\n\n```php\n\u003c?php\n\nnamespace frontend\\controllers;\n\nuse Yii;\n\nclass PayController extends Controller\n{\n    public function actionIndex()\n    {\n        $order = [\n            'out_trade_no' =\u003e time(),\n            'total_amount' =\u003e '1',\n            'subject' =\u003e 'test subject - 测试',\n        ];\n\n        $alipay = Yii::$app-\u003epay-\u003egetAlipay()-\u003eweb($order); // 电脑支付\n        // $alipay = Yii::$app-\u003epay-\u003egetAlipay()-\u003ewap($order); // 手机网站支付\n        // $alipay = Yii::$app-\u003epay-\u003egetAlipay()-\u003eapp($order); // APP 支付\n        // $alipay = Yii::$app-\u003epay-\u003egetAlipay()-\u003epos($order); // 刷卡支付\n        // $alipay = Yii::$app-\u003epay-\u003egetAlipay()-\u003escan($order); // 扫码支付\n        // $alipay = Yii::$app-\u003epay-\u003egetAlipay()-\u003etransfer($order); // 帐户转账\n        // $alipay = Yii::$app-\u003epay-\u003egetAlipay()-\u003emini($order); // 小程序支付\n\n        return $alipay-\u003esend();\n    }\n\n    public function actionReturn()\n    {\n        $data = Yii::$app-\u003epay-\u003egetAlipay()-\u003everify();\n\n        // 订单号：$data-\u003eout_trade_no\n        // 支付宝交易号：$data-\u003etrade_no\n        // 订单总金额：$data-\u003etotal_amount\n    }\n\n    public function actionNotify()\n    {\n        $alipay = Yii::$app-\u003epay-\u003egetAlipay();\n    \n        try{\n            $data = $alipay-\u003everify();\n\n            // 请自行对 trade_status 进行判断及其它逻辑进行判断，在支付宝的业务通知中，只有交易通知状态为 TRADE_SUCCESS 或 TRADE_FINISHED 时，支付宝才会认定为买家付款成功。\n            // 1、商户需要验证该通知数据中的out_trade_no是否为商户系统中创建的订单号；\n            // 2、判断total_amount是否确实为该订单的实际金额（即商户订单创建时的金额）；\n            // 3、校验通知中的seller_id（或者seller_email) 是否为out_trade_no这笔单据的对应的操作方（有的时候，一个商户可能有多个seller_id/seller_email）；\n            // 4、验证app_id是否为该商户本身。\n            // 5、其它业务逻辑情况\n\n            Yii::$app-\u003epay-\u003egetLog()-\u003edebug('Alipay notify', $data-\u003eall());\n        } catch (\\Exception $e) {\n            // $e-\u003egetMessage();\n        }\n\n        return $alipay-\u003esuccess()-\u003esend();\n    }\n}\n```\n\n### 获取微信实例\n\n```php\nYii::$app-\u003epay-\u003egetWechat();\n// or\nYii::$app-\u003epay-\u003ewechat;\n```\n\n### 微信使用示例，更多详细文档请参考 [yansongda/pay](https://github.com/yansongda/pay)\n\n```php\n\u003c?php\n\nnamespace frontend\\controllers;\n\nuse Yii;\n\nclass PayController extends Controller\n{\n    public function actionIndex()\n    {\n        $order = [\n            'out_trade_no' =\u003e time(),\n            'total_fee' =\u003e '1', // **单位：分**\n            'body' =\u003e 'test body - 测试',\n            'openid' =\u003e 'onkVf1FjWS5SBIixxxxxxx',\n        ];\n\n        $pay = Yii::$app-\u003epay-\u003egetWechat()-\u003emp($order); // 公众号支付\n        // $pay = Yii::$app-\u003epay-\u003egetWechat()-\u003eminiapp($order); // 小程序支付\n        // $pay = Yii::$app-\u003epay-\u003egetWechat()-\u003ewap($order); // H5 支付\n        // $pay = Yii::$app-\u003epay-\u003egetWechat()-\u003escan($order); // 扫码支付\n        // $pay = Yii::$app-\u003epay-\u003egetWechat()-\u003epos($order); // 刷卡支付\n        // $pay = Yii::$app-\u003epay-\u003egetWechat()-\u003eapp($order); // APP 支付\n        // $pay = Yii::$app-\u003epay-\u003egetWechat()-\u003etransfer($order); // 企业付款\n        // $pay = Yii::$app-\u003epay-\u003egetWechat()-\u003eredpack($order); // 普通红包\n        // $pay = Yii::$app-\u003epay-\u003egetWechat()-\u003egroupRedpack($order); // 分裂红包\n\n        // $pay-\u003eappId\n        // $pay-\u003etimeStamp\n        // $pay-\u003enonceStr\n        // $pay-\u003epackage\n        // $pay-\u003esignType\n    }\n\n    public function actionNotify()\n    {\n        $pay = Yii::$app-\u003epay-\u003egetWechat();\n\n        try{\n            $data = $pay-\u003everify();\n            \n            Yii::$app-\u003epay-\u003egetLog()-\u003edebug('Alipay notify', $data-\u003eall());\n        } catch (\\Exception $e) {\n            // $e-\u003egetMessage();\n        }\n        \n        return $pay-\u003esuccess()-\u003esend();\n    }\n}\n```\n\n## 测试\n\n```shell\n$ composer test\n```\n\n## 相关链接\n\n* [https://github.com/yansongda/pay](https://github.com/yansongda/pay)，[yansongda](https://github.com/yansongda)\n\n## License\n\n[MIT](LICENSE)","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fguanguans%2Fyii-pay","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fguanguans%2Fyii-pay","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fguanguans%2Fyii-pay/lists"}