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

ActiveLibrary[Payment Processing](/categories/payments)

xuzhen/wechat-pay
=================

wechat pay for composer

0.0.4(4y ago)36MITPHPPHP &gt;=7.0

Since Sep 16Pushed 3y ago1 watchersCompare

[ Source](https://github.com/gentlemm/wechat-pay)[ Packagist](https://packagist.org/packages/xuzhen/wechat-pay)[ RSS](/packages/xuzhen-wechat-pay/feed)WikiDiscussions master Synced 6d ago

READMEChangelog (4)Dependencies (1)Versions (4)Used By (0)

wechat-pay
==========

[](#wechat-pay)

做这个包的原因
-------

[](#做这个包的原因)

我们公司有（ 微信app支付、微信公众号支付 ）两个商户号，微信官网给的 sdk 在 `lib\WxPay.Config.php` 里面配置项都是`const`修饰所以只能配置一个商户号的信息，这样的问题就是：两个商户号就要有两个 sdk，在不同的 function 分别调用`WxPayApi()`没有问题，可是一旦在同一个 function 使用就会告诉报类重复定义的错误。第一次遇到这个问题是在自动退款脚本，不能使用一个退款脚本，所以定义了两个。但后来代码重构，将相同的逻辑写成 serverApi ，如果 serverApi 也写两个方法就失去了重构的意义，所以就决定重新定义一下官网的 sdk。这个包就这样诞生了

对微信官网支付sdk做了以下几点优化：
-------------------

[](#对微信官网支付sdk做了以下几点优化)

- 对`WxPayDataBase.php`做了拆分，将每个接口对应的类拆分成了单独的类
- 全部支持命名空间
- 支持多个商户号分别调用

说明
--

[](#说明)

- 为了兼容商户号自定义配置，将 `lib\WxPay.Config.php` 里的配置都使用 `static` 替换 `const` ，`WxPayApi()` 和 `JsApiPay()` 都继承了 `WxPayConfig` ，所以在使用 `WxPayApi()` 和 `JsApiPay()` 时都需要先做配置
- 由于加密 KEY 需要配置，所以在使用 `SetSign()` 、 `MakeSign()` 、 `Handle()` 、 `CheckSign()` 、 `WxPayResults::Init()` 都增加了 `$apiKey` 参数

安装
--

[](#安装)

```
  composer require xuzhen/wechat-pay：dev-master

```

使用
--

[](#使用)

```
use WxPay\ApiObj\WxPayOrderQuery;
use WxPay\WxPayApi;

$transaction_id = 'transaction_id';
$input = new WxPayOrderQuery();
$input->SetTransaction_id($transaction_id);

# 配置方法一
WxPayApi::$APPID = 'your_app_id';
WxPayApi::$MCHID = 'your_mch_id';
WxPayApi::$KEY   = 'your_key';
print_r(WxPayApi::orderQuery($input));

# 配置方法二
$configArr = [
 'APPID' => 'your_app_id',
 'MCHID' => 'your_mch_id',
 'KEY'   => 'your_key'
];
print_r( (new WxPayApi($configArr)) -> orderQuery($input));
```

###  Health Score

20

—

LowBetter than 14% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity8

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity37

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

Total

3

Last Release

1703d ago

Major Versions

0.0.3 → 1.0.1.x-dev2021-09-17

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/1476521?v=4)[Filepicker](/maintainers/Ink)[@Ink](https://github.com/Ink)

---

Top Contributors

[![hh-Ink](https://avatars.githubusercontent.com/u/16871357?v=4)](https://github.com/hh-Ink "hh-Ink (20 commits)")

###  Code Quality

Code StylePHP CS Fixer

### Embed Badge

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

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

###  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)
