360 Secure SkillHub
360 安全技能中心

【汇付支付斗拱】·(一键启动)自动通天·PHP历史最强全量支付方式全自动模式

提供汇付聚合支付下单接口的 PHP SDK 接入指引:说明 SDK 初始化、params 传参与响应解析方式,按 trade_type 覆盖微信、支付宝、银联的 JS、正扫、反扫场景,并给出异步通知处理与常见错误排查,参数细节拆分到多个 reference 文件。

fbz1234
fbz1234
热度 17.46
最近更新 2026-04-16 15:36:46
分类:开发依赖:代码执行 / 第三方 API应用场景:API 集成 / 代码生成 / 财务

安装技能

复制下面的话术发给你的 Agent,它会通过 secure-skills 检索并安装该技能。

执行命令安装此 skill: npx secure-skills-cli add huifu-dougong-full-payment-auto-php
Metadata
name
huifu-dougong-aggregation-order-php
display_name
汇付支付聚合支付下单(PHP)
description
汇付支付聚合支付下单的 PHP SDK Skill:覆盖微信公众号/小程序/APP、支付宝 JS / 正扫、银联 JS / 正扫、微信 / 支付宝 / 银联付款码等全场景聚合支付下单。语言适配层改为 PHP dg-php-sdk。当开发者需要用 PHP 创建聚合支付订单时使用。触发词:聚合支付下单、微信支付下单、支付宝下单、银联下单、二维码支付、付款码支付。
version
1.0.0
author
内容版权:上海汇付支付有限公司;PHP 适配层整理
homepage
https://paas.huifu.com/open/home/index.html
license
CC-BY-NC-4.0
compatibility
["openclaw"]
dependencies
["huifu-dougong-aggregation-base"]
metadata
{"openclaw":{"requires":{"config":["HUIFU_PRODUCT_ID","HUIFU_SYS_ID","HUIFU_RSA_PRIVATE_KEY","HUIFU_RSA_PUBLIC_KEY","HUIFU_NOTIFY_URL"]}}}

版权声明:本 Skill 内容来源于上海汇付支付有限公司官方开放平台文档,版权归属上海汇付支付有限公司。如有疑问可咨询汇付支付客服:400-820-2819 / cs@huifu.com

Source: Official Open Platform documentation of Shanghai Huifu Payment Co., Ltd.

Copyright: Shanghai Huifu Payment Co., Ltd.


聚合支付 - 下单(PHP 版)

覆盖微信/支付宝/银联全场景聚合支付下单,PHP SDK 适配。

适配版本与复核信息

项目 内容
Skill 版本 1.0.0
当前适配 SDK huifurepo/dg-php-sdk ^2.0
SDK Packagist composer require huifurepo/dg-php-sdk
SDK GitHub https://github.com/huifurepo/bspay-php-sdk
最后复核日期 2026-04-16
官方文档来源 汇付开放平台聚合支付下单接口文档、PHP SDK 文档、加验签说明、异步消息说明

PHP SDK 字段传参速查

协议字段 PHP 写法 说明
huifu_id "huifu_id" => "xxx" 直接写进 params 数组
trade_type "trade_type" => "T_JSAPI" 同上
method_expand "method_expand" => json_encode($methodExpand, JSON_UNESCAPED_UNICODE) 渠道扩展对象,先数组建模再序列化
acct_split_bunch "acct_split_bunch" => json_encode($split, JSON_UNESCAPED_UNICODE) 分账对象
terminal_device_data "terminal_device_data" => json_encode($device, JSON_UNESCAPED_UNICODE) 设备信息
combinedpay_data "combinedpay_data" => json_encode($arr, JSON_UNESCAPED_UNICODE) 补贴支付,直接写顶层
SDK 调用 (new BsPayClient())->postRequest($params) 命名空间 BsPaySdk\core
取响应 $result->getRspDatas()['data']['pay_info'] 用 getRspDatas() 取响应字段

SDK 初始化

⚠️ 必须使用官方 SDK,禁止裸 cURL 直接调用汇付 API。裸 cURL 会返回 HTTP 922(空响应),详见 aggregate-order-errors.md#http-922。

SDK 实际命名空间是 BsPaySdk,不是 Huifu\BsPay。SDK 需要手动 require_once init.php。

require_once 'vendor/autoload.php';
require_once 'vendor/huifurepo/dg-php-sdk/BsPaySdk/init.php';

use BsPaySdk\core\BsPay;
use BsPaySdk\core\BsPayClient;
use BsPaySdk\enums\FunctionCodeEnum;

// config.json 示例(注意键名是 rsa_merch_private_key / rsa_huifu_public_key):
// {
//   "product_id": "YOUR_PRODUCT_ID",
//   "sys_id": "YOUR_SYS_ID",
//   "rsa_merch_private_key": "BASE64_PRIVATE_KEY",
//   "rsa_huifu_public_key": "BASE64_PUBLIC_KEY"
// }
BsPay::init('/path/to/huifu-config.json');

PHP SDK 调用基础模式

use BsPaySdk\core\BsPayClient;
use BsPaySdk\enums\FunctionCodeEnum;

$params = [
    "funcCode" => FunctionCodeEnum::$V4_TRADE_PAYMENT_CREATE,
    "params"   => [
        "req_date"      => date("Ymd"),
        "req_seq_id"    => date("YmdHis") . mt_rand(1000, 9999),
        "huifu_id"      => "YOUR_HUIFU_ID",
        "trade_type"    => "T_JSAPI",
        "trans_amt"     => "1.00",
        "goods_desc"    => "商品描述",
        "method_expand" => json_encode($methodExpand, JSON_UNESCAPED_UNICODE),
        "notify_url"    => "https://your-domain.com/notify",
    ]
];

$result = (new BsPayClient())->postRequest($params);

if (!$result || $result->isError()) {
    $errInfo = $result ? $result->getErrorInfo() : '网络异常';
    throw new \Exception("SDK error: " . print_r($errInfo, true));
}

$rspDatas = $result->getRspDatas();
$data = $rspDatas['data'] ?? [];
if ($data['resp_code'] !== '00000000' && $data['resp_code'] !== '00000100') {
    throw new \Exception("业务失败: [{$data['resp_code']}] " . $data['resp_desc']);
}

// 受理成功,以 trans_stat 为终态依据
$transStat = $data['trans_stat'] ?? 'P';  // P=处理中,S=成功,F=失败
$hfSeqId   = $data['hf_seq_id'] ?? '';

运行依赖与凭据边界

本 Skill 依赖 huifu-dougong-aggregation-base 提供公共运行时。凭据使用规则见基础 Skill。

前置依赖:首次接入请先阅读 huifu-dougong-aggregation-base/SKILL.md 完成 SDK 初始化。

开发前先补两步:先核对客户前置准备清单,再按参数校验与 JSON 构造规范建模。sub_openid、buyer_id、auth_code、devs_id、customer_ip 这些值都不能让模型自行猜测。

端到端支付流程

[1] 下单 (本 Skill)
  -> [2] 用户支付 (前端处理)
  -> [3] 异步通知 (回调 notify)
  -> [4] 查询确认 (二次校验)
  -> [5] 退款 (可选)

步骤 1:下单(本 Skill)

调用 v4/trade/payment/create 创建支付订单,根据 trade_type 返回不同结果:

  • 正扫(NATIVE):返回 qr_code(二维码 URL)
  • JS 支付(JSAPI/MINIAPP):返回 pay_info(JS 调起参数)
  • 反扫(MICROPAY):同步返回支付结果

同时保存 req_seq_id 和 req_date(后续所有操作都需要)。

步骤 2:用户支付

  • 正扫:前端将 $data['qr_code'] 生成二维码展示,用户扫码支付
  • JS 支付:前端使用 $data['pay_info'] 调起微信/支付宝/银联支付(pay_info 已是 JSON 字符串,直接传前端)
  • 反扫:无需用户操作,商户扫描用户付款码后同步完成

步骤 3:接收异步通知

// notify.php
$rawBody = file_get_contents('php://input');
$notify  = json_decode($rawBody, true);
$respData = json_decode($notify['resp_data'] ?? '{}', true);

$hfSeqId  = $respData['hf_seq_id']  ?? '';
$transStat = $respData['trans_stat'] ?? '';
$transType = $respData['trans_type'] ?? ''; // 注意:异步字段名是 trans_type,不是 trade_type
$reqSeqId  = $respData['req_seq_id'] ?? '';

// 幂等处理
if (alreadyProcessed($hfSeqId)) {
    echo "RECV_ORD_ID_" . $reqSeqId;
    exit;
}

if ($transStat === 'S') {
    // 支付成功,更新订单状态
}

// 5 秒内必须返回
echo "RECV_ORD_ID_" . $reqSeqId;
exit;

场景路由

根据支付场景选择对应 trade_type:

用户意图 trade_type 返回关键字段 详细说明
微信公众号内支付 T_JSAPI pay_info 见 aggregate-order-method-wechat.md
微信小程序支付 T_MINIAPP pay_info 同上
微信APP支付 T_APP pay_info 同上
微信付款码(反扫) T_MICROPAY 同步结果 同上
支付宝JS支付 A_JSAPI pay_info 见 aggregate-order-method-alipay.md
支付宝正扫 A_NATIVE qr_code 同上
支付宝付款码(反扫) A_MICROPAY 同步结果 同上
银联JS支付 U_JSAPI pay_info 见 aggregate-order-method-unionpay.md
银联正扫 U_NATIVE qr_code 同上
银联付款码(反扫) U_MICROPAY 同步结果 同上

汇付 API 端点

属性 值
API 路径 v4/trade/payment/create
PHP SDK FunctionCode FunctionCodeEnum::$V4_TRADE_PAYMENT_CREATE
请求方式 POST
Content-Type application/json

常见错误与排查

错误码 原因 PHP 排查
10000000 参数校验失败 检查必填字段和格式,$data['resp_desc'] 有具体说明
20000000 重复交易 date("YmdHis") . mt_rand() 生成新 req_seq_id
22000000 产品号不存在 检查 config.json 中 product_id
22000002 商户信息不存在 检查 huifu_id
22000005 分账/费率/入驻配置有误 查 resp_desc 定位具体配置项
90000000 业务执行失败 查看 $data['resp_desc'] 详情
// PHP 错误处理示例
$respCode = $data['resp_code'] ?? '';
switch ($respCode) {
    case '00000000':
    case '00000100':
        // 受理成功,继续判断 trans_stat
        break;
    case '20000000':
        // 重复流水,换 req_seq_id 重试
        break;
    default:
        // 业务失败
        error_log("聚合下单失败: [{$respCode}] " . ($data['resp_desc'] ?? ''));
        break;
}

Reference 地图

文件 内容
references/aggregate-order.md 总览与阅读导航(PHP 入口)
references/aggregate-order-request.md 公共请求参数与顶层字段(PHP 传参列)
references/aggregate-order-method-wechat.md 微信请求与回调字段(PHP method_expand 示例)
references/aggregate-order-method-alipay.md 支付宝请求与回调字段(PHP method_expand 示例)
references/aggregate-order-method-unionpay.md 银联请求与回调字段(PHP method_expand 示例)
references/aggregate-order-tx-metadata.md 分账、补贴、设备、手续费对象(PHP 构造示例)
references/aggregate-order-response.md 同步返回、异步回调、解冻通知(PHP 解析示例)
references/aggregate-order-errors.md 返回码与文档勘误
references/quickstart.md 快速接入摘要(含全场景 PHP 代码)

版权声明:本 Skill 内容由开发者分享整理,基于上海汇付支付有限公司官方文档编写,版权归上海汇付支付有限公司所有。汇付天下斗拱校园交流群:https://paas.huifu.com/cms/details/m5SqYOn6n.html 欢迎加入!