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

ActiveLibrary[Payment Processing](/categories/payments)

zfuming/omnipay-wxpay
=====================

Wechat gateway for Omnipay payment processing library

1.0(8y ago)7353MITPHP

Since Sep 8Pushed 8y ago1 watchersCompare

[ Source](https://github.com/zfuming/omnipay-wxpay)[ Packagist](https://packagist.org/packages/zfuming/omnipay-wxpay)[ Docs](https://github.com/zfuming/omnipay-wxpay)[ RSS](/packages/zfuming-omnipay-wxpay/feed)WikiDiscussions master Synced 2w ago

READMEChangelogDependencies (2)Versions (2)Used By (0)

Omnipay: WxPay
==============

[](#omnipay-wxpay)

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

[![Build Status](https://camo.githubusercontent.com/b622d816d991647b800c3929e3ae2fccafbf4f56d1317186decb9ee5a234bf15/68747470733a2f2f7472617669732d63692e6f72672f6c6f6b69656c73652f6f6d6e697061792d57785061792e706e673f6272616e63683d6d6173746572)](https://travis-ci.org/zfuming/omnipay-wxpay)[![Latest Stable Version](https://camo.githubusercontent.com/1766e1de9537c28eb663269189074aa097506c6a6bd84288781903e4b985986f/68747470733a2f2f706f7365722e707567782e6f72672f6c6f6b69656c73652f6f6d6e697061792d57785061792f76657273696f6e2e706e67)](https://packagist.org/packages/zfuming/omnipay-wxpay)[![Total Downloads](https://camo.githubusercontent.com/a2d5cd939bb599137930158621c76b9425d2722c014a002468a6000215cec772/68747470733a2f2f706f7365722e707567782e6f72672f6c6f6b69656c73652f6f6d6e697061792d57785061792f642f746f74616c2e706e67)](https://packagist.org/packages/zfuming/omnipay-wxpay)

> The WxPay gateway can be accessed from outside of China

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

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

[](#installation)

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

```
"zfuming/omnipay-wxpay": "^1.0",

```

And run composer to update your dependencies:

```
$ composer update -vvv

```

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

[](#basic-usage)

The following gateways are provided by this package:

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

Usage
-----

[](#usage)

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

[](#create-order-doc)

```
//gateways: WxPay_App, WxPay_Native, WxPay_Js, WxPay_Pos
$gateway    = Omnipay::create('WxPay_App');
$gateway->setAppId($config['app_id']);
$gateway->setMchId($config['mch_id']);
$gateway->setSubMchId($config['sub_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\WxPay\Message\CreateOrderRequest $request
 * @var Omnipay\WxPay\Message\CreateOrderResponse $response
 */
$request  = $gateway->purchase($order);
$response = $request->send();

//available methods
$response->isSuccessful();
$response->getData(); //For debug
$response->getAppOrderData(); //For WxPay_App
$response->getJsOrderData(); //For WxPay_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('WxPay');
$gateway->setAppId($config['app_id']);
$gateway->setMchId($config['mch_id']);
$gateway->setSubMchId($config['sub_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->getData());
}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 `WxPay_Native`) [doc](https://pay.weixin.qq.com/wiki/doc/api/micropay.php?chapter=9_9&index=8)

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

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

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

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

[](#query-openid-for-wxpay_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.

###  Health Score

30

—

LowBetter than 62% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity15

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity63

Established project with proven stability

 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

Unknown

Total

1

Last Release

3217d ago

### Community

Maintainers

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

---

Top Contributors

[![zfuming](https://avatars.githubusercontent.com/u/15259174?v=4)](https://github.com/zfuming "zfuming (2 commits)")

---

Tags

phpsdkpaymentgatewayapppayomnipaypurchasewechat

### Embed Badge

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

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

###  Alternatives

[lokielse/omnipay-wechatpay

Wechat gateway for Omnipay payment processing library

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

UnionPay gateway for Omnipay payment processing library

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

PHPackages © 2026

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