
Table of Contents
背景 Link to 背景
在体育馆预约系统中,支付流程是最后的关键环节。本文分析了支付流程的优化方法,并提供了详细的实现步骤。
通用请求头(Headers) Link to 通用请求头(Headers)
所有请求的 Headers 中,有以下共同部分:
JSON
123456
{
"Accept-Encoding": "gzip, deflate",
"Accept-Language": "zh-CN,zh-Hans;q=0.9",
"Connection": "keep-alive",
"User-Agent": "Mozilla/5.0 xxxxxx"
}
1. 获取支付页面 Link to 1. 获取支付页面
请求 Link to 请求
URL: GET http://xxx.xxx.xxx/index.php/index/user/pay.html?order_num=xxx
Cookie: iPlanetDirectoryPro=xxx; PHPSESSID=xxx
额外 Headers:
JSON
123456
{
"Host": "xxx.xxx.xxx",
"Upgrade-Insecure-Requests": "1",
"Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8",
"Referer": "http://xxx.xxx.xxx/index.php/index/user/index.html"
}
处理 Link to 处理
解析返回的 HTML,提取 sign
、sysid
、data
、subsysid
。
2. (可选)检查支付状态 Link to 2. (可选)检查支付状态
请求 Link to 请求
URL: POST http://xxx.xxx.xxx/index.php/index/user/check.html
Cookie: iPlanetDirectoryPro=xxx; PHPSESSID=xxx
额外 Headers:
JSON
123456789
{
"Host": "xxx.xxx.xxx",
"Accept": "application/json, text/javascript, */*; q=0.01",
"X-Requested-With": "XMLHttpRequest",
"Content-Type": "application/x-www-form-urlencoded; charset=UTF-8",
"Origin": "http://xxx.xxx.xxx",
"Referer": "http://xxx.xxx.xxx/index.php/index/user/pay.html?order_num=xxx",
"Content-Length": "xxx"
}
正确返回值 Link to 正确返回值
JSON
12345
{
"code": 1,
"time": 299,
"msg": "查询成功"
}
3. 发送支付请求 Link to 3. 发送支付请求
请求 Link to 请求
URL: POST http://xxx.xxx.xxx/index.php/index/user/gopay.html
Cookie: iPlanetDirectoryPro=xxx; PHPSESSID=xxx
额外 Headers:
JSON
123456789
{
"Host": "xxx.xxx.xxx",
"Accept": "application/json, text/javascript, */*; q=0.01",
"X-Requested-With": "XMLHttpRequest",
"Content-Type": "application/x-www-form-urlencoded; charset=UTF-8",
"Origin": "http://xxx.xxx.xxx",
"Referer": "http://xxx.xxx.xxx/index.php/index/user/pay.html?order_num=xxx",
"Content-Length": "xxx"
}
请求体:
JSON
1234
{
"order_num": "xxx",
"pay_type": "1"
}
正确返回值 Link to 正确返回值
JSON
12345
{
"code": 1,
"data": "",
"msg": "编辑成功"
}
4. 提交支付请求 Link to 4. 提交支付请求
请求 Link to 请求
URL: POST http://xxx.xxx.xxx/payment/pay/mobileAppPay.action
Cookie: iPlanetDirectoryPro=xxx
额外 Headers:
JSON
123456789
{
"Host": "xxx.xxx.xxx",
"Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8",
"Content-Type": "application/x-www-form-urlencoded",
"Origin": "http://xxx.xxx.xxx",
"Upgrade-Insecure-Requests": "1",
"Referer": "http://xxx.xxx.xxx/",
"Content-Length": "595"
}
请求体:
JSON
1234567
{
"sign": "xxx",
"sysid": "xxx",
"data": "xxx",
"subsysid": "xxx",
"pay_type": "1"
}
关键响应头 Link to 关键响应头
JSON
1234
{
"Set-Cookie": "JSESSIONID=xxx; Path=/payment; HttpOnly",
"Location": "https://xxx.xxx.xxx/connect/oauth2/authorize?appid=xxx&redirect_uri=http://xxx.xxx.xxx/payment
}
JSESSIONID
和 Location
是关键数据。
5. 微信支付 Link to 5. 微信支付
用户在微信中打开 Location
返回的 URL,带着JSESSIONID
然后重定向到支付界面,至此,主域名完成服务,支付的子域名开始工作,优化完毕。
感谢阅读!