PHPackages                             mindongji/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. [Payment Processing](/categories/payments)
4. /
5. mindongji/wxpay

AbandonedArchivedLibrary[Payment Processing](/categories/payments)

mindongji/wxpay
===============

wechat payment sdk

0.1.5(7y ago)029MITPHPPHP &gt;=5.6.0

Since Jul 17Pushed 7y ago1 watchersCompare

[ Source](https://github.com/mindongji/wxpay)[ Packagist](https://packagist.org/packages/mindongji/wxpay)[ RSS](/packages/mindongji-wxpay/feed)WikiDiscussions master Synced yesterday

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

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

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

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

`WXPay\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 "wxpay/wxpay:0.0.5" -vvv

```

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

示例
--

[](#示例)

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

```
require __DIR__.'/vendor/autoload.php';
use WXPay\WXPay;
use WXPay\WXPayConstants;
use WXPay\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 WXPay\WXPay;
use WXPay\WXPayConstants;
use WXPay\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 \WXPay\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

23

—

LowBetter than 27% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity7

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity51

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

Total

5

Last Release

2857d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/05f81a475569b5bfe1623d0002ad27274158e33487ec5a8b7aed051f5bc25cf2?d=identicon)[mindongji](/maintainers/mindongji)

---

Top Contributors

[![mdx86](https://avatars.githubusercontent.com/u/4197341?v=4)](https://github.com/mdx86 "mdx86 (6 commits)")

### Embed Badge

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

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

###  Alternatives

[omnipay/paypal

PayPal gateway for Omnipay payment processing library

3156.8M53](/packages/omnipay-paypal)[eduardokum/laravel-boleto

Biblioteca com boletos para o laravel

626351.9k2](/packages/eduardokum-laravel-boleto)[tbbc/money-bundle

This is a Symfony bundle that integrates moneyphp/money library (Fowler pattern): https://github.com/moneyphp/money.

1961.9M](/packages/tbbc-money-bundle)[2checkout/2checkout-php

2Checkout PHP Library

83740.3k2](/packages/2checkout-2checkout-php)[smhg/sepa-qr-data

Generate QR code data for SEPA payments

61717.2k5](/packages/smhg-sepa-qr-data)[omnipay/dummy

Dummy driver for the Omnipay payment processing library

271.2M33](/packages/omnipay-dummy)

PHPackages © 2026

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