{"id":44419230,"url":"https://github.com/zhangv/union-pay","last_synced_at":"2026-02-12T09:09:33.481Z","repository":{"id":57090686,"uuid":"45740014","full_name":"zhangv/union-pay","owner":"zhangv","description":"simplest union pay（银联支付）","archived":false,"fork":false,"pushed_at":"2020-05-21T03:06:24.000Z","size":220,"stargazers_count":32,"open_issues_count":1,"forks_count":17,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-12-20T06:07:34.611Z","etag":null,"topics":["chinapay","pay","union","unionpay"],"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/zhangv.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-11-07T14:37:40.000Z","updated_at":"2025-01-11T06:39:31.000Z","dependencies_parsed_at":"2022-08-22T20:40:26.676Z","dependency_job_id":null,"html_url":"https://github.com/zhangv/union-pay","commit_stats":null,"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"purl":"pkg:github/zhangv/union-pay","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zhangv%2Funion-pay","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zhangv%2Funion-pay/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zhangv%2Funion-pay/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zhangv%2Funion-pay/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/zhangv","download_url":"https://codeload.github.com/zhangv/union-pay/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zhangv%2Funion-pay/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29362243,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-12T08:51:36.827Z","status":"ssl_error","status_checked_at":"2026-02-12T08:51:26.849Z","response_time":55,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["chinapay","pay","union","unionpay"],"created_at":"2026-02-12T09:09:32.573Z","updated_at":"2026-02-12T09:09:33.469Z","avatar_url":"https://github.com/zhangv.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# UnionPay - 银联支付\n[![Latest Stable Version](https://poser.pugx.org/zhangv/union-pay/v/stable)](https://packagist.org/packages/zhangv/union-pay)\n[![License](https://poser.pugx.org/zhangv/union-pay/license)](https://packagist.org/packages/zhangv/union-pay)\n[![Build Status](https://travis-ci.org/zhangv/union-pay.svg?branch=master)](https://travis-ci.org/zhangv/union-pay)\n[![codecov](https://codecov.io/gh/zhangv/union-pay/branch/master/graph/badge.svg)](https://codecov.io/gh/zhangv/union-pay)\n\nsimplest union pay - no dependency to any library, simple enough to let you hack.\n\n\n### Feature\n* [B2C - 在线网关支付](src/service/B2C.php)\n* [Wap - 手机网页支付（WAP支付）](src/service/Wap.php)\n* [App - App/控件支付](src/service/App.php)\n* [B2B - 企业网银支付](src/service/B2B.php)\n* [Direct - 无跳转标准版](src/service/Direct.php)\n* [Token - 无跳转Token版](src/service/Token.php)\n* [Qrcode - 二维码支付](src/service/Qrcode.php)\n* [DirectDebit - 代收](src/service/DirectDebit.php)\n* [Charge - 便民缴费产品](src/service/Charge.php)\n* 刷脸支付 （TODO）\n* 跨境电商海关申报（TODO）\n\n### Install\n```\ncomposer require zhangv/union-pay\n```\nor\n\nadd:\n\n```\n\"zhangv/union-pay\":\"0.8.12\"\n```\nin composer.json\n\n\n### Step 1: [config.php](demo/config.php) - 配置\n\n```php\nreturn ['test', [\n\t\t'version' =\u003e '5.1.0',\n\t\t'signMethod'=\u003e '01', //RSA\n\t\t'encoding' =\u003e 'UTF-8',\n\t\t'merId' =\u003e '700000000000001',\n\t\t'returnUrl' =\u003e 'http://dev.git.com/union-pay/demo/payreturn.php', //前台网关支付返回\n\t\t'notifyUrl' =\u003e 'http://dev.git.com/union-pay/demo/paynotify.php', //后台通知\n\t\t'frontFailUrl'   =\u003e 'http://dev.git.com/union-pay/demo/payfail.php',\n\t\t'refundnotifyUrl' =\u003e 'http://dev.git.com.com/union-pay/demo/refundnotify.php',\n\t\t'signCertPath' =\u003e dirname(__FILE__).'/../cert/acp_test_sign.pfx',\n\t\t'signCertPwd' =\u003e '000000', //签名证书密码\n\t\t'verifyCertPath' =\u003e dirname(__FILE__).'/../cert/acp_test_verify_sign.cer',  //v5.0.0 required\n\t\t'verifyRootCertPath' =\u003e dirname(__FILE__).'/../cert/acp_test_root.cer', //v5.1.0 required\n\t\t'verifyMiddleCertPath' =\u003e dirname(__FILE__).'/../cert/acp_test_middle.cer', //v5.1.0 required\n\t\t'encryptCertPath' =\u003e dirname(__FILE__).'/../cert/acp_test_enc.cer',\n\t\t'ifValidateCNName' =\u003e false, //正式环境设置为true\n\t]\n];\n```\n\n\n### Step 2: [pay.php](demo/b2c/pay.php) - 支付\n\n```php\n\u003c?php\n\nlist($mode,$config) = include './config.php';\n$unionPay = UnionPay::B2C($config,$mode);\n\n$payOrderNo = date('YmdHis');\n$amt = 1;\n\n$html = $unionPay-\u003epay($payOrderNo,$amt);\necho $html;\n```\n\n### Step 3: [payreturn.php](demo/payreturn.php) - 支付完成前台返回\n\n```php\n\u003c?php\n\nlist($mode,$config) = include './config.php';\n$unionPay = UnionPay::B2C($config,$mode);\n\n$postdata = $_REQUEST;\n$unionPay-\u003eonPayNotify($postdata,function($notifydata){\n\techo 'SUCCESS';\n\tvar_dump($notifydata);\n});\n```\n\n### Step 4: [paynotify.php](demo/paynotify.php) - 支付完成后台通知\n```php\n\u003c?php\nlist($mode,$config) = include './config.php';\n$unionPay = UnionPay::B2C($config,$mode);\n\n$notifyData = $_POST;\n$respCode = $notifyData['respCode'];\nif($respCode == '00'){\n\t$unionPay-\u003eonNotify($notifyData,'demoCallback');\n}elseif(in_array($respCode,['03','04','05'])){\n\t//后续需发起交易状态查询交易确定交易状态\n}else{\n\techo 'fail';\n}\n\n\nfunction demoCallback($notifyData){//自定义回调\n\tvar_dump($notifyData);\n\tprint('ok');\n}\n```\n\n### FAQ\n\n* 关于测试环境：有时候会报验签错误，一般的原因是证书错误或者参数拼接，如果确认二者没错，那么可能是因为你的商户号在银联测试环境中不生效，这种时候需要联系银联的客服。也可以直接用生产环境的证书测试交易，如果可以正常交易，那么测试交易这步也可以不做。\n* 关于测试用例：目前的测试用例依赖银联的测试环境，但并不是很稳定，经常会有返回错误的情况。后续可能考虑改成模拟数据。","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzhangv%2Funion-pay","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzhangv%2Funion-pay","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzhangv%2Funion-pay/lists"}