标准API支付
POST
https://pay.phpwc.com/initiatepay
本接口直接返回上游支付网关的原生支付信息(HTML 表单 / 跳转 URL),由开发者自行决定如何渲染或调用。
典型场景:原生 App 内嵌 H5、自研收银台、前端直接调用支付宝 PC/WAP 网关。
请求参数
| 参数名 | 必填 | 类型 | 验签 | 示例值 | 说明 |
|---|---|---|---|---|---|
pid | 是 | Int | 是 | 1000 | 商户ID |
type | 是 | String | 是 | alipay | 支付方式 |
out_trade_no | 是 | String | 是 | 20160806151343349 | 商户请求单号(唯一) |
notify_url | 是 | String | 是 | https://域名/notify_url.php | 服务器异步通知地址(本接口必填) |
return_url | 是 | String | 是 | https://域名/return_url.php | 页面跳转通知地址 |
name | 是 | String | 是 | 充值100元 | 商品名称 |
money | 是 | String | 是 | 1.00 | 商品金额(元) |
device | 是 | String | 是 | pc | 设备类型 |
clientip | 是 | String | 是 | 192.168.1.100 | 用户发起支付的IP地址 |
buyer_id | 否 | String | 是 | 18888888888 | 买家识别号 |
tdid | 否 | Int | 是 | 4665 | 指定商户支付通道ID |
param | 否 | String | 是 | &id=1&lx=2 | 自定义参数 |
sign | 是 | String | 否 | 202cb962ac... | 签名字符串 |
sign_type | 否 | String | 否 | MD5 | 签名类型,默认 MD5 |
响应参数(JSON)
| 参数名 | 类型 | 说明 |
|---|---|---|
code | Int | 1=接口调用成功,其他值=接口调用失败 |
msg | String | 提示信息 |
out_trade_no | String | 商户订单号(与请求一致) |
money | String | 商品金额(与请求一致) |
type | String | 支付原料类型,取值见下表 |
content | String | 上游原生支付信息(含义随 type 变化) |
type 取值说明
| type | content 含义 | 开发者处理建议 |
|---|---|---|
payurl | 跳转 URL(支付宝 PC、微信授权、码牌、H5 跳转) | 将浏览器 302 跳转或前端 window.location 到该地址 |
payform | 自动提交 HTML 表单(支付宝 WAP 常用) | 把 HTML 字符串直接写入文档,浏览器会自动提交到支付宝网关 |
失败响应
| 参数名 | 类型 | 说明 |
|---|---|---|
code | Int | 0=接口调用失败 |
msg | String | 错误原因,格式:PID:xxx,通道ID:xxx,错误原因:XXX-网程PAY |
请求示例
// 请求方式:application/x-www-form-urlencoded
{
"pid": 1000,
"type": "wxpay",
"out_trade_no": "20160806151343349",
"notify_url": "https://域名/notify_url.php",
"return_url": "https://域名/return_url.php",
"name": "充值100元",
"money": "1.00",
"device": "pc",
"clientip": "192.168.1.100",
"sign": "202cb962ac...",
"sign_type": "MD5"
}响应示例(type = payurl)
// 支付宝 PC、微信授权、码牌、H5 跳转
{
"code": 1,
"msg": "下单成功,请按[type]字段处理支付。",
"out_trade_no": "20160806151343349",
"money": "1.00",
"type": "payurl",
"content": "https://openapi.alipay.com/gateway.do?app_id=..."
}响应示例(type = payform)
// 支付宝 WAP 自动提交表单
{
"code": 1,
"msg": "下单成功,请按[type]字段处理支付。",
"out_trade_no": "20160806151343349",
"money": "1.00",
"type": "payform",
"content": "<form id='alipaysubmit' name='alipaysubmit' action='https://openapi.alipay.com/gateway.do' method='post'>...</form><script>document.forms['alipaysubmit'].submit();</script>"
}失败响应示例
{
"code": 0,
"msg": "PID:1000,通道ID:4871,错误原因:未匹配到可用支付通道-网程PAY"
}前端处理参考(伪代码)
fetch('/initiatepay', { method: 'POST', body: formData })
.then(r => r.json())
.then(data => {
if (data.code !== 1) { alert(data.msg); return; }
switch (data.type) {
case 'payurl':
window.location.href = data.content;
break;
case 'payform':
document.write(data.content); // 自动提交表单
break;
}
});