1、接口的请求和响应的报文:采用JSON作为具体业务报文的载体
2、请求方式为:POST方式
3、报文中中文字符编码需要设置为:UTF-8
4、sign计算规则为:
(1) 筛选参数并排序
获取所有请求参数,不包含有子节点的参数,不包括字节类型参数,如文件、字节流,剔除sign字段,剔除值为空的参数(NULL或全空格都视为空),并按照第一个字符的键值ASCII码递增排序(字母升序排序),如果遇到相同字符则按照第二个字符的键值ASCII码递增排序,以此类推。
(2) 拼接参数
将排序后的参数与其对应值,组合成“参数参数值”的格式,并且把这些参数全部拼接起来,此时生成的字符串为待签名字符串。
(3) 计算签名
将待签名字符串首尾拼接密钥后,进行md5运算,并转为大写
5.报文及sign计算示例
- 如以下请求报文
{
"request_type": "scanpay_request",
"isspid": "39493002",
"pos_id": "1511300001",
"store_id": "1511300001",
"pos_seq": "1812100000002",
"user_id": "imageco",
"system_id": "8888",
"scanpay_request": {
"pay_type": "502",
"tx_amt": "1",
"goods_detail": [
{
"goods_id": "apple-01啊",
"payment_goods_id": "20010001",
"goods_name": "ipad",
"quantity": 1,
"price": 200000,
"goods_category": "34543238",
"body": "特价手机",
"show_url": "http://www.alipay.com/xxx.jpg"
},
{
"goods_id": "apple-02额",
"payment_goods_id": "20010002",
"goods_name": "ipad2",
"quantity": 1,
"price": 200000,
"goods_category": "34543239",
"body": "特价手机2",
"show_url": "http://www.alipay.com/xxx2.jpg"
}
]
}
}
- 接入密钥为
test
(1) 筛选参数并排序
"isspid":"39493002"
"pos_id":"1511300001"
"pos_seq":"1812100000002"
"request_type":"scanpay_request"
"store_id":"1511300001"
"system_id":"8888"
"user_id":"imageco"
(2) 拼接参数生成待签名字符串
isspid39493002pos_id1511300001pos_seq1812100000002request_typescanpay_requeststore_id1511300001system_id8888user_idimageco
(3) 计算sign值
md5(testisspid39493002pos_id1511300001pos_seq1812100000002request_typescanpay_requeststore_id1511300001system_id8888user_idimagecotest)
=b7eee879c312adb820f44588d32c8222
(4) 将计算出的sign值转为大写放入请求报文形成最终请求JSON
{
"request_type": "scanpay_request",
"isspid": "39493002",
"pos_id": "1511300001",
"store_id": "1511300001",
"pos_seq": "1812100000002",
"user_id": "imageco",
"system_id": "8888",
"scanpay_request": {
"pay_type": "502",
"tx_amt": "1",
"goods_detail": [
{
"goods_id": "apple-01啊",
"payment_goods_id": "20010001",
"goods_name": "ipad",
"quantity": 1,
"price": 200000,
"goods_category": "34543238",
"body": "特价手机",
"show_url": "http://www.alipay.com/xxx.jpg"
},
{
"goods_id": "apple-02额",
"payment_goods_id": "20010002",
"goods_name": "ipad2",
"quantity": 1,
"price": 200000,
"goods_category": "34543239",
"body": "特价手机2",
"show_url": "http://www.alipay.com/xxx2.jpg"
}
]
},
"sign": "B7EEE879C312ADB820F44588D32C8222"
}