PHPackages                             lyenrowe/omnipay-wechatpay - 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. lyenrowe/omnipay-wechatpay

ActiveLibrary[Payment Processing](/categories/payments)

lyenrowe/omnipay-wechatpay
==========================

Wechat gateway for Omnipay payment processing library

v3.0.6(7y ago)0171MITPHP

Since Jan 26Pushed 1y ago1 watchersCompare

[ Source](https://github.com/lyenrowe/omnipay-wechatpay)[ Packagist](https://packagist.org/packages/lyenrowe/omnipay-wechatpay)[ Docs](https://github.com/php-cpm/omnipay-wechatpay)[ RSS](/packages/lyenrowe-omnipay-wechatpay/feed)WikiDiscussions master Synced today

READMEChangelogDependencies (3)Versions (31)Used By (0)

Omnipay: WechatPay
==================

[](#omnipay-wechatpay)

本项目基于Omnipay 3.0分支开发，依赖版本较新，也可能会带来不稳定的可能。

增加子商户模式 增加沙箱模式 子商户模式支持小程序的sub\_appid和sub\_openid传递

**WechatPay driver for the Omnipay PHP payment processing library**

[![Build Status](https://camo.githubusercontent.com/ebc14f36c11f631f4c5ba70737f78360cbbb60a8f66fcd4b8ac322285852f549/68747470733a2f2f7472617669732d63692e6f72672f6c79656e726f77652f6f6d6e697061792d7765636861747061792e706e673f6272616e63683d6d6173746572)](https://travis-ci.org/lyenrowe/omnipay-wechatpay)[![Latest Stable Version](https://camo.githubusercontent.com/350b07cd10b8e2695835efeaee4c3263b0255e7f2531fc5c712aed91f8234f57/68747470733a2f2f706f7365722e707567782e6f72672f6c79656e726f77652f6f6d6e697061792d7765636861747061792f76657273696f6e2e706e67)](https://packagist.org/packages/lyenrowe/omnipay-wechatpay)[![Total Downloads](https://camo.githubusercontent.com/6ceaa7e09b5629e830c4d4768312873a3d893081b24cddd11e65b51c77648dc0/68747470733a2f2f706f7365722e707567782e6f72672f6c79656e726f77652f6f6d6e697061792d7765636861747061792f642f746f74616c2e706e67)](https://packagist.org/packages/lyenrowe/omnipay-wechatpay)

[Omnipay](https://github.com/omnipay/omnipay) is a framework agnostic, multi-gateway payment processing library for PHP 5.3+. This package implements WechatPay support for Omnipay.

Installation
------------

[](#installation)

Omnipay is installed via [Composer](http://getcomposer.org/). To install, simply add it to your `composer.json` file:

```
"lyenrowe/omnipay-wechatpay": "^3.0",

```

And run composer to update your dependencies:

```
$ composer update -vvv

```

Basic Usage
-----------

[](#basic-usage)

The following gateways are provided by this package:

- WechatPay (Wechat Common Gateway) 微信支付通用网关
- WechatPay\_App (Wechat App Gateway) 微信APP支付网关
- WechatPay\_Native (Wechat Native Gateway) 微信原生扫码支付支付网关
- WechatPay\_Js (Wechat Js API/MP Gateway) 微信网页、公众号、小程序支付网关
- WechatPay\_Pos (Wechat Micro/POS Gateway) 微信刷卡支付网关
- WechatPay\_Mweb (Wechat H5 Gateway) 微信H5支付网关

Usage
-----

[](#usage)

### Create Order [doc](https://pay.weixin.qq.com/wiki/doc/api/app/app.php?chapter=9_1)

[](#create-order-doc)

```
//gateways: WechatPay_App, WechatPay_Native, WechatPay_Js, WechatPay_Pos, WechatPay_Mweb, WechatPay_Lite
$gateway    = Omnipay::create('WechatPay_App');
$gateway->setAppId($config['app_id']);
$gateway->setMchId($config['mch_id']);
$gateway->setApiKey($config['api_key']);

$order = [
    'body'              => 'The test order',
    'out_trade_no'      => date('YmdHis').mt_rand(1000, 9999),
    'total_fee'         => 1, //=0.01
    'spbill_create_ip'  => 'ip_address',
    'fee_type'          => 'CNY'
];

/**
 * @var Omnipay\WechatPay\Message\CreateOrderRequest $request
 * @var Omnipay\WechatPay\Message\CreateOrderResponse $response
 */
$request  = $gateway->purchase($order);
$response = $request->send();

//available methods
$response->isSuccessful();
$response->getData(); //For debug
$response->getAppOrderData(); //For WechatPay_App
$response->getJsOrderData(); //For WechatPay_Js
$response->getCodeUrl(); //For Native Trade Type
```

### Notify [doc](https://pay.weixin.qq.com/wiki/doc/api/app/app.php?chapter=9_7&index=3)

[](#notify-doc)

```
$gateway    = Omnipay::create('WechatPay');
$gateway->setAppId($config['app_id']);
$gateway->setMchId($config['mch_id']);
$gateway->setApiKey($config['api_key']);

$response = $gateway->completePurchase([
    'request_params' => file_get_contents('php://input')
])->send();

if ($response->isPaid()) {
    //pay success
    var_dump($response->getRequestData());
}else{
    //pay fail
}
```

### Query Order [doc](https://pay.weixin.qq.com/wiki/doc/api/app/app.php?chapter=9_1)

[](#query-order-doc)

```
$response = $gateway->query([
    'transaction_id' => '1217752501201407033233368018', //The wechat trade no
])->send();

var_dump($response->isSuccessful());
var_dump($response->getData());
```

### Close Order [doc](https://pay.weixin.qq.com/wiki/doc/api/app/app.php?chapter=9_3&index=5)

[](#close-order-doc)

```
$response = $gateway->close([
    'out_trade_no' => '201602011315231245', //The merchant trade no
])->send();

var_dump($response->isSuccessful());
var_dump($response->getData());
```

### Refund [doc](https://pay.weixin.qq.com/wiki/doc/api/app/app.php?chapter=9_4&index=6)

[](#refund-doc)

```
$gateway->setCertPath($certPath);
$gateway->setKeyPath($keyPath);

$response = $gateway->refund([
    'transaction_id' => '1217752501201407033233368018', //The wechat trade no
    'out_refund_no' => $outRefundNo,
    'total_fee' => 1, //=0.01
    'refund_fee' => 1, //=0.01
])->send();

var_dump($response->isSuccessful());
var_dump($response->getData());
```

### QueryRefund [doc](https://pay.weixin.qq.com/wiki/doc/api/app/app.php?chapter=9_5&index=7)

[](#queryrefund-doc)

```
$response = $gateway->queryRefund([
    'refund_id' => '1217752501201407033233368018', //Your site trade no, not union tn.
])->send();

var_dump($response->isSuccessful());
var_dump($response->getData());
```

### Shorten URL (for `WechatPay_Native`) [doc](https://pay.weixin.qq.com/wiki/doc/api/micropay.php?chapter=9_9&index=8)

[](#shorten-url-for-wechatpay_native-doc)

```
$response = $gateway->shortenUrl([
    'long_url' => $longUrl
])->send();

var_dump($response->isSuccessful());
var_dump($response->getData());
var_dump($response->getShortUrl());
```

### Query OpenId (for `WechatPay_Pos`) [doc](https://pay.weixin.qq.com/wiki/doc/api/micropay.php?chapter=9_13&index=9)

[](#query-openid-for-wechatpay_pos-doc)

```
$response = $gateway->shortenUrl([
    'auth_code' => $authCode
])->send();

var_dump($response->isSuccessful());
var_dump($response->getData());
var_dump($response->getOpenId());
```

For general usage instructions, please see the main [Omnipay](https://github.com/omnipay/omnipay)repository.

Related
-------

[](#related)

- [Laravel-Omnipay](https://github.com/ignited/laravel-omnipay)
- [Omnipay-Alipay](https://github.com/lokielse/omnipay-alipay)
- [Omnipay-UnionPay](https://github.com/lokielse/omnipay-unionpay)

Support
-------

[](#support)

If you are having general issues with Omnipay, we suggest posting on [Stack Overflow](http://stackoverflow.com/). Be sure to add the [omnipay tag](http://stackoverflow.com/questions/tagged/omnipay) so it can be easily found.

If you want to keep up to date with release anouncements, discuss ideas for the project, or ask more detailed questions, there is also a [mailing list](https://groups.google.com/forum/#!forum/omnipay) which you can subscribe to.

If you believe you have found a bug, please report it using the [GitHub issue tracker](https://github.com/lokielse/omnipay-wechatpay/issues), or better yet, fork the library and submit a pull request.

###  Health Score

34

—

LowBetter than 77% of packages

Maintenance29

Infrequent updates — may be unmaintained

Popularity7

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity74

Established project with proven stability

 Bus Factor1

Top contributor holds 87.5% 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 ~31 days

Recently: every ~24 days

Total

29

Last Release

2876d ago

Major Versions

v1.0.22 → v3.0.02018-01-22

### Community

Maintainers

![](https://www.gravatar.com/avatar/50f7bd7a793feaa7daf548a83f309180b38a26f943ded478eae4753f110d9653?d=identicon)[lyenrowe](/maintainers/lyenrowe)

---

Top Contributors

[![lokielse](https://avatars.githubusercontent.com/u/1573211?v=4)](https://github.com/lokielse "lokielse (63 commits)")[![php-cpm](https://avatars.githubusercontent.com/u/14024606?v=4)](https://github.com/php-cpm "php-cpm (4 commits)")[![lyenrowe](https://avatars.githubusercontent.com/u/11901387?v=4)](https://github.com/lyenrowe "lyenrowe (3 commits)")[![videni](https://avatars.githubusercontent.com/u/4058341?v=4)](https://github.com/videni "videni (1 commits)")[![zacksleo](https://avatars.githubusercontent.com/u/3369169?v=4)](https://github.com/zacksleo "zacksleo (1 commits)")

---

Tags

phpsdkpaymentgatewayapppayomnipaypurchasewechat

### Embed Badge

![Health badge](/badges/lyenrowe-omnipay-wechatpay/health.svg)

```
[![Health](https://phpackages.com/badges/lyenrowe-omnipay-wechatpay/health.svg)](https://phpackages.com/packages/lyenrowe-omnipay-wechatpay)
```

###  Alternatives

[lokielse/omnipay-wechatpay

Wechat gateway for Omnipay payment processing library

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

UnionPay gateway for Omnipay payment processing library

11358.1k2](/packages/lokielse-omnipay-unionpay)

PHPackages © 2026

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