PHPackages                             xiaowei007/payment-v2 - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Payment Processing](/categories/payments)
4. /
5. xiaowei007/payment-v2

ActiveLibrary[Payment Processing](/categories/payments)

xiaowei007/payment-v2
=====================

微信、支付宝支付 PHP SDK

v1.4(9mo ago)023MITPHPPHP &gt;=7.0

Since Sep 18Pushed 9mo agoCompare

[ Source](https://github.com/xiaowei-007/paymentV2)[ Packagist](https://packagist.org/packages/xiaowei007/payment-v2)[ RSS](/packages/xiaowei007-payment-v2/feed)WikiDiscussions main Synced today

READMEChangelog (5)DependenciesVersions (6)Used By (0)

Payment for PHP
===============

[](#payment-for-php)

- 运行最底要求 PHP 版本 7.0 , 建议在 PHP8 上运行以获取最佳性能；
- 微信的部分接口需要缓存数据在本地，因此配置目录并需要对目录有写权限；
- 微信商户已经支持 v2 和 v3 接口，未加入的接口可以使用通用方式调用。

功能描述
----

[](#功能描述)

- 微信小程序，服务端接口支持
- 微信认证服务号，服务端接口支持
- 微信支付（账单、卡券、红包、退款、转账、App支付、JSAPI支付、Web支付、扫码支付等）
- 微信服务商支付（JSAPI、App、H5、Native、小程序支付、退款、转账等）
- 支付宝支付（账单、转账、App支付、刷卡支付、扫码支付、Web支付、Wap支付等）

基于官方接口封装，在做微信开发前，必需先阅读微信官方文档。

- 微信官方文档：
- 商户支付文档：
- 服务商支付文档：
- Github 仓库地址：

文件说明（后续会根据官方文档增加文件）
-------------------

[](#文件说明后续会根据官方文档增加文件)

文件名类名描述类型加载 ①App.phpAliPay\\App支付宝App支付支付宝支付\\We::AliPayApp()Bill.phpAliPay\\Bill支付宝账单下载支付宝支付\\We::AliPayBill()Pos.phpAliPay\\Pos支付宝刷卡支付支付宝支付\\We::AliPayPos()Scan.phpAliPay\\Scan支付宝扫码支付支付宝支付\\We::AliPayScan()Transfer.phpAliPay\\Transfer支付宝转账支付宝支付\\We::AliPayTransfer()Wap.phpAliPay\\Wap支付宝Wap支付支付宝支付\\We::AliPayWap()Web.phpAliPay\\Web支付宝Web支付支付宝支付\\We::AliPayWeb()ZhimaCreditPePromiseOrder.phpAliPay\\ZhimaCreditPePromiseOrder支付宝芝麻先享V3接口支付宝支付\\We::AliPayZhimaCreditPePromiseOrder()ZhimaCreditEpSceneAgreement.phpAliPay\\ZhimaCreditEpSceneAgreement支付宝芝麻免押V3接口支付宝支付\\We::AliPayZhimaCreditEpSceneAgreement()Card.phpWeChat\\Card微信卡券接口支持认证服务号\\We::WeChatCard()Custom.phpWeChat\\Custom微信客服消息接口支持认证服务号\\We::WeChatCustom()Media.phpWeChat\\Media微信媒体素材接口支持认证服务号\\We::WeChatMedia()Oauth.phpWeChat\\Oauth微信网页授权消息类接口认证服务号\\We::WeChatOauth()Pay.phpWeChat\\Pay微信支付类接口认证服务号\\We::WeChatPay()Product.phpWeChat\\Product微信商店类接口认证服务号\\We::WeChatProduct()Qrcode.phpWeChat\\Qrcode微信二维码接口支持认证服务号\\We::WeChatQrcode()Receive.phpWeChat\\Receive微信推送事件消息处理支持认证服务号\\We::WeChatReceive()Scan.phpWeChat\\Scan微信扫一扫接口支持认证服务号\\We::WeChatScan()Script.phpWeChat\\Script微信前端JSSDK支持认证服务号\\We::WeChatScript()Shake.phpWeChat\\Shake微信蓝牙设备揺一揺接口认证服务号\\We::WeChatShake()Tags.phpWeChat\\Tags微信粉丝标签接口支持认证服务号\\We::WeChatTags()Template.phpWeChat\\Template微信模板消息接口支持认证服务号\\We::WeChatTemplate()User.phpWeChat\\User微信粉丝管理接口支持认证服务号\\We::WeChatCard()Wifi.phpWeChat\\Wifi微信门店WIFI管理支持认证服务号\\We::WeChatWifi()Draft.phpWeChat\\Draft微信草稿箱认证服务号\\We::WeChatDraft()Freepublish.phpWeChat\\Freepublish微信发布能力认证服务号\\We::WeChatFreepublish()Bill.phpWePay\\Bill微信商户账单及评论微信支付\\We::WePayBill()Coupon.phpWePay\\Coupon微信商户代金券微信支付\\We::WePayCoupon()Order.phpWePay\\Order微信商户订单微信支付\\We::WePayOrder()Redpack.phpWePay\\Redpack微信红包支持微信支付\\We::WePayRedpack()Refund.phpWePay\\Refund微信商户退款微信支付\\We::WePayRefund()Transfers.phpWePay\\Transfers微信商户打款到零钱微信支付\\We::WePayTransfers()TransfersBank.phpWePay\\TransfersBank微信商户打款到银行卡微信支付\\We::WePayTransfersBank()Order.phpWePayV3\\Order微信商户V3订单支付微信支付V3\\We::WePayV3Order()Refund.phpWePayV3\\Refund微信商户V3退款微信支付V3\\We::WePayV3Refund()ProfitSharing.phpWePayV3\\ProfitSharing微信商户V3分账微信支付V3\\We::WePayV3ProfitSharing()PayScore.phpWePayV3\\PayScore微信支付分微信支付V3\\We::WePayV3PayScore()Parking.phpWePayV3\\Parking微信支付分停车服务微信支付V3\\We::WePayV3Parking()Crypt.phpWeMini\\Crypt微信小程序数据加密处理微信小程序\\We::WeMiniCrypt()Plugs.phpWeMini\\Plugs微信小程序插件管理微信小程序\\We::WeMiniPlugs()Poi.phpWeMini\\Poi微信小程序地址管理微信小程序\\We::WeMiniPoi()Qrcode.phpWeMini\\Qrcode微信小程序二维码管理微信小程序\\We::WeMiniCrypt()Template.phpWeMini\\Template微信小程序模板消息支持微信小程序\\We::WeMiniTemplate()Total.phpWeMini\\Total微信小程序数据接口微信小程序\\We::WeMiniTotal()Order.phpWePayPartner\\Order微信服务商订单支付微信服务商\\We::WePayPartnerOrder()Refund.phpWePayPartner\\Refund微信服务商退款微信服务商\\We::WePayPartnerRefund()ProfitSharing.phpWePayPartner\\ProfitSharing微信服务商分账微信服务商\\We::WePayPartnerProfitSharing()Ecommerce.phpWePayPartner\\Ecommerce微信服务商特约商户进件微信服务商\\We::WePayPartnerEcommerce()Parking.phpWePayPartner\\Parking微信服务商支付分停车服务微信服务商\\We::WePayPartnerParking()Transfers.phpWePayPartner\\Transfers微信服务商转账到零钱微信服务商\\We::WePayPartnerTransfers()PayScore.phpWePayPartner\\PayScore微信服务商支付分微信服务商\\We::WePayPartnerPayScore()Subject.phpWePayPartner\\Subject微信服务商商户开户意愿确认微信服务商\\We::WePayPartnerSubject()Violation.phpWePayPartner\\Violation微信服务商商户平台处置通知微信服务商\\We::WePayPartnerViolation()Bill.phpWePayPartner\\Bill微信服务商下载账单微信服务商\\We::WePayPartnerBill()安装使用
----

[](#安装使用)

1.1 通过 Composer 来管理安装

```
# 首次安装 线上版本（稳定）
composer require xiaowei007/payment-v2
```

2.1 接口实例所需参数

```
// =====================================================
// 配置缓存处理函数（适配不同环境）
// -----------------------------------------------------
// - 数据缓存（set|get|del）：可存储到本地或 Redis
// - 文件缓存（put）：仅支持本地存储，并返回可读的文件路径
// - 若未设置自定义缓存处理，默认存储在 cache_path 目录
// =====================================================
// \WeChat\Contracts\Tools::$cache_callable = [
//    'set' => function ($name, $value, $expired = 360) {
//        var_dump(func_get_args());
//        return $value;
//    },
//    'get' => function ($name) {
//        var_dump(func_get_args());
//        return $value;
//    },
//    'del' => function ($name) {
//        var_dump(func_get_args());
//        return true;
//    },
//    'put' => function ($name) {
//        var_dump(func_get_args());
//        return $filePath;
//    },
// ];

return [
    // 公众号 APPID（可选）
    'appid'        => 'wx3760xxxxxxxxxxxx',

    // 微信商户号（必填）
    'mch_id'       => '15293xxxxxx',

    // 微信商户 V3 接口密钥（必填）
    'mch_v3_key'   => '98b7fxxxxxxxxxxxxxxxxxxxxxxxxxxxx',

    // 商户证书序列号（可选）：用于请求签名
    'cert_serial'  => '49055D67B2XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX',

    // 微信商户证书公钥（必填）：可填写证书内容或文件路径，仅用于提取序列号
    'cert_public'  => $certPublic,

    // 微信商户证书私钥（必填）：可填写证书内容或文件路径，用于请求数据签名
    'cert_private' => $certPrivate,

    // 自定义证书包：支持平台证书或支付公钥（可填写文件路径或证书内容）
    'cert_package' => [
        'PUB_KEY_ID_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx' => $certPayment
    ],

    // 微信平台证书或支付证书序列号（可选）
    // 'mp_cert_serial'  => 'PUB_KEY_ID_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',

    // 微信平台证书或支付证书内容（可选）
    // 'mp_cert_content' => $certPayment,

    // 运行时文件缓存路径（可选）
    'cache_path'   => ''
];
```

2.2 微信服务商支付参数

```
return [
    // 服务商应用ID
    'sp_appid' => 'wx3760xxxxxxxxxxxx',

    // 服务商户号
    'sp_mchid' => '15293xxxxxx',

    // 子商户应用ID（可选）
    'appid' => 'wx3760xxxxxxxxxxxx',

    // 子商户号（可选）
    'mch_id' => '15293xxxxxx',

    // 微信商户 V3 接口密钥（必填）
    'mch_v3_key' => '98b7fxxxxxxxxxxxxxxxxxxxxxxxxxxxx',

    // 商户证书序列号（可选）：用于请求签名
    'cert_serial' => '49055D67B2XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX',

    // 微信商户证书公钥（必填）：可填写证书内容或文件路径，仅用于提取序列号
    'cert_public' => $certPublic,

    // 微信商户证书私钥（必填）：可填写证书内容或文件路径，用于请求数据签名
    'cert_private' => $certPrivate,

    // 自定义证书包：支持平台证书或支付公钥（可填写文件路径或证书内容）
    'cert_package' => [
        'PUB_KEY_ID_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx' => $certPayment
    ],

    // 微信平台证书或支付证书序列号（可选）
    // 'mp_cert_serial' => 'PUB_KEY_ID_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',

    // 微信平台证书或支付证书内容（可选）
    // 'mp_cert_content' => $certPayment,

    // 运行时文件缓存路径（可选）
    'cache_path' => ''
];
```

3.1 实例指定接口

```
try {

    // 实例对应的接口对象
    $user = new \WeChat\User($config);

    // 调用接口对象方法
    $list = $user->getUserList();

    // 处理返回的结果
    echo '';
    var_export($list);

} catch (Exception $e) {

    // 出错啦，处理下吧
    echo $e->getMessage() . PHP_EOL;

}
```

微信支付
----

[](#微信支付)

```
  // 创建接口实例
  $wechat = new \WeChat\Pay($config);

  // 组装参数，可以参考官方商户文档
  $options = [
      'body'             => '测试商品',
      'out_trade_no'     => time(),
      'total_fee'        => '1',
      'openid'           => 'o38gpszoJoC9oJYz3UHHf6bEp0Lo',
      'trade_type'       => 'JSAPI',
      'notify_url'       => 'http://a.com/text.html',
      'spbill_create_ip' => '127.0.0.1',
  ];

try {

    // 生成预支付码
    $result = $wechat->createOrder($options);

    // 创建JSAPI参数签名
    $options = $wechat->createParamsForJsApi($result['prepay_id']);

    // @todo 把 $options 传到前端用js发起支付就可以了

} catch (Exception $e) {

    // 出错啦，处理下吧
    echo $e->getMessage() . PHP_EOL;

}
```

微信服务商支付
-------

[](#微信服务商支付)

```
  // 创建接口实例
  $wechat = \We::WePayPartnerOrder($config);
  // $wechat = new \WePayPartner\Order($config);

  // 组装参数，可以参考官方商户文档
  $options = [
      'sp_appid' => $config['sp_appid'],
      'sp_mchid' => $config['sp_mchid'],
      'sub_appid' => $config['appid'],
      'sub_mchid' => $config['mch_id'],
      'description' => '测试商品',
      'out_trade_no' => time(),
      'notify_url' => 'http://a.com/text.html',
      'amount' => [
          'total' => 1,
          'currency' => 'CNY'
      ],
      'payer' => [
          'sp_openid' => 'o38gpszoJoC9oJYz3UHHf6bEp0Lo'
      ]
  ];

try {

    // 生成预支付码
    $result = $wechat->create(\WePayPartner\Order::WXPAY_JSAPI, $options);

    // @todo 把 $result 传到前端用js发起支付就可以了

} catch (Exception $e) {

    // 出错啦，处理下吧
    echo $e->getMessage() . PHP_EOL;

}
```

- 更多功能请阅读测试代码或SDK封装源码

支付宝支付
-----

[](#支付宝支付)

- 支付参数配置（可用沙箱模式）

```
$config = [
    // 沙箱模式
    'debug'            => true,
    // 签名类型 ( RSA|RSA2 )
    'sign_type'        => 'RSA2',
    // 应用ID
    'appid'            => '2021000122667306',
    // 应用私钥内容 ( 需1行填写，特别注意：这里的应用私钥通常由支付宝密钥管理工具生成 )
    'private_key'      => 'MIIEowIBAAKCAQEAn...',
    // 公钥模式，支付宝公钥内容 ( 需1行填写，特别注意：这里不是应用公钥而是支付宝公钥，通常是上传应用公钥换取支付宝公钥，在网页可以复制 )
    'public_key'       => '',
    // 证书模式，应用公钥证书路径 ( 新版资金类接口转 app_cert_sn，如文件 appCertPublicKey.crt )
    'app_cert_path'    => __DIR__ . '/alipay/appPublicCert.crt', // 'app_cert' => '证书内容',
    // 证书模式，支付宝根证书路径 ( 新版资金类接口转 alipay_root_cert_sn，如文件 alipayRootCert.crt )
    'alipay_root_path' => __DIR__ . '/alipay/alipayRootCert.crt', // 'root_cert' => '证书内容',
    // 证书模式，支付宝公钥证书路径 ( 未填写 public_key 时启用此参数，如文件 alipayPublicCert.crt )
    'alipay_cert_path' => __DIR__ . '/alipay/alipayPublicCert.crt', // 'public_key' => '证书内容'
    // 支付成功通知地址
    'notify_url'       => '',
    // 网页支付回跳地址
    'return_url'       => '',
];
```

- 支付宝发起PC网站支付

```
// 参考公共参数  https://docs.open.alipay.com/203/107090/
$config['notify_url'] = 'http://pay.thinkadmin.top/test/alipay-notify.php';
$config['return_url'] = 'http://pay.thinkadmin.top/test/alipay-success.php';

try {

    // 实例支付对象
    $pay = We::AliPayWeb($config);
    // $pay = new \AliPay\Web($config);

    // 参考链接：https://docs.open.alipay.com/api_1/alipay.trade.page.pay
    $result = $pay->apply([
        'out_trade_no' => time(), // 商户订单号
        'total_amount' => '1',    // 支付金额
        'subject'      => '支付订单描述', // 支付订单描述
    ]);

    echo $result; // 直接输出HTML（提交表单跳转)

} catch (Exception $e) {

    // 异常处理
    echo $e->getMessage();

}
```

- 支付宝发起手机网站支付

```
// 参考公共参数  https://docs.open.alipay.com/203/107090/
$config['notify_url'] = 'http://pay.thinkadmin.top/test/alipay-notify.php';
$config['return_url'] = 'http://pay.thinkadmin.top/test/alipay-success.php';

try {

    // 实例支付对象
    $pay = We::AliPayWap($config);
    // $pay = new \AliPay\Wap($config);

    // 参考链接：https://docs.open.alipay.com/api_1/alipay.trade.wap.pay
    $result = $pay->apply([
        'out_trade_no' => time(), // 商户订单号
        'total_amount' => '1',    // 支付金额
        'subject'      => '支付订单描述', // 支付订单描述
    ]);

    echo $result; // 直接输出HTML（提交表单跳转)

} catch (Exception $e) {

    // 异常处理
    echo $e->getMessage();

}
```

- 更多功能请阅读测试代码或SDK封装源码

支付宝芝麻先享V3接口
-----------

[](#支付宝芝麻先享v3接口)

```
try {
    // 实例化芝麻先享对象
    $zhima = We::AliPayZhimaCreditPePromiseOrder($config);
    // $zhima = new \AliPay\ZhimaCreditPePromiseOrder($config);

    // 创建芝麻先享订单
    $result = $zhima->create([
        'out_order_no' => time(), // 商户订单号
        'product_code' => 'w1010100100000000000', // 产品码
        'subject' => '测试商品', // 商品标题
        'amount' => '0.01', // 订单总金额
        'seller_id' => '2088102146222222', // 卖家支付宝用户ID
    ]);

    var_export($result);

} catch (Exception $e) {
    // 异常处理
    echo $e->getMessage();
}
```

支付宝芝麻免押V3接口
-----------

[](#支付宝芝麻免押v3接口)

```
try {
    // 实例化芝麻免押对象
    $zhima = We::AliPayZhimaCreditEpSceneAgreement($config);
    // $zhima = new \AliPay\ZhimaCreditEpSceneAgreement($config);

    // 创建芝麻免押订单
    $result = $zhima->create([
        'credit_order_no' => time(), // 信用订单号
        'product_code' => 'w1010100100000000000', // 产品码
        'subject' => '测试免押商品', // 商品标题
        'amount' => '0.01', // 订单总金额
        'seller_id' => '2088102146222222', // 卖家支付宝用户ID
    ]);

    var_export($result);

} catch (Exception $e) {
    // 异常处理
    echo $e->getMessage();
}
```

- 更多功能请阅读测试代码或SDK封装源码

微信支付分V3接口
---------

[](#微信支付分v3接口)

```
try {
    // 实例化微信支付分对象
    $payscore = We::WePayV3PayScore($config);
    // $payscore = new \WePayV3\PayScore($config);

    // 创建支付分订单
    $result = $payscore->create([
        'out_order_no' => time(), // 商户订单号
        'service_id' => 'your_service_id', // 服务ID
        'service_introduction' => '测试服务', // 服务介绍
        'risk_amount' => 10000, // 风险金额，单位为分
        'time_range' => [
            'start_time' => date('Y-m-d H:i:s'),
            'end_time' => date('Y-m-d H:i:s', strtotime('+1 hour')),
        ],
        'notify_url' => 'https://yourdomain.com/notify',
    ]);

    var_export($result);

} catch (Exception $e) {
    // 异常处理
    echo $e->getMessage();
}
```

微信支付分停车服务V3接口
-------------

[](#微信支付分停车服务v3接口)

```
try {
    // 实例化微信支付分停车服务对象
    $parking = We::WePayV3Parking($config);
    // $parking = new \WePayV3\Parking($config);

    // 创建停车入场
    $result = $parking->create([
        'out_parking_no' => time(), // 商户停车入场号
        'plate_number' => '粤B12345', // 车牌号
        'plate_color' => 'BLUE', // 车牌颜色
        'start_time' => date('Y-m-d H:i:s'), // 入场时间
        'parking_name' => '测试停车场', // 停车场名称
        'free_duration' => 30, // 免费时长，单位分钟
        'notify_url' => 'https://yourdomain.com/notify',
    ]);

    var_export($result);

} catch (Exception $e) {
    // 异常处理
    echo $e->getMessage();
}
```

- 更多功能请阅读测试代码或SDK封装源码

微信服务商商户开户意愿确认接口
---------------

[](#微信服务商商户开户意愿确认接口)

```
try {
    // 实例化微信服务商商户开户意愿确认对象
    $subject = We::WePayPartnerSubject($config);
    // $subject = new \WePayPartner\Subject($config);

    // 提交商户开户意愿申请单
    $result = $subject->apply([
        'business_code' => 'business_' . time(), // 业务申请编号
        'contact_info' => [
            'contact_type' => 'LEGAL_PERSON', // 联系人类型
            'contact_name' => '张三', // 联系人姓名
            'contact_id_card_number' => '11010119900307XXXX', // 联系人身份证号码
            'mobile' => '13800138000', // 联系人手机号
            'email' => 'zhangsan@example.com' // 联系人邮箱
        ],
        'subject_info' => [
            'subject_type' => 'SUBJECT_TYPE_INDIVIDUAL', // 主体类型
            'business_licence_info' => [
                'licence_number' => '9144030076543210XX', // 营业执照编号
                'merchant_name' => '深圳市某某科技有限公司', // 商户名称
                'company_address' => '深圳市南山区某某街道某某号', // 公司地址
                'legal_person' => '张三' // 法人姓名
            ]
        ],
        'notify_url' => 'https://yourdomain.com/notify', // 通知地址
    ]);

    var_export($result);

    // 撤销商户开户意愿申请单（通过申请单号）
    $subject->cancelApplyment(['applyment_id' => $result['applyment_id']]);

    // 或者通过业务申请编号撤销
    // $subject->cancelApplyment(['business_code' => 'your_business_code']);

} catch (Exception $e) {
    // 异常处理
    echo $e->getMessage();
}
```

微信服务商商户平台处置通知接口
---------------

[](#微信服务商商户平台处置通知接口)

```
try {
    // 实例化微信服务商商户平台处置通知对象
    $violation = We::WePayPartnerViolation($config);
    // $violation = new \WePayPartner\Violation($config);

    // 创建商户违规通知回调地址
    $result = $violation->createCallback([
        'notify_url' => 'https://yourdomain.com/violation-notify' // 回调地址
    ]);

    var_export($result);

    // 查询商户违规通知回调地址
    $violation->getCallback();

    // 更新商户违规通知回调地址
    $violation->updateCallback([
        'notify_url' => 'https://yourdomain.com/violation-notify-update'
    ]);

    // 查询商户违规记录
    $violation->getViolations('sub_mchid', [
        'limit' => 10,
        'offset' => 0
    ]);

    // 删除商户违规通知回调地址
    $violation->deleteCallback();

} catch (Exception $e) {
    // 异常处理
    echo $e->getMessage();
}
```

微信服务商消费者投诉接口
------------

[](#微信服务商消费者投诉接口)

```
try {
    // 实例化微信服务商消费者投诉对象
    $complaint = \We::WePayPartnerComplaint($config);
    // $complaint = new \WePayPartner\Complaint($config);

    // 查询投诉单列表
    $complaint->list([
        'limit' => 5,
        'offset' => 0,
        'begin_date' => '2023-01-01',
        'end_date' => '2023-01-31'
    ]);

    // 创建投诉通知回调地址
    $complaint->createCallback([
        'url' => 'https://yourdomain.com/complaint-notify'
    ]);

    // 查询投诉通知回调地址
    $complaint->getCallback();

    // 更新投诉通知回调地址
    $complaint->updateCallback([
        'url' => 'https://yourdomain.com/complaint-notify-update'
    ]);

    // 删除投诉通知回调地址
    $complaint->deleteCallback();

} catch (Exception $e) {
    // 异常处理
    echo $e->getMessage();
}
```

- 更多功能请阅读测试代码或SDK封装源码

微信服务商下载账单接口
-----------

[](#微信服务商下载账单接口)

```
try {
    // 实例化微信服务商下载账单对象
    $bill = \We::WePayPartnerBill($config);
    // $bill = new \WePayPartner\Bill($config);

    // 申请交易账单
    $tradeBill = $bill->tradeBill('2023-01-01', [
        'sub_mchid' => '1600000000',  // 可选，指定子商户号
        'bill_type' => 'ALL',         // 可选，账单类型 ALL|SUCCESS|REFUND
        'tar_type' => 'GZIP'          // 可选，压缩类型 GZIP
    ]);

    // 申请资金账单
    $fundFlowBill = $bill->fundFlowBill('2023-01-01', [
        'account_type' => 'BASIC',    // 可选，资金账户类型 BASIC|OPERATION|FEES
        'tar_type' => 'GZIP'          // 可选，压缩类型 GZIP
    ]);

    // 下载账单文件（如果获取到了下载链接）
    if (isset($tradeBill['download_url'])) {
        $bill->download($tradeBill['download_url'], './trade_bill.csv', [
            'tar_type' => 'GZIP'  // 如果是压缩文件需要指定
        ]);
    }

} catch (Exception $e) {
    // 异常处理
    echo $e->getMessage();
}
```

- 更多功能请阅读测试代码或SDK封装源码

版权说明
----

[](#版权说明)

**Payment** 遵循 **MIT** 开源协议发布，并免费提供使用。

###  Health Score

28

—

LowBetter than 52% of packages

Maintenance58

Moderate activity, may be stable

Popularity7

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity35

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~3 days

Total

5

Last Release

278d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/bca58b793dfea83d6b785d0a3d2f9991b3a765b019b87b5f8b00fa7ff489981d?d=identicon)[xiaowei](/maintainers/xiaowei)

---

Top Contributors

[![xiaowei-007](https://avatars.githubusercontent.com/u/62641121?v=4)](https://github.com/xiaowei-007 "xiaowei-007 (18 commits)")

---

Tags

sdkpaymentalipaywechatwechatpayWeChatDeveloperWeMini

### Embed Badge

![Health badge](/badges/xiaowei007-payment-v2/health.svg)

```
[![Health](https://phpackages.com/badges/xiaowei007-payment-v2/health.svg)](https://phpackages.com/packages/xiaowei007-payment-v2)
```

###  Alternatives

[zoujingli/wechat-developer

WeChat and Alipay Platform Development

1.7k142.1k15](/packages/zoujingli-wechat-developer)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
