Skip to content

聚合支付统一下单

聚合支付统一下单接口是支付流程的核心接口,用于创建支付订单。支持微信支付、支付宝、银联等多种支付渠道。

接口信息

  • 接口地址
    /zro/pay/unify-pay
  • 请求方式POST
  • Content-Typeapplication/json

请求参数

公共参数

参数名类型必填长度描述
merchantNoString32商户号
signString32签名

业务参数

参数名类型必填描述示例值
orderIdString必填商户订单号,需保证在商户端不重复ORDER20231119001
orderAmountNumber必填订单总金额,单位:元,精确到小数点后两位100.00
goodsNameString必填商品名称,用于展示在收银台页面或支付明细中旺仔牛奶
payWayString必填支付方式,详见支付方式说明SDK_PAY
channelString必填支付渠道,详见支付渠道说明WECHAT
userIpString必填用户真实 IP 地址123.123.123.123
fundProcessTypeString分账订单标记,详见分账订单标记说明DELAY_SETTLE
returnSchemaString条件必填返回 APP 的 Schema,支付宝且 SDK_PAY 时必传alipays://...
notifyUrlString异步通知地址https://...
returnUrlString微信 H5 支付方式页面回跳地址https://...
expiredTimeString订单失效时间,默认 30 分钟2023-11-19 15:30

请求示例

json
{
  "merchantNo": "your_merchant_no",
  "orderId": "ORDER20231119001",
  "orderAmount": "100.00",
  "goodsName": "嗖付商城-iPhone手机壳",
  "payWay": "H5_PAY",
  "channel": "WECHAT",
  "userIp": "192.168.1.100",
  "returnSchema": "your_return_schema",
  "notifyUrl": "https://your-domain.com/notify",
  "returnUrl": "https://your-domain.com/return",
  "expiredTime": "2023-11-19 15:30:00",
  "sign": "A1B2C3D4E5F6G7H8I9J0K1L2M3N4O5P6"
}

响应参数

成功响应

参数名类型描述
codeNumber响应码,6000 表示成功
messageString响应信息
resultObject响应数据
request_idString请求 ID
timestampString响应时间

响应示例

成功响应

json
{
  "code": 6000,
  "message": "预付订单创建成功",
  "result": {
    "appId": "wxxc3xxcd4axxxe4d1",
    "timeStamp": "1766641816",
    "nonceStr": "f9e7axxaa9148a9866942319851d46d",
    "package": "prepay_id=wx25xxx3813b459xxxxxx9a20000",
    "signType": "RSA",
    "paySign": "dkU1MPGaJQMadXGtJhbbGdGg473nL7FCB..."
  },
  "request_id": "61a27b04-a1xx6-44c5-a6cc-43cae44943e3",
  "timestamp": "2023-09-25 13:50:16"
}

错误响应

json
{
  "code": 6015,
  "message": "下单失败"
}

支付渠道说明(channel)

渠道值说明
WECHAT微信
ALIPAY支付宝
UNIONPAY银联云闪付

支付方式说明(payWay)

方式值说明
SDK_PAYSDK 支付
H5_PAYH5 支付
MINI_PROGRAM小程序支付

分账订单标记说明(fundProcessType)

标记值说明
DELAY_SETTLE需要分账
REAL_TIME不需要分账

分账说明

#

开启订单分账标记后,系统自动匹配后台分账设置中已经打开的分账商户,按照设置的
(比例/金额) * 订单进行分账

代码示例

Java 示例

java
import com.sofu.pay.SofuPayClient;
import com.sofu.pay.model.UnifiedOrderRequest;
import com.sofu.pay.model.UnifiedOrderResponse;

public class PaymentExample {

    private SofuPayClient client = new SofuPayClient("your_merchant_no", "your_api_key");

    public void createOrder(String userIp) {
        UnifiedOrderRequest request = new UnifiedOrderRequest();
        request.setOrderId("ORDER" + System.currentTimeMillis());
        request.setOrderAmount("100.00");
        request.setGoodsName("测试订单");
        request.setBody("订单描述");
        request.setPayWay("H5_PAY");
        request.setChannel("WECHAT");
        request.setUserIp(userIp);
        request.setNotifyUrl("https://your-domain.com/notify");
        request.setReturnUrl("https://your-domain.com/return");

        try {
            UnifiedOrderResponse response = client.unifiedOrder(request);
            if (response.getCode() == 6000) {
                System.out.println("支付链接:" + response.getResult().getPayUrl());
                System.out.println("二维码:" + response.getResult().getQrCode());
            } else {
                System.out.println("创建订单失败:" + response.getMessage());
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

PHP 示例

php
<?php
require_once 'vendor/autoload.php';

use Sofu\Pay\SofuPayClient;

$client = new SofuPayClient('your_merchant_no', 'your_api_key');

$params = [
    'orderId' => 'ORDER' . time(),
    'orderAmount' => '100.00',
    'goodsName' => '测试订单',
    'body' => '订单描述',
    'payWay' => 'H5_PAY',
    'channel' => 'ALIPAY',
    'userIp' => $_SERVER['REMOTE_ADDR'],
    'notifyUrl' => 'https://your-domain.com/notify',
    'returnUrl' => 'https://your-domain.com/return'
];

try {
    $response = $client->unifiedOrder($params);
    if ($response['code'] === 6000) {
        echo "支付链接:" . $response['result']['payUrl'] . "\n";
        echo "二维码:" . $response['result']['qrCode'] . "\n";
    } else {
        echo "创建订单失败:" . $response['message'] . "\n";
    }
} catch (Exception $e) {
    echo "异常:" . $e->getMessage() . "\n";
}
?>

注意事项

重要提醒

  1. 订单号唯一性:商户订单号必须在商户端保持唯一,重复的订单号会返回已存在的订单信息
  2. 金额格式:订单金额必须为正数,格式为字符串,精确到小数点后两位
  3. 异步通知:必须正确处理异步通知,确保订单状态的准确性
  4. 订单有效期:订单创建后默认 30 分钟有效,过期后需重新创建
  5. 回调地址:notify_url 必须为外网可访问的 HTTP/HTTPS 地址

相关接口

嗖付聚合支付API文档