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

ActiveLibrary[Payment Processing](/categories/payments)

papajo/wxpay
============

wxpay

1.0.1(7y ago)113BSDPHP

Since Jul 10Pushed 7y ago1 watchersCompare

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

READMEChangelogDependenciesVersions (2)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

26

—

LowBetter than 43% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity7

Limited adoption so far

Community4

Small or concentrated contributor base

Maturity62

Established project with proven stability

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

Unknown

Total

1

Last Release

2866d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/235e62e08c72e239aab59716748500b8f602d91d9b014780adba49e9812f94f5?d=identicon)[papajo](/maintainers/papajo)

---

Tags

Wxpay

### Embed Badge

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

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

###  Alternatives

[chen-see/chen-pay

免签约支付宝与微信双支付，根据COOKIE

44987.1k](/packages/chen-see-chen-pay)[omnipay/paypal

PayPal gateway for Omnipay payment processing library

3156.8M53](/packages/omnipay-paypal)[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)[hyperbolaa/wechatpay

微信支付在laravle5中的封装

471.3k](/packages/hyperbolaa-wechatpay)

PHPackages © 2026

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