接着下文,本文主要描述在对接过程中踩到的坑有哪些。。
一.错误列表
1.签名不通过
报错“public key verify failed”
{
"apiName":"",
"appId":"",
"certID":"13412652941845540388",
"checkValid":true,
"sign":"Q8X2iuf+HIkl9PS/Vmzz+Vt1OjWXPzRrZk84VXE+M0GNLbqp5+wZXypl8Co+gvKA0IlPxCQNOEawbm7coiTo46PgrwErqrD87GiMXN5r57fkgxd4gTmHk/4lnLaxcWomxFmAjFRBDjklb3Ih1QjcEH1akJibyzQI3f3mE8A7TVM1MFRJxD9aRPuwChsb+TrzuyqU0Iut9uVxrxYPulrWwxvB7dBQKr36U0msuax+cOEp0/qraxTD2XrXcOj56jMzyi9un203yluD2gSX5hlDsOgXbHWphjMM64YUgW8LHUlpfLC4t65pgDOGcXbRiJQ2XfXJ3FKyf1oRKPQobPc3ug==",
"signBlock":"{\"ICBC_API_TIMESTAMP\":\"2021-08-31 16:00:38\",\"ICBC_API_RETMSG\":\"public key verify failed\",\"ICBC_API_RETCODE\":42}",
"timesTamp":""
}
解决思路:
会导致两边的签名不一致,除了密钥对不一致外,最可能的就是明文不一致了。
而最可能的就是对空字段的处理,一方算进签名,而另一方忽略了签名。
最后排查出来是attach字段,请求的时候赋空值了。
2.扫码付
{
"apiName":"",
"appId":"",
"certID":"13412652941845540388",
"checkValid":true,
"sign":"X/gE8AEmQnzP1TMJYPPNaI7eUsgj4tRJCPxZaRATOKdCClElZ6/nOTq6i2Obgpxdqn1ShSW5/MYjL5HnwJYp0keGHEnDQ9Gs/8ifqYSi96zkOsry+7chW8E9WmN/YWy0kn9W2Yj8QjgW5qXAI0LMAqM7w8M7094W1IM1Dt11P44djqqQoU+GCtspX62WPaEQzD5d5NBeYexhiettFlTYNVVqh8vMRt+ImnPPOaBrk9iewMY1U5wR6gtehAmc9uS9bgkZqULDMPVjMCe2S5uqK98eKFMPXJ2KEDxm83it3YIcr2pS6lqxOSj9PNZBMH/MzOpAEWhJRzAOnbIWdqQMqw==",
"signBlock":"{\"invokerCode\":\"SUCCESS\",\"response\":{\"appid\":\"\",\"tradeType\":\"NATIVE\",\"prepayId\":\"\"},\"invokerMsg\":\"交易成功\",\"hostRspMsg\":\"数据不存在[[UPayInstWxpayMct]参数不存在,key[12021000000000000366:001:NATIVE]]\",\"ICBC_API_TIMESTAMP\":\"2021-09-02 10:03:01\",\"hostRspCode\":\"B0203\",\"ICBC_API_RETMSG\":\"success\",\"ICBC_API_RETCODE\":0}",
"timesTamp":""
}
答案是:工行不支持该支付方式了。。。
3.网络不可达(未解决)
不知道怎么回事,本地调试的时候出现的。。担心线上也会出现该问题。。。
com.icbc.api.core.ApiFailure: [unknown_exception][io_exception]Connect to web.zj.icbc.com.cn:443 [web.zj.icbc.com.cn/61.129.98.130, web.zj.icbc.com.cn/240e:e5:8001:1600:0:0:0:11d] failed: 网络不可达 (connect failed)
at com.icbc.api.core.ApiClient.execute(ApiClient.java:120)
...
...
Caused by: com.icbc.api.core.ApiFailure: [io_exception]Connect to web.zj.icbc.com.cn:443 [web.zj.icbc.com.cn/61.129.98.130, web.zj.icbc.com.cn/240e:e5:8001:1600:0:0:0:11d] failed: 网络不可达 (connect failed)
at com.icbc.api.core.HttpClient.doPost(HttpClient.java:207)
at com.icbc.api.core.ApiClient.execute(ApiClient.java:90)
... 80 common frames omitted
Caused by: org.apache.http.conn.HttpHostConnectException: Connect to web.zj.icbc.com.cn:443 [web.zj.icbc.com.cn/61.129.98.130, web.zj.icbc.com.cn/240e:e5:8001:1600:0:0:0:11d] failed: 网络不可达 (connect failed)
at org.apache.http.impl.conn.DefaultHttpClientConnectionOperator.connect(DefaultHttpClientConnectionOperator.java:156)
at org.apache.http.impl.conn.PoolingHttpClientConnectionManager.connect(PoolingHttpClientConnectionManager.java:374)
at org.apache.http.impl.execchain.MainClientExec.establishRoute(MainClientExec.java:393)
at org.apache.http.impl.execchain.MainClientExec.execute(MainClientExec.java:236)
at org.apache.http.impl.execchain.ProtocolExec.execute(ProtocolExec.java:186)
at org.apache.http.impl.execchain.RetryExec.execute(RetryExec.java:89)
at org.apache.http.impl.execchain.RedirectExec.execute(RedirectExec.java:110)
at org.apache.http.impl.client.InternalHttpClient.doExecute(InternalHttpClient.java:185)
at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:83)
at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:108)
at com.icbc.api.core.HttpClient.doPost(HttpClient.java:195)
... 81 common frames omitted
Caused by: java.net.ConnectException: 网络不可达 (connect failed)
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350)
at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206)
at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
at java.net.Socket.connect(Socket.java:589)
at org.apache.http.conn.ssl.SSLConnectionSocketFactory.connectSocket(SSLConnectionSocketFactory.java:368)
at org.apache.http.impl.conn.DefaultHttpClientConnectionOperator.connect(DefaultHttpClientConnectionOperator.java:142)
... 91 common frames omitted
3.商户传入的appid的参数不正确,请联系商户处理
坑在于,appid字段不是必填项,所以我使用公众号支付的时候,就没有传入。而且当时有将我方的appid悉数让工行配置好。 另外,需要注意的字段tradeType(交易类型):JSAPI(公众号),JSAPI_MINI(小程序)。也就是说,公众号和小程序在jsapi支付方式这块,是需要区分的。(这一点也和其他的银行对接区分很大)