PHPackages                             zhangv/wechat-pay - 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. zhangv/wechat-pay

ActiveLibrary[Payment Processing](/categories/payments)

zhangv/wechat-pay
=================

The simplest wechat pay

v1.4.2(7y ago)56981↓100%37MITPHPPHP &gt;=7.0CI failing

Since Jan 14Pushed 1y ago5 watchersCompare

[ Source](https://github.com/zhangv/wechat-pay)[ Packagist](https://packagist.org/packages/zhangv/wechat-pay)[ Docs](https://github.com/zhangv/wechat-pay)[ RSS](/packages/zhangv-wechat-pay/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (1)Dependencies (10)Versions (25)Used By (0)

WechatPay - 微信支付
================

[](#wechatpay---微信支付)

[![Latest Stable Version](https://camo.githubusercontent.com/630d28d6eceb213a8a70ecfabef7214a2e85972f6712689e806598d1e0412152/68747470733a2f2f706f7365722e707567782e6f72672f7a68616e67762f7765636861742d7061792f762f737461626c65)](https://packagist.org/packages/zhangv/wechat-pay)[![License](https://camo.githubusercontent.com/3bc418d0747f42a2c31d03fb62d46d940bf30ef169040ba8a8f376ff4eb77eb2/68747470733a2f2f706f7365722e707567782e6f72672f7a68616e67762f7765636861742d7061792f6c6963656e7365)](https://packagist.org/packages/zhangv/wechat-pay)[![Build Status](https://camo.githubusercontent.com/94d26a85796e5c08e829bf8866bf804514a10a692015f72f20fdd684c078e844/68747470733a2f2f7472617669732d63692e6f72672f7a68616e67762f7765636861742d7061792e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/zhangv/wechat-pay)[![codecov](https://camo.githubusercontent.com/be21ba2a6675d6c3ae43e8fca893b019d315e190d5c20b62f49335611fdedb6b/68747470733a2f2f636f6465636f762e696f2f67682f7a68616e67762f7765636861742d7061792f6272616e63682f6d61737465722f67726170682f62616467652e737667)](https://codecov.io/gh/zhangv/wechat-pay)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/bc0fd43b8e40e41517fa92d787d64b53d5e19c306e6cd7c634b3666277ce2127/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f7a68616e67762f7765636861742d7061792f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/zhangv/wechat-pay/?branch=master)[![Author](https://camo.githubusercontent.com/71e110b4704a6d617d7cce55b7aff3d88a11ae1a9012dc4b2219a6197204cab5/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f617574686f722d7a68616e67762d677265656e2e737667)](https://zhangv.com)

#### simplest, minimal dependency

[](#simplest-minimal-dependency)

### Feature

[](#feature)

- 使用简单
- 支持php-7x
- 不依赖第三方库（但依赖json、simpleXML、openssl、curl扩展）
- 100%测试覆盖
- 支持所有付款方式（公众号、APP、小程序、H5、扫码、刷卡）
- 支持企业付款、红包、代金券

### Install

[](#install)

```
composer require zhangv/wechat-pay

```

### Demo

[](#demo)

- 配置参数

```
$cfg = [
    'mch_id'            => 'XXXX', //商户号
    'app_id'            => 'XXXXXXXXXXXXXXXXXXX', //APPID
    'app_secret'        => 'XXXXXXXXXXXXXXXXXXXXXXXXX', //App Secret
    'api_key'           =>'XXXXXXXXXXXXXXXXXXXXXXX', //支付密钥
    'ssl_cert_path'     => __DIR__ . '/../cert/apiclient_cert.pem', //SSL证书（通过商户后台下载）
    'ssl_key_path'      => __DIR__ .'/../cert/apiclient_key.pem', //SSL密钥（通过商户后台下载）
    'sign_type'         => 'MD5',
    'notify_url'        => 'http://XXX.XXX/paidnotify.php', //支付结果通知地址
    'refund_notify_url' => 'http://XXX.XXX/refundednotify.php', //退款结果通知地址
    'h5_scene_info'     => [//H5支付时需要
        'h5_info' => ['type' => 'Wap', 'wap_url' => 'http://wapurl', 'wap_name' => 'wapname']
    ],
    'rsa_pubkey_path'   => __DIR__ .'/../cert/pubkey.pem',
    'jsapi_ticket'      => __DIR__ .'/jsapi_ticket.json' //jsticket的临时存放路径
];
```

- 获取公众号支付参数（公众号网页支付）

```
$wp = WechatPay::Jsapi($cfg);
$prepayId = $wp->getPrepayId($body, $orderNo, $amt, $openid);
$package = $wp->getPackage($prepayId);
```

- 获取小程序支付参数（小程序支付）

```
$wp = WechatPay::Weapp($cfg);
$prepayId = $wp->getPrepayId($body, $orderNo, $amt, $openid);
$package = $wp->getPackage($prepayId);
```

- 获取APP的支付参数（APP支付）

```
$wp = WechatPay::App($cfg);
$prepayId = $wp->getPrepayId($body, $orderNo, $amt, $openid);
$package = $wp->getPackage($prepayId);
```

- 获取H5支付URL（H5支付）

```
$wp = WechatPay::Mweb($cfg);
$url = $wp->getMwebUrl($body,$orderNo,$amt);
```

- 获取扫码支付URL（扫码支付）

```
$wp = WechatPay::Native($cfg);
$url = $wp->getCodeUrl($body,$out_trade_no,$total_fee,$product_id);
```

- 提交支付授权码（刷卡支付）

```
$wp = WechatPay::Micro($cfg);
$url = $wp->microPay($body,$out_trade_no,$total_fee,$spbill_create_ip,$auth_code);
```

- 支付结果后台通知处理

```
$notifyxml = file_get_contents("php://input");
$wp = new WechatPay($cfg);
$msg = $wp->onPaidNotify($notifyxml, function($notifyArray){
    //处理逻辑
    return 'ok';
});
$xml = "
           SUCCESS
           $msg]]>
        ";
echo $xml;
```

- 退款

```
$wxpay = new WechatPay($cfg);
$result = $wxpay->refundByOutTradeNo($out_trade_no,$out_refund_no,$total_fee,$refund_fee);
```

- 企业付款

```
$wp = WechatPay::Mchpay($cfg);
//付款到零钱
$result = $wp->transferWallet($partner_trade_no,$openid,$amount,$desc);
//付款到银行卡
$result = $wp->transferBankCard($partner_trade_no,$bank_no,$true_name,$bank_code,$amount,$desc);
```

- 红包

```
$wp = WechatPay::Redpack($cfg);
//发放普通红包
$result = $wp->sendRedPack($mch_billno,$send_name,$re_openid,$total_amount,$total_num,$wishing,$act_name,$remark)；
//发放裂变红包
$result = $wp->sendGroupRedPack($mch_billno,$send_name,$re_openid,$total_amount,$total_num,$wishing,$act_name,$remark)；
```

- 代金券

```
$wp = WechatPay::Coupon($cfg);
//发放代金券
$result = $wp->sendCoupon($coupon_stock_id,$open_id,$partner_trade_no)；
//查询代金券批次
$result = $wp->queryCouponStock($coupon_stock_id)；
```

###  Health Score

39

—

LowBetter than 85% of packages

Maintenance27

Infrequent updates — may be unmaintained

Popularity31

Limited adoption so far

Community18

Small or concentrated contributor base

Maturity68

Established project with proven stability

 Bus Factor1

Top contributor holds 98% 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 ~10 days

Recently: every ~18 days

Total

24

Last Release

2802d ago

PHP version history (3 changes)v1.2.0PHP &gt;=5.3.3

v1.3.5PHP &gt;=7.0

v1.3.10PHP &gt;=7.1

### Community

Maintainers

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

---

Top Contributors

[![zhangv](https://avatars.githubusercontent.com/u/496221?v=4)](https://github.com/zhangv "zhangv (100 commits)")[![branchzero](https://avatars.githubusercontent.com/u/7685609?v=4)](https://github.com/branchzero "branchzero (1 commits)")[![nishuihanlong](https://avatars.githubusercontent.com/u/3214297?v=4)](https://github.com/nishuihanlong "nishuihanlong (1 commits)")

---

Tags

payphptoolwechatwechatpayweixinwechatweixinwechatpay

###  Code Quality

TestsPHPUnit

Code StylePHP\_CodeSniffer

### Embed Badge

![Health badge](/badges/zhangv-wechat-pay/health.svg)

```
[![Health](https://phpackages.com/badges/zhangv-wechat-pay/health.svg)](https://phpackages.com/packages/zhangv-wechat-pay)
```

###  Alternatives

[yansongda/pay

可能是我用过的最优雅的 Alipay 和 WeChat 的支付 SDK 扩展包了

5.3k1.2M53](/packages/yansongda-pay)[yansongda/laravel-pay

专注 Alipay/WeChat/Unipay 的 laravel 支付扩展包

1.1k353.2k9](/packages/yansongda-laravel-pay)[lokielse/omnipay-wechatpay

Wechat gateway for Omnipay payment processing library

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

微信支付在laravle5中的封装

471.3k](/packages/hyperbolaa-wechatpay)[yansongda/hyperf-pay

可能是基于 hyperf 的最优雅的支付宝、微信、银联支付 SDK 了

8959.8k1](/packages/yansongda-hyperf-pay)[fantasystudio/easypay

Wechat and Alipay payment SDK

383.4k](/packages/fantasystudio-easypay)

PHPackages © 2026

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