支付网关 API 文档

版本 v1 · 基础地址 https://p.paysphere.cn

简介

本平台提供 RESTful 支付接口,商户使用 AppID / AppSecret 签名调用。

签名规则

  1. 除 sign 外,所有非空参数按 key 升序
  2. 拼接 k1=v1&k2=v2
  3. 使用 AppSecret 计算 HMAC-SHA256
  4. 十六进制结果转大写作为 sign
$str  = 'app_id=xxx&amount=1.00&...';
$sign = strtoupper(hash_hmac('sha256', $str, $appSecret));

基础信息

协议HTTPS
编码UTF-8
方法POST (application/x-www-form-urlencoded)
响应JSON

创建订单

POST /api/v1/order/create

参数必填说明
app_id是AppID
merchant_order_no是商户订单号(唯一)
amount是金额(元)
pay_type是alipay / wechat
subject否商品标题
notify_url否异步通知
return_url否同步跳转
sign是签名
{
  "code": 0,
  "data": {
    "order_no": "20240101123456",
    "pay_url": "https://p.paysphere.cn/pay/20240101123456?auto=1"
  }
}

查询订单

POST /api/v1/order/query

参数:app_id、order_no 或 merchant_order_no、sign

关闭订单

POST /api/v1/order/close

异步通知

支付成功后 POST 到 notify_url:

{
  "order_no": "...",
  "merchant_order_no": "...",
  "amount": "1.00",
  "trade_no": "...",
  "status": 1,
  "paid_at": "2024-01-01 12:00:00",
  "sign": "..."
}

返回 success 表示接收成功。

同步跳转

支付完成后跳转 return_url。

返回码

code说明
0成功
400参数错误
401签名错误
403商户禁用/冻结
404订单不存在

PHP 示例

<?php
$params = [
    'app_id'            => 'AKxxx',
    'merchant_order_no' => 'ORD_' . time(),
    'amount'            => '1.00',
    'pay_type'          => 'alipay',
    'subject'           => '测试商品',
];
ksort($params);
$str = implode('&', array_map(fn($k, $v) => $k . '=' . $v, array_keys($params), $params));
$params['sign'] = strtoupper(hash_hmac('sha256', $str, 'your_secret'));

$ch = curl_init('https://p.paysphere.cn/api/v1/order/create');
curl_setopt_array($ch, [
    CURLOPT_POST           => true,
    CURLOPT_POSTFIELDS     => http_build_query($params),
    CURLOPT_RETURNTRANSFER => true,
]);
print_r(json_decode(curl_exec($ch), true));