接口指南(签名规范)
开发者在接口请求和响应时,出于安全考虑采用双向签名,该文档讲述如何使用示例代码进行签名,参考本文档并使用示例代码,签名的接入将非常简单。
校验流程
客户端请求服务端,客户端将accessKey、timestamp、token设置到请求头中,根据客户端请求服务端签名规范生成token和服务端进行校验。
服务端响应客户端,服务端将timestamp、token设置到响应头中,根据服务端响应客户端签名规范生成头token和客户端进行校验。
客户端请求服务端签名规范:
-
1
|
https://openapi.duolabao.com/v1/customer/order/payresult/10001114596730086163709/10001277938612
|
|
726371591/315080832507485
|
请求头:
请求头 |
示例值 |
描述 |
accessKey |
fe02aa7e8f3249fe86c93774b7103d9945f80 |
用户的公钥 |
timestamp |
102202020202 |
时间戳 |
token |
44B74C2B0BDA30F8C949FC9F20FA5CB123E179E7 |
根据密钥和算法生成的结果 |
-
1
|
secretKey=0fa4484f19564326b224e18af5c0ad37ec725bc8×tamp=1467124971193&path=/v1/
|
|
customer/order/payresult/10001114596730086163709/10001277938612726371591/315080832507485
|
-
1
|
根据摘要进行sha1加密生成token
|
|
44B74C2B0BDA30F8C949FC9F20FA5CB123E179E7
|
-
1
|
https://openapi.duolabao.com/v1/customer/order/payurl/create
|
请求头:
请求头 |
示例值 |
描述 |
Content-Type |
application/json |
POST请求json格式数据,必需声明该类型 |
accessKey |
fe02aa7e8f3249fe86c93774b7103d9945f80 |
用户的公钥 |
timestamp |
102202020202 |
时间戳 |
token |
C9EF9BCE7138E21A353DE3F57187DC5E5396DD96 |
根据密钥和算法生成的结果 |
-
1
|
secretKey=0fa4484f19564326b224e18af5c0ad37ec725bc8×tamp=1467124971193
|
|
&path=/v1/customer/order/payurl/create&body=body体内容
|
|
body体内容如下
|
2
|
{
|
3
|
"customerNum": "10001114513826266541863",
|
4
|
"shopNum": "10001214653797401143127",
|
5
|
"machineNum": "10011014593073262477203",
|
6
|
"requestNum": "2014072300007148",
|
7
|
"amount": "100.00",
|
8
|
"tableNum": "15",
|
9
|
"source": "API",
|
10
|
"callbackUrl":"www.duolabao.com"
|
11
|
}
|
-
1
|
sha1加密生成token,token示例如下
|
|
C9EF9BCE7138E21A353DE3F57187DC5E5396DD96
|
服务端响应客户端签名:
响应头:
响应头 |
示例值 |
描述 |
timestamp |
1467124971193 |
时间戳 |
token |
B75DF2EA958D02931FE774EA487715252D874064 |
根据密钥和算法生成的结果 |
-
1
|
secretKey=0fa4484f19564326b224e18af5c0ad37ec725bc8×tamp=1467124971193
|
-
1
|
根据摘要进行sha1加密生成token
|
|
B75DF2EA958D02931FE774EA487715252D874064
|
错误码解释:
错误码 |
错误描述 |
解决方案 |
accessKeyError |
access key is error |
accessKey错误,请确认accessKey |
tokenError |
token is error |
token错误,请确认token是否合法 |
urlAuthError |
url auth is error |
url接口权限,请确认接口权限 |
accessKeyNotExist |
accessKey is not exist |
accessKey不存在,请确认accessKey |
jsonParserError |
json parser is error |
json解析错误,请确认json数据格式 |
jsonParamsError |
json params is error |
json参数错误,请确认json参数数据格式 |
userIllegalError |
user is illegal |
用户非法请求,请确认用户 |
systemError |
system is error |
系统错误 |