💴 API接口支付
POST
https://ypay.leikeb.cn/mapi.php
接口描述
POST数据:pid={商户ID}&type={支付方式}&out_trade_no={商户订单号}¬ify_url={服务器异步通知地址}&return_url={页面跳转通知地址}&name={商品名称}&money={金额}&sitename={网站名称}&sign={签名字符串}&sign_type=MD5
请求参数
字段名
参数名
必填
类型
示例值
描述
商户ID
pid
必填
Int
1000
商户ID
支付方式
type
必填
String
alipay
alipay:支付宝, qqpay:QQ钱包, wxpay:微信支付
商户订单号
out_trade_no
必填
String
20160806151343349
商户订单号
异步通知地址
notify_url
必填
String
http://站点域名/notify.php
服务器异步通知地址
跳转通知地址
return_url
必填
String
http://站点域名/return.php
页面跳转通知地址
商品名称
name
必填
String
一个奥利奥
商品名称
商品金额
money
必填
String
1.00
商品金额
网站名称
sitename
选填
String
测试站点
网站名称
签名字符串
sign
必填
String
5d9e7a8c3b1f4e6d...
签名字符串,签名算法见下方说明
签名类型
sign_type
必填
String
MD5
默认为MD5
响应参数
字段名
参数名
类型
示例值
描述
返回状态码
code
Int
200
200为成功,201为失败
返回信息
msg
String
获取成功!
成功/失败时返回对应信息
金额
money
String
1.00
支付金额
订单号
trade_no
String
Y2026063012300012345
平台订单号
二维码链接
qrcode
String
wxp://f2f15IaTGck...
第三方生成二维码的内容
二维码图片
code_url
String
http://xxx/qrcode.php?text=xxx
二维码图片完整URL
过期时间
out_time
Int
1719847200
订单过期时间戳
签名算法
1
参数排序
按key升序排序
→
2
拼接字符串
key=value&key=value
→
3
添加密钥
末尾直接拼接密钥
→
4
MD5加密
结果即为sign
签名计算示例
商户密钥
test_key_123456
📋 提交的参数
pid=1000&type=alipay&out_trade_no=2026063012300012345¬ify_url=http://xxx.com/notify.php&return_url=http://xxx.com/return.php&name=测试商品&money=1.00
Step 1 - 按key升序排序
money, name, notify_url, out_trade_no, pid, return_url, type
Step 2 - 拼接成 key=value&key=value 格式
money=1.00&name=测试商品¬ify_url=http://xxx.com/notify.php&out_trade_no=2026063012300012345&pid=1000&return_url=http://xxx.com/return.php&type=alipay
Step 3 - 末尾直接拼接商户密钥
money=1.00&name=测试商品¬ify_url=http://xxx.com/notify.php&out_trade_no=2026063012300012345&pid=1000&return_url=http://xxx.com/return.php&type=alipaytest_key_123456
Step 4 - MD5加密结果
md5(Step3字符串) = c859e25ee0eb2d03600fb5d761d10eac
请求示例
POST
/mapi.php
Content-Type: application/x-www-form-urlencoded
pid=1000&type=alipay&out_trade_no=2026063012300012345¬ify_url=http://xxx.com/notify.php&return_url=http://xxx.com/return.php&name=测试商品&money=1.00&sign_type=MD5&sign=c859e25ee0eb2d03600fb5d761d10eac
响应示例
✅ 成功响应
{
"code": 200,
"msg": "获取成功!",
"money": "1.00",
"trade_no": "Y2026063012300012345",
"qrcode": "wxp://xxx",
"code_url": "http://xxx/qrcode.php?text=xxx",
"out_time": 1719847200
}
❌ 失败响应
{
"code": 201,
"msg": "验签失败,请检查PID或者Key是否正确!"
}
PHP示例代码
PHP
完整签名和请求示例
<?php
// 商户信息
$pid = '1000';
$key = 'test_key_123456';
// 支付参数
$params = [
'pid' => $pid,
'type' => 'alipay',
'out_trade_no' => date('YmdHis') . mt_rand(1000, 9999),
'notify_url' => 'http://xxx.com/notify.php',
'return_url' => 'http://xxx.com/return.php',
'name' => '测试商品',
'money' => '1.00',
'sign_type' => 'MD5',
];
// 签名
ksort($params);
$signStr = http_build_query($params);
$signStr .= '&key=' . $key;
$params['sign'] = md5($signStr);
// 发起API请求
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'http://xxx.com/mapi.php');
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
curl_close($ch);
// 解析响应
$result = json_decode($response, true);
$result['code'] == 200 ? print_r($result) : print_r($result['msg']);
Python示例代码
Python
完整签名和请求示例
import requests
import hashlib
# 商户信息
pid = '1000'
key = 'test_key_123456'
# 支付参数
params = {
'pid': pid,
'type': 'alipay',
'out_trade_no': '2026063012300012345',
'notify_url': 'http://xxx.com/notify.php',
'return_url': 'http://xxx.com/return.php',
'name': '测试商品',
'money': '1.00',
'sign_type': 'MD5',
}
# 签名
sorted_params = sorted(params.items(), key=lambda x: x[0])
sign_str = '&'.join(f'{k}={v}' for k, v in sorted_params)
sign_str += f'&key={key}'
params['sign'] = hashlib.md5(sign_str.encode('utf-8')).hexdigest()
# 发起API请求
response = requests.post('http://xxx.com/mapi.php', data=params)
result = response.json()
result['code'] == 200 print(result) print(result['msg'])
在线调试
响应结果
开发建议
参数大小写
money和Money是不同的参数,签名时注意区分
URL编码
参数值不需要URL编码,系统会自动处理
密钥保管
商户密钥是唯一凭证,请妥善保管切勿泄露