PHPackages                             winwin/pay-sdk - 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. winwin/pay-sdk

ActiveProject[Payment Processing](/categories/payments)

winwin/pay-sdk
==============

0.2.1(10mo ago)36.3kPHPPHP &gt;= 5.6

Since Apr 24Pushed 10mo ago4 watchersCompare

[ Source](https://github.com/winwin-inc/pay-sdk)[ Packagist](https://packagist.org/packages/winwin/pay-sdk)[ RSS](/packages/winwin-pay-sdk/feed)WikiDiscussions master Synced 3w ago

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

码上赢支付SDK
========

[](#码上赢支付sdk)

安装
--

[](#安装)

使用 [composer](http://getcomposer.org/):

```
$ composer require winwin/pay-sdk
```

配置
--

[](#配置)

调用接口需要先创建 payment 对象：

```
use winwin\pay\sdk\Config;
use winwin\pay\sdk\payment\Payment;

$payment = new Payment(new Config([
    'appid' => $appid,
    'secret' => $secret,
]));
```

appid 和 secret 需要申请获取。

创建订单
----

[](#创建订单)

```
use winwin\pay\sdk\payment\Order;

$result = $payment->prepare(new Order([
    'mch_id' => $merchant_id,
    'method' => 'pay.weixin.jsapi',
    'body' => '支付1分',
    'total_fee' => 1,
    'out_trade_no' => date('ymdHis') . mt_rand(1000, 9999),
    'notify_url' => 'http://example.org/notify',
    'openid' => $openid,
]));
```

mch\_id 需要申请获取。

openid 需要网页授权获取，参考[微信官方文档](https://mp.weixin.qq.com/wiki?action=doc&id=mp1421140842&t=0.04999664287487349#1)。

处理支付异步通知
--------

[](#处理支付异步通知)

```
$response = $payment->handleNotify(function($notify, $successful) {
    // 处理逻辑
    return true;
});
echo $response->getBody();
```

`handleNotify` 接收一个回调函数，该回调函数接收两个参数，这两个参数分别为：

- `$notify` 为封装了通知信息的数组对象，可以使用对象或者数组形式来读取通知内容，比如：`$notify->total_fee` 或者 `$notify['total_fee']`。
- `$successful` 用于判断用户是否付款成功了

回调函数返回 false 或者一个具体的错误消息，那么系统会在稍后再次继续通知你，直到你明确的告诉它：“我已经处理完成了”，在函数里 `return true;` 代表处理完成。

`handleNotify` 返回值 `$response` 是一个 [PSR-7](http://www.php-fig.org/psr/psr-7/) Response 对象。

订单查询
----

[](#订单查询)

```
use winwin\pay\sdk\payment\OrderQuery;

$result = $payment->query(new OrderQuery([
    'mch_id' => $merchant_id,
    'method' => 'trade.query',
    'transaction_id' => '平台订单号',
    'out_trade_no' => '商户订单号',
]));
```

关闭订单
----

[](#关闭订单)

```
use winwin\pay\sdk\payment\CloseOrder;

$result = $payment->close(new CloseOrder([
    'mch_id' => $merchant_id,
    'method' => 'trade.close',
    'out_trade_no' => '商户订单号',
]));
```

退款
--

[](#退款)

```
use winwin\pay\sdk\payment\Refund;

$result = $payment->refund(new Refund([
    'mch_id' => $merchant_id,
    'method' => 'trade.refund',
    'transaction_id' => '平台订单号',
    'out_trade_no' => '商户订单号',
    'out_refund_no' => '商户退款单号',
    'total_fee' => 1,
    'refund_fee' => 1,
    'op_user_id' => $merchant_id,
]));
```

退款查询
----

[](#退款查询)

```
use winwin\pay\sdk\payment\RefundQuery;

$result = $payment->queryRefund(new RefundQuery([
    'mch_id' => $merchant_id,
    'method' => 'trade.refund.query',
    'transaction_id' => '平台订单号',
    'out_trade_no' => '商户订单号',
    'out_refund_no' => '商户退款单号',
    'refund_id' => '平台退款单号',
]));
```

调试
--

[](#调试)

如果需要打印 http 请求日志，可使用 [PSR-3](http://www.php-fig.org/psr/psr-3/) 实现库，例如 [Monolog](https://github.com/Seldaek/monolog) ：

```
use Monolog\Logger;
use Monolog\Handler\StreamHandler;
$logger = new Logger('WinwinPay');
$logger->pushHandler(new StreamHandler('php://stderr', Logger::DEBUG));

$payment->setLogger($logger);
```

###  Health Score

36

—

LowBetter than 79% of packages

Maintenance54

Moderate activity, may be stable

Popularity21

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity51

Maturing project, gaining track record

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

Total

4

Last Release

316d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/28c8284abda0bddba804c7919864a36b925898741745ff910f98cd7f2fd73625?d=identicon)[wenbinye](/maintainers/wenbinye)

---

Top Contributors

[![wenbinye](https://avatars.githubusercontent.com/u/1221975?v=4)](https://github.com/wenbinye "wenbinye (1 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/winwin-pay-sdk/health.svg)

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

###  Alternatives

[laravel/framework

The Laravel Framework.

34.8k543.8M19.8k](/packages/laravel-framework)[tempest/framework

The PHP framework that gets out of your way.

2.2k34.4k13](/packages/tempest-framework)[drupal/core

Drupal is an open source content management platform powering millions of websites and applications.

21866.0M1.7k](/packages/drupal-core)[drupal/core-recommended

Locked core dependencies; require this project INSTEAD OF drupal/core.

6942.5M413](/packages/drupal-core-recommended)[civicrm/civicrm-core

Open source constituent relationship management for non-profits, NGOs and advocacy organizations.

751291.4k40](/packages/civicrm-civicrm-core)[avalara/avataxclient

Client library for Avalara's AvaTax suite of business tax calculation and processing services. Uses the REST v2 API.

528.5M7](/packages/avalara-avataxclient)

PHPackages © 2026

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