PHPackages                             phalapi/xunhupay - 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. phalapi/xunhupay

ActiveLibrary[Payment Processing](/categories/payments)

phalapi/xunhupay
================

PhalApi 2.x 虎皮椒支付扩展

231PHP

Since Jan 14Pushed 6y ago1 watchersCompare

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

READMEChangelogDependenciesVersions (1)Used By (0)

PhalApi 2.x 虎皮椒支付扩展
===================

[](#phalapi-2x-虎皮椒支付扩展)

安装
--

[](#安装)

修改composer.json文件，添加：

```
    "require": {
        "phalapi/xunhupay": "dev-master"
    },

```

然后再进行composer update操作。

如果要简化操作，可以直接使用composer命令进行安装：

```
$ composer require phalapi/xunhupay

```

安装好后，还需要在根目录的composer.json文件的psr-4中添加配置，以便在线接口文档可以加载扩展里面的接口。

```
{
    "autoload": {
        "psr-4": {
            "PhalApi\\Xunhupay\\":"vendor/phalapi/xunhupay/src",
            "App\\": "src/app"
        }
    }

}

```

此外，还需要把./vendor/phalapi/xunhupay/public/xunhupay\_notify.php文件复制到./public目录下，以便作为支付回调入口提供给虎皮椒调用。出于安全性考虑，文件名可以自行修改，但在配置时要同步修改。

在数据库中以下创建虎皮椒订单表：

```
CREATE TABLE `xunhupay_order` (
      `id` int(11) NOT NULL AUTO_INCREMENT,
      `trade_order_id` varchar(32) DEFAULT '' COMMENT '商户订单号',
      `payment` varchar(20) DEFAULT NULL COMMENT '支付接口标识',
      `total_fee` decimal(18,2) DEFAULT NULL COMMENT '订单金额(元)。单位为人民币，精确到分',
      `title` varchar(128) DEFAULT NULL COMMENT '订单标题',
      `add_time` int(11) DEFAULT NULL COMMENT '当前时间戳',
      `nonce_str` varchar(32) DEFAULT NULL COMMENT '随机值',
      `plugins` varchar(128) DEFAULT NULL COMMENT '备注',
      `order_status` int(11) DEFAULT '0' COMMENT '支付状态，0待支付1已支付',
      PRIMARY KEY (`id`),
      UNIQUE KEY `trade_order_id` (`trade_order_id`)
) ENGINE=InnoDB;
```

配置
--

[](#配置)

在./config/app.php配置中，添加以下虎皮椒支付扩展配置，并根据自己的情况修改里面的appid、appsecret、notify\_url。

```
return array(
    // 虎皮椒支付扩展配置
    'xunhupay' => array(
        // 接口地址，一般不需要修改
        'api' => array(
            'do' => 'https://api.xunhupay.com/payment/do.html',
            'query' => 'https://api.xunhupay.com/payment/query.html',
        ),
        // 微信支付
        'wechat' => array(
            'appid' => '2147483647', // TODO 修改成你的APPID
            'appsecret' => '160130736b1ac0d54ed7abe51e44840b', // TODO 修改成你的密钥
        ),
        // 支付宝支付
        'alipay' => array(
            'appid' => '2147483647', // TODO 修改成你的APPID
            'appsecret' => '160130736b1ac0d54ed7abe51e44840b', // TODO 修改成你的密钥
        ),
        'notify_url' => 'http://你的接口域名/xunhupay_notify.php', // TODO 成功支付后的回调地址
    ),
);
```

接口
--

[](#接口)

- 发起支付接口：PhalApi\\Xunhupay.Xunhupay.PaymentDo
- 查询支付接口：PhalApi\\Xunhupay.Xunhupay.OrderQuery
- 回调入口：[http://你的接口域名/xunhupay\_notify.php](http://%E4%BD%A0%E7%9A%84%E6%8E%A5%E5%8F%A3%E5%9F%9F%E5%90%8D/xunhupay_notify.php)

示例效果
----

[](#示例效果)

1、调用发起支付接口，可以选择直接接口跳转到支付页面，也可以先返回接口json结果然后客户端再跳转。例如返回：

```
{
    "ret": 200,
    "data": {
        "pay_url": "https://api.xunhupay.com/payments/wechat/index?id=20201381209&nonce_str=8976995811&time=1578991869&appid=2147483647&hash=51de5fa1a6cc9d4a0f6182d07970f927",
        "trade_order_id": "11888888898"
    },
    "msg": ""
}

```

打开pay\_url链接，进入在线支付页面，如：
[![](https://camo.githubusercontent.com/0f3c64894c107a0b6b9997dac340c72de320321bc6b4d1ce10b75ca9cf972fcb/687474703a2f2f63646e372e6f6b61796170692e636f6d2f7965737965736170695f32303230303131343136343931395f36623161313332363231656566626238393234353838363063313835656666392e706e67)](https://camo.githubusercontent.com/0f3c64894c107a0b6b9997dac340c72de320321bc6b4d1ce10b75ca9cf972fcb/687474703a2f2f63646e372e6f6b61796170692e636f6d2f7965737965736170695f32303230303131343136343931395f36623161313332363231656566626238393234353838363063313835656666392e706e67)

小结：

- 1、要么用ajax请求，把json拿回来，用js进行跳转（js\_jump=0）
- 2、要么直接把接口当作跳转链接，用a标签新窗口打开（js\_jump=1）

2、支付成功后，会回调到xunhupay\_notify.php，在里面进行业务的处理。

```
if($data['status']=='OD'){
	// 更新订单为已支付
	$model->update($orderInfo['id'], array('order_status' => 1));
    /************商户业务处理******************/
    //TODO:此处处理订单业务逻辑,支付平台会多次调用本接口(防止网络异常导致回调失败等情况)
    //     请避免订单被二次更新而导致业务异常！！！
    //     if(订单未处理){
    //         处理订单....
    //      }

    //....
    //...
    /*************商户业务处理 END*****************/
}else{
    //处理未支付的情况
}
```

手机扫码后，
[![](https://camo.githubusercontent.com/d90c027f1e8c2aeae3a91e744320558c1a7f4c162b2ce2ba1965fbfbefd48d59/687474703a2f2f63646e372e6f6b61796170692e636f6d2f7965737965736170695f32303230303131343136353430365f30616531666262646261646436633936643331313930633263616563333564362e706e67)](https://camo.githubusercontent.com/d90c027f1e8c2aeae3a91e744320558c1a7f4c162b2ce2ba1965fbfbefd48d59/687474703a2f2f63646e372e6f6b61796170692e636f6d2f7965737965736170695f32303230303131343136353430365f30616531666262646261646436633936643331313930633263616563333564362e706e67)

3、最后进行订单查询，当未支付时返回：

```
{
    "ret": 200,
    "data": {
        "errcode": 0,
        "errmsg": "",
        "data": {
            "open_order_id": "20201381200",
            "total_amount": "0.01",
            "title": "test",
            "status": "WP",
            "payment_method": "wechat",
            "transaction_id": null,
            "order_date": "2020-01-14 16:48:28",
            "paid_date": null,
            "pay_url": "weixin://wxpay/bizpayurl?pr=8R4Z3LI",
            "out_trade_order": "11888888898"
        }
    },
    "msg": ""
}

```

已支付后，返回：

```
{
    "ret": 200,
    "data": {
        "errcode": 0,
        "errmsg": "",
        "data": {
            "open_order_id": "20201381209",
            "total_amount": "0.01",
            "title": "test",
            "status": "OD",
            "payment_method": "wechat",
            "transaction_id": "4200000504202001141029026607",
            "paid_date": "2020-01-14 16:52:01",
            "pay_url": "weixin://wxpay/bizpayurl?pr=6Mprr2S",
            "out_trade_order": "11888888898"
        }
    },
    "msg": ""
}

```

4、数据库支付订单纪录

[![](https://camo.githubusercontent.com/bc88752bf241caa1bbfe69c58f6788e30d82a4962a97d3c6ca02339a09027ea5/687474703a2f2f63646e372e6f6b61796170692e636f6d2f7965737965736170695f32303230303131343136353532395f64643236646536303334313466323135333137393763616665636566393462612e706e67)](https://camo.githubusercontent.com/bc88752bf241caa1bbfe69c58f6788e30d82a4962a97d3c6ca02339a09027ea5/687474703a2f2f63646e372e6f6b61796170692e636f6d2f7965737965736170695f32303230303131343136353532395f64643236646536303334313466323135333137393763616665636566393462612e706e67)

参考
--

[](#参考)

- [虎皮椒开发文档](https://www.xunhupay.com/doc/api/search.html)

###  Health Score

19

—

LowBetter than 10% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity10

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity34

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.

### Community

Maintainers

![](https://www.gravatar.com/avatar/35d70b1236f8f67d96ba3da4ba88889faf2837ff8f7ab62acc54fe6cb4992c87?d=identicon)[dogstarhuang](/maintainers/dogstarhuang)

---

Top Contributors

[![dogstarTest](https://avatars.githubusercontent.com/u/6116306?v=4)](https://github.com/dogstarTest "dogstarTest (14 commits)")

### Embed Badge

![Health badge](/badges/phalapi-xunhupay/health.svg)

```
[![Health](https://phpackages.com/badges/phalapi-xunhupay/health.svg)](https://phpackages.com/packages/phalapi-xunhupay)
```

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