Skip to main content

报文加密规则

本平台提供的交易接口均使用HTTP协议对外提供服务,对于协议报文内容,采用以下方式进行加密验签。

假设所有发送或者接收到的数据为集合 M,将集合 M 内参数值的参数按照参数名 ASCII码从小到大排序(字典序),对参数值(即 value1value2value3...)拼接成字符串 strX

info
  1. 参数名ASCII 码从小到大排序(字典序)
  2. 签名原始串(strX)中,参数值均采用原始值,不进行 URL Encode
  3. platSign 是签名后产生的,在接收平台回调时,解密验签比对时,不要讲该字段纳入比对

开发人员可参考文档提供的示例来了解具体的加解密过程 示例Demo,下文对加密的过程进行详细说明。

假定用户发往服务器的原始报文内容如下:

{
"dateTime": "20200712205101",
"merchantCode": "S820200906085630000001",
"payMoney": "20000",
"method": "BRI",
"productDetail": "Buy Bus",
"phone": "06281235078907",
"name": "King",
"orderNum": "ORD1232r343",
"notifyUrl": "https://www.my.biz.com",
"expiryPeriod": "1440",
"email": "[email protected]"
}

先按键值排序,然后将参数值进行拼接,该报文内容产生待签名报文内容 strX 为:

[email protected]://www.my.biz.comORD1232r3432000006281235078907Buy Bus

然后使用商户生成的私钥(参考配置商户)对报文内容进行加密:

PH+WZVUQirCsmKN8DbHJeHuozWWEia0fUW+CkKU6iJ5z51sOfbGYoEZK6AsIYgD6THAi9h7kFlRkgU0+39Hh+1iQ0MJA403HBYmM9LmCkCx0xtEyRwaYKlhGu/48GFucIWTyxvi7DnkxpBHz8LQPWiIyklvo5T/2T/LX+FO2joO+xAXwCzPc1iG66yrWK4sXsYOO6Ge5z8XgaVfnCuaTqeIvKMffHY15sS45DxSxzkXV9xRM3nfryNn74d6UyrH7KpauCyKZhHxfQktKUvlgbf1nHJK35RRg/1vB02oKu3YjBD6aciQhQuasCx9H7c1mC/3tt0OymwokzFTwpiRVFA==

最后,将新生成的报文作为补充字段添加至原始报文中。完整的发送给服务器的数据报文为:

{
"dateTime": "20200712205101",
"merchantCode": "S820200906085630000001",
"payMoney": "20000",
"method": "BRI",
"productDetail": "Buy Bus",
"phone": "06281235078907",
"name": "King",
"orderNum": "ORD1232r343",
"notifyUrl": "https://www.my.biz.com",
"expiryPeriod": "1440",
"email": "[email protected]",
"sign": "PH+WZVUQirCsmKN8DbHJeHuozWWEia0fUW+CkKU6iJ5z51sOfbGYoEZK6AsIYgD6THAi9h7kFlRkgU0+39Hh+1iQ0MJA403HBYmM9LmCkCx0xtEyRwaYKlhGu/48GFucIWTyxvi7DnkxpBHz8LQPWiIyklvo5T/2T/LX+FO2joO+xAXwCzPc1iG66yrWK4sXsYOO6Ge5z8XgaVfnCuaTqeIvKMffHY15sS45DxSxzkXV9xRM3nfryNn74d6UyrH7KpauCyKZhHxfQktKUvlgbf1nHJK35RRg/1vB02oKu3YjBD6aciQhQuasCx9H7c1mC/3tt0OymwokzFTwpiRVFA=="
}