PHPackages                             lbsfei/wxpay - 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. lbsfei/wxpay

ActiveLibrary

lbsfei/wxpay
============

微信支付 PHP SDK

0.0.6(7y ago)018BSDPHP

Since Dec 26Pushed 7y ago1 watchersCompare

[ Source](https://github.com/lbsfei/wxpay)[ Packagist](https://packagist.org/packages/lbsfei/wxpay)[ RSS](/packages/lbsfei-wxpay/feed)WikiDiscussions master Synced 4d ago

READMEChangelog (2)DependenciesVersions (4)Used By (0)

微信支付 PHP SDK
------------

[](#微信支付-php-sdk)

对[微信支付开发者文档](https://pay.weixin.qq.com/wiki/doc/api/index.html)中给出的API进行了封装。

`Lbsfei\WXPay`类下提供了对应的方法：

方法名说明microPay刷卡支付unifiedOrder统一下单orderQuery查询订单reverse撤销订单closeOrder关闭订单refund申请退款refundQuery查询退款downloadBill下载对账单report交易保障shortUrl转换短链接authCodeToOpenid授权码查询openid- 参数为关联数组，返回类型也是关联数组。
- 方法内部会将参数会转换成含有`appid、mch_id`、`nonce_str`、`sign_type`和`sign`的XML；
- 默认使用MD5进行签名；
- 通过HTTPS请求得到返回数据后会对其做必要的处理（例如验证签名，签名错误则抛出异常）。
- 对于downloadBill，无论是否成功都返回Map，且都含有`return_code`和`return_msg`。若成功，其中`return_code`为SUCCESS，`data`对应对账单数据。暂不支持下载压缩格式的对账单。

安装
--

[](#安装)

```
$ composer require "feiger/wxpay:0.0.5" -vvv

```

php必须启用curl，并在php.ini中配置`curl.cainfo`的值`rootca.pem`的绝对路径。

示例
--

[](#示例)

接口的使用方法是一致的，例如统一下单：

```
require __DIR__.'/vendor/autoload.php';
use Lbsfei\WXPay;
use Lbsfei\WXPayConstants;
use Lbsfei\WXPayUtil;

$wxpay = new WXPay(
        'wx888888888',  // appid
        '22222222',     // mch id
        '123456781234567812345678',  // key
        '/path/to/apiclient_cert.pem',
        '/path/to/apiclient_key.pem',
        6000);  // 超时时间，毫秒
$resp = $wxpay->orderQuery(array(
                  'out_trade_no' => '201610265257070987061763',
                  'total_fee' => 1,
                  'body' => '腾讯充值中心-QQ会员充值',
                  'spbill_create_ip' => '123.12.12.123',
                  'trade_type' => 'NATIVE',
                  'notify_url' => 'https://www.example.com/wxpay/notify'
              ));
var_dump($resp);
```

### 关于签名

[](#关于签名)

默认使用MD5签名。查询订单示例：

```
require __DIR__.'/vendor/autoload.php';
use Lbsfei\WXPay;
use Lbsfei\WXPayConstants;
use Lbsfei\WXPayUtil;

$wxpay = new WXPay(
        'wx888888888',  // appid
        '22222222',     // mch id
        '123456781234567812345678',  // key
        '/path/to/apiclient_cert.pem',
        '/path/to/apiclient_key.pem',
        6000);  // 超时时间，毫秒
$resp = $wxpay->orderQuery(array('out_trade_no' => '201610265257070987061763'));
var_dump($resp);
```

使用HMAC-SHA256做签名查询订单：

```
$wxpay = new WXPay(
        'wx888888888',  // appid
        '22222222',     // mch id
        '123456781234567812345678',  // key
        '/path/to/apiclient_cert.pem',
        '/path/to/apiclient_key.pem',
        6000,  // 超时时间，毫秒
        WXPayConstants::SIGN_TYPE_HMACSHA256);
$resp = $wxpay->orderQuery(array('out_trade_no' => '201610265257070987061763'));
var_dump($resp);
```

### 沙箱环境

[](#沙箱环境)

查询订单示例：

```
$useSandbox = true;

$wxpay = new WXPay(
       'wx888888888',  // appid
       '22222222',     // mch id
       '123456781234567812345678',  // 沙箱环境key
       '/path/to/apiclient_cert.pem',
       '/path/to/apiclient_key.pem',
       6000,  // 超时时间，毫秒
       WXPayConstants::SIGN_TYPE_MD5,
       $useSandbox);

var_dump( $wxpay->orderQuery(array('out_trade_no' => '201610265257070987061763')) );
```

### 其他

[](#其他)

若需要生成请求的XML数据，可以这样：

```
$data = array(
    'bill_date' => '20140603',
    'bill_type' => 'ALL',
    'tar_type' => 'GZIP'
);
$wxpay = new WXPay(
        'wx888888888',  // appid
        '22222222',     // mch id
        '123456781234567812345678',  // key
        '/path/to/apiclient_cert.pem',
        '/path/to/apiclient_key.pem',
        6000);  // 超时时间，毫秒
$data = $wxpay->fillRequestData($data); // 会添加appid、mch_id、sign_type、sign、nonce_str
var_dump($data);
echo "\n";
echo \Lbsfei\WXPayUtil::array2xml($data);
```

收到支付结果通知时，需要验证签名，可以这样做：

```
$wxpay = new WXPay(
    'wx888888888',  // appid
    '22222222',     // mch id
    "123456781234567812345678",  // key
    '/path/to/apiclient_cert.pem',
    '/path/to/apiclient_key.pem',
    6000);

$xml = "
    ......
    9A0A8659F005D6984697E2CA0A9CF3B7
    ";
$data = WXPayUtil::xml2array($xml);
// $data必须有sign字段，也就是return_code必须为SUCCESS。否则返回false
var_dump($wxpay->isPayResultNotifySignatureValid($data));  // 布尔类型，标识签名是否正确
```

更多见 [tests/WXPayTest.php](tests/WXPayTest.php) 。

兼容性
---

[](#兼容性)

在 PHP 5.6.21 中测试通过。

License
-------

[](#license)

BSD

###  Health Score

24

—

LowBetter than 32% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity53

Maturing project, gaining track record

 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 ~1 days

Total

2

Last Release

2695d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/6889383?v=4)[feiger](/maintainers/feiger)[@Feiger](https://github.com/Feiger)

---

Top Contributors

[![lbsfei](https://avatars.githubusercontent.com/u/12455682?v=4)](https://github.com/lbsfei "lbsfei (2 commits)")

---

Tags

phpwechat-paysdkpaywechat

### Embed Badge

![Health badge](/badges/lbsfei-wxpay/health.svg)

```
[![Health](https://phpackages.com/badges/lbsfei-wxpay/health.svg)](https://phpackages.com/packages/lbsfei-wxpay)
```

###  Alternatives

[lokielse/omnipay-wechatpay

Wechat gateway for Omnipay payment processing library

329224.5k7](/packages/lokielse-omnipay-wechatpay)

PHPackages © 2026

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