# 中国电子口岸报文加签验证

统一加签接口: http://localhost:8080/rpc/eport/signature

## 1 海关总署311 `XML`加签验证

入参:

![image-20220215180751937](https://alphahub-test-bucket.oss-cn-shanghai.aliyuncs.com/image/image-20220215180751937.png)

响应:

```json
{
  "message": "操作成功",
  "success": true,
  "timestamp": "2022-02-15 17:53:27",
  "code": 200,
  "data": {
    "success": true,
    "certNo": "01691f7f",
    "x509Certificate": " ",
    "digestValue": "wz3Mne4HAnnHGeKvHv4LxU2ysuc=",
    "signatureValue": "JjKKuzwbl8+aHdmNNM4gVQI5R9NRyeDhzTL2huJnU4kD9nN35pYJ7pMzquCFhNUvns89GN/Aim0DSAlXMa63aSSw3ad4wvmKjYBl24U+S1KYbX2mKhwkJIK6Ic8bWLuu5eC6+h0+Gttvo7baQT11w0I0xfDyBH7awuddcZyaLIU="
  }
}
```

自行生成用返回数据组装`xml`, 311推单,  `xml`预览:

![image-20220215181303331](https://alphahub-test-bucket.oss-cn-shanghai.aliyuncs.com/image/image-20220215181303331.png)

省略发请求直接看返回:

![image-20220215181519216](https://alphahub-test-bucket.oss-cn-shanghai.aliyuncs.com/image/image-20220215181519216.png)

查询验签是否通过:

![image-20220215181718468](https://alphahub-test-bucket.oss-cn-shanghai.aliyuncs.com/image/image-20220215181718468.png)

回执单查询: 

```tex
http://36.101.208.230:8090/ceb312msg?dxpid=DXPENT0000458763&qryid=202202151758
```



响应:

```json
[
  {
    org_id=1,
    instm=1644919105000,
    re_order_guid=CEB311_HNZB_FXJK_20220215175237_0013,
    returnstatus=2,
    ebpcode=46121601BC,
    returntime2=20220215175825,
    ebccode=46121601BC,
    trans_dxpid=DXPENT0000458763,
    returninfo=新增申报成功
  [
    CEB311_HNZB_FXJK_20220215175237_0014
  ],
  returntime=1644919100000,
  orderno=20220215148803180891992064
  }
]
```

## 2 海关总署621 `XML`加签验证

http://localhost:8080/rpc/eport/signature

![image-20220215183948685](https://alphahub-test-bucket.oss-cn-shanghai.aliyuncs.com/image/image-20220215183948685.png)

```json
{
  "message": "操作成功",
  "success": true,
  "timestamp": "2022-02-15 19:14:41",
  "code": 200,
  "data": {
    "success": true,
    "certNo": "01691f7f",
    "x509Certificate": "MIIE+zCCBGSgAwIBAgIEAWkffzANBgkqhkiG9w0BAQUFADB8MQswCQYDVQQGEwJj\nbjEVMBMGA1UECh4MTi1W/XU1W1BT41y4MRUwEwYDVQQLHgyLwU5me6F0Bk4tX8Mx\nDTALBgNVBAgeBFMXTqwxITAfBgNVBAMeGE4tVv11NVtQThpSoYvBTmZ7oXQGTi1f\nwzENMAsGA1UEBx4EUxdOrDAeFw0yMTA1MzEwMDAwMDBaFw0zMTA1MzEwMDAwMDBa\nMB4xDzANBgNVBAMeBoSLWSdOOjELMAkGA1UEEh4CADEwgZ8wDQYJKoZIhvcNAQEB\nBQADgY0AMIGJAoGBAMtI8VNQW/F/tP4KvX6I8qV1IkthY596m59Cy1nWcYdq2MkJ\n9x7F35VekgJxbVumHTNJSBbOZs1hGTeuKaTLl3+xMhLQ+YQ4kfvJUwcbCIdPTewq\nrCyJAq1UKTTHjxgudwUahb9IviSzDo0j4PJtCommbd84EO7SxNiLw6Rpg9QnAgMB\nAAGjggLmMIIC4jALBgNVHQ8EBAMCBsAwCQYDVR0TBAIwADCBpwYDVR0jBIGfMIGc\ngBT5daN4RQtCaMIEU6vrw04+VHh0YKGBgKR+MHwxCzAJBgNVBAYTAmNuMRUwEwYD\nVQQKHgxOLVb9dTVbUFPjXLgxFTATBgNVBAseDIvBTmZ7oXQGTi1fwzENMAsGA1UE\nCB4EUxdOrDEhMB8GA1UEAx4YTi1W/XU1W1BOGlKhi8FOZnuhdAZOLV/DMQ0wCwYD\nVQQHHgRTF06sggEAMB0GA1UdDgQWBBT1YEuTpXfAwy4GwPYMasIvwDCwaDBCBgNV\nHSAEOzA5MDcGBiuBBwEBAjAtMCsGCCsGAQUFBwIBFh9odHRwOi8vY3BzLmNoaW5h\ncG9ydC5nb3YuY24vQ1BTMHIGA1UdHwRrMGkwMKAuoCyGKmxkYXA6Ly9sZGFwLmNo\naW5hcG9ydC5nb3YuY246Mzg5LzAwMC0xLmNybDA1oDOgMYYvaHR0cDovL2xkYXAu\nY2hpbmFwb3J0Lmdvdi5jbjo4MDg4L2R6a2EwMDAtMS5jcmwwbQYIKwYBBQUHAQEE\nYTBfMC4GCCsGAQUFBzABhiJodHRwOi8vb2NzcC5jaGluYXBvcnQuZ292LmNuOjg4\nMDAvMC0GCCsGAQUFBzABhiFodHRwOi8vb2NzcC5jaGluYXBvcnQuZ292LmNuOjgw\nODgwKgYKKwYBBAGpQ2QFAQQcFhq6o8TP0Me0tLulwarN+NK90qnT0M/euavLvjAS\nBgorBgEEAalDZAUDBAQWAjAxMCIGCisGAQQBqUNkBQgEFBYSMzQxMDAzMTk4MzAx\nMTMwNDEwMB0GCisGAQQBqUNkBQkEDxYNSkowRzkwMDE1OTI3MTAZBgorBgEEAalD\nZAULBAsWCU1BNVRMVUE1MzASBgorBgEEAalDZAUMBAQWAjAwMBIGCisGAQQBqUNk\nAgQEBBYCMTQwEgYKKwYBBAGpQ2QCAQQEFgIxMDANBgkqhkiG9w0BAQUFAAOBgQA4\nw5rNt9NIi8S1vhNjMU/qH7IkX79X3B1wHwiuLvMZPnRPNY0xO0uDc2lme8RDHDxC\nk7RhUupgDbgQIiEwITWYaqNP499wkQ8EK88wLRCiuybcFGTl5MXyOIpfZtaDnRcU\nu2Edyt07vcIEWgtJmR6TTEBehCE14v+fIKuAcFDPTg==\n",
    "digestValue": "5nkQYKEtVilTfyWeWDr8Q+WuFNM=",
    "signatureValue": "mclW30swezmNfgpftA0j6cJz0qoqEaHyu9Q/TD1605k76mYsEzre2i3XdTiyWfXw8RLmVlvS/LTThc64iUIr8Dd5AZqaOBOeD8wHZ2AJ9B6emX9c3P7KfWXz4VF1k47TQg8MjGGpOS/zE+s2pIJWGa8y6ku7s3Rwro92mZ1INag="
  }
}
```

![image-20220215192458799](https://alphahub-test-bucket.oss-cn-shanghai.aliyuncs.com/image/image-20220215192458799.png)

直接看推推单结果

![image-20220215191938907](https://alphahub-test-bucket.oss-cn-shanghai.aliyuncs.com/image/image-20220215191938907.png)

回执查询响应

![image-20220215192525860](https://alphahub-test-bucket.oss-cn-shanghai.aliyuncs.com/image/image-20220215192525860.png)

回执单查询: 

```tex
http://36.101.208.230:8090/ceb622msg?dxpid=DXPENT0000458763&qryid=202202151758
```





## 3 海关179数据抓取验证

详见第4节

## 4 `U-KEY`加签`signatureValue`和`U-KEY`无关验证

以`海关179数据抓取`加签为例：

[互联网+海关窗口](https://customs.chinaport.gov.cn/deskserver/cus/deskIndex?menu_id=swcebimp)

**服务管理**  -> **服务注册管理**的证书编号: `01691fe9`

加签**海关179数据抓取**`ukey`的证书编号: `01691f7f`

步骤：

- 在推送**海关179数据**前弄个断点把`01691fe9`签名的`signatureValue`替换成`01691f7f`加签返回的`signatureValue`的值,

![image-20220217112041770](https://alphahub-test-bucket.oss-cn-shanghai.aliyuncs.com/image/image-20220217112041770.png)

先看`01691fe9`
加签返回结果：`Ocrba9PVqkNluFxjKdxVqbAMdqxq5B4EbmSqapdRL0WIblkG7cIeaOG/dMV3V2JoLAQuTtYDm7QNz9kfZGFgqFyHHVQWIRZbz7prchjI9rFXDGIRGafleX+gdlindZWE9p3ptROWcpKmBmVhg4aNBoVI0zETj8s25ewQQBpnrlM=`

- 使用`01691f7f`加签数据

访问项目: http://127.0.0.1:8080/

![image-20220217121515713](https://alphahub-test-bucket.oss-cn-shanghai.aliyuncs.com/image/image-20220217121515713.png)

`01691f7f`加签结果返回：

```json
{
  "message": "操作成功",
  "success": true,
  "timestamp": "2022-02-17 12:15:52",
  "code": 200,
  "data": {
    "success": true,
    "certNo": "01691f7f",
    "signatureValue": "qFiqQB2BDLGrZWXVYh0ZXHYhfIWBvWrd7xM3tw78yW/eiwn0hgj+MdVHUsNc1RMgHhZoQihtVGrP5HZFcgtYmTBaxiHNoJ0gfS0sJBOOndyLV3WqOUn74HgRQXJ88pjjPw38SaTyTEsbLEGkDwfFvkbwD8W7/HHxx7bI/SUGJn8="
  }
}
```

`01691fe9`推送179数据给海关前替换`java`堆中`01691fe9`加签值为`01691f7f`的`signatureValue`值：

`qFiqQB2BDLGrZWXVYh0ZXHYhfIWBvWrd7xM3tw78yW/eiwn0hgj+MdVHUsNc1RMgHhZoQihtVGrP5HZFcgtYmTBaxiHNoJ0gfS0sJBOOndyLV3WqOUn74HgRQXJ88pjjPw38SaTyTEsbLEGkDwfFvkbwD8W7/HHxx7bI/SUGJn8=`

![image-20220217122427291](https://alphahub-test-bucket.oss-cn-shanghai.aliyuncs.com/image/image-20220217122427291.png)

提高警惕，重要的事情来了，我们直接看海关179数据抓取接口的返回信息:

```json
{
  "code": "10000",
  "message": "上传成功",
  "total": 0,
  "serviceTime": 1645071876726
}
```

![image-20220217123124100](https://alphahub-test-bucket.oss-cn-shanghai.aliyuncs.com/image/image-20220217123124100.png)

到这里你应该相信你应该能明白我想表达什么了......

😇**验签通过**

以下图片来源于`IDEA`的`DEBUG`过程。
