问题描述

博主在使用支付宝沙箱集成当面付接口时,遇到一个问题。本来按照按照官方的解释,自己下载完demo以后,修改里面的部分参数:


# 支付宝网关名、partnerId和appId
open_api_domain = https://openapi.alipaydev.com/gateway.do
mcloud_api_domain = http://mcloudmonitor.com/gateway.do
pid = ?
appid = ?

# RSA私钥、公钥和支付宝公钥
private_key =?
public_key =?

#SHA1withRsa对应支付宝公钥,已经废弃
#alipay_public_key = MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDDI6d306Q8fIfCOaTXyiUeJHkrIvYISRcc73s3vF1ZT7XN8RNPwJxo8pWaJMmvyTn9N4HQ632qJBVHf8sxHi/fEsraprwCtzvzQETrNRwVxLO5jVmRGi60j8Ue1efIlzPXV9je9mkjzOmdssymZkh2QhUrCmZYI/FCEa3/cNMW0QIDAQAB

#SHA256withRsa对应支付宝公钥
alipay_public_key =?

# 签名类型: RSA->SHA1withRsa,RSA2->SHA256withRsa
sign_type = RSA2
# 当面付最大查询次数和查询间隔(毫秒)
max_query_retry = 5
query_duration = 5000

# 当面付最大撤销次数和撤销间隔(毫秒)
max_cancel_retry = 3
cancel_duration = 2000

# 交易保障线程第一次调度延迟和调度间隔(秒)
heartbeat_delay = 5
heartbeat_duration = 900

也就是5个问号,然后运行主方法就应该可以得到正确的代码:

十二月 23, 2018 6:52:52 下午 com.alipay.demo.trade.config.Configs init
信息: 配置文件名: zfbinfo.properties
十二月 23, 2018 6:52:52 下午 com.alipay.demo.trade.config.Configs init
信息: Configs{支付宝openapi网关: https://openapi.alipaydev.com/gateway.do
, 支付宝mcloudapi网关域名: xxxxxxxxxxxxx
, pid: xxxxxxxxxxxxxxx
, appid: xxxxxxxxxxxxxx
, 商户RSA私钥: xxxxxxxxxxxxxxxx
, 商户RSA公钥: xxxxxxxxxxxxx
, 支付宝RSA公钥: xxxxxxxxxx
, 签名类型: RSA2
, 查询重试次数: 5
, 查询间隔(毫秒): 5000
, 撤销尝试次数: 3
, 撤销重试间隔(毫秒): 2000
, 交易保障调度延迟(秒): 5
, 交易保障调度间隔(秒): 900
}
十二月 23, 2018 6:52:52 下午 com.alipay.demo.trade.service.impl.AbsAlipayTradeService tradePrecreate
信息: trade.precreate bizContent:{"out_trade_no":"tradeprecreate15455623721193880632","seller_id":"","total_amount":"0.01","undiscountable_amount":"0","subject":"xxx品牌xxx门店当面付扫码消费","body":"购买商品3件共20.00元","goods_detail":[{"goods_id":"goods_id001","goods_name":"xxx小面包","quantity":1,"price":"10"},{"goods_id":"goods_id002","goods_name":"xxx牙刷","quantity":2,"price":"5"}],"operator_id":"test_operator_id","store_id":"test_store_id","extend_params":{"sys_service_provider_id":"2088100200300400500"},"timeout_express":"120m"}
十二月 23, 2018 6:52:54 下午 com.alipay.api.internal.util.AlipayLogger logBizSummary
信息: Summary^_^10000^_^null^_^ProtocalMustParams:sign=x?arams:biz_content={"out_trade_no":"tradeprecreate15455623721193880632","seller_id":"","total_amount":"0.01","undiscountable_amount":"0","subject":"xxx品牌xxx门店当面付扫码消费","body":"购买商品3件共20.00元","goods_detail":[{"goods_id":"goods_id001","goods_name":"xxx小面包","quantity":1,"price":"10"},{"goods_id":"goods_id002","goods_name":"xxx牙刷","quantity":2,"price":"5"}],"operator_id":"test_operator_id","store_id":"test_store_id","extend_params":{"sys_service_provider_id":"2088100200300400500"},"timeout_express":"120m"}^_^234ms,2030ms,116ms
十二月 23, 2018 6:52:54 下午 com.alipay.demo.trade.service.impl.AbsAlipayService getResponse
信息: {"alipay_trade_precreate_response":{"code":"10000","msg":"Success","out_trade_no":"tradeprecreate15455623721193880632","qr_code":"https:\/\/qr.alipay.com\/bax070434utkzzfjabke0030"},"sign":"???
十二月 23, 2018 6:52:54 下午 com.alipay.demo.trade.Main test_trade_precreate
信息: 支付宝预下单成功: )
十二月 23, 2018 6:52:54 下午 com.alipay.demo.trade.Main dumpResponse
信息: code:10000, msg:Success
十二月 23, 2018 6:52:54 下午 com.alipay.demo.trade.Main dumpResponse
信息: body:{"alipay_trade_precreate_response":{"code":"10000","msg":"Success","out_trade_no":"tradeprecreate15455623721193880632","qr_code":"https:\/\/qr.alipay.com\/bax070434utkzzfjabke0030"},"sign":"???
十二月 23, 2018 6:52:54 下午 com.alipay.demo.trade.Main test_trade_precreate
信息: filePath:/Users/sudo/Desktop/qr-tradeprecreate15455623721193880632.png

但是实际运行的结果则是:

严重: 2018-01-04 17:27:14^_^alipay.trade.precreate^_^null^_^192.168.1.105^_^Windows 7^_^alipay-sdk-java-dynamicVersionNo^_^https://openapi.alipaydev.com/gateway.do?charset=utf-8
com.alipay.api.AlipayApiException: java.net.SocketTimeoutException: Read timed out
 at com.alipay.api.DefaultAlipayClient.doPost(DefaultAlipayClient.java:483)
 at com.alipay.api.DefaultAlipayClient._execute(DefaultAlipayClient.java:412)
 at com.alipay.api.DefaultAlipayClient.execute(DefaultAlipayClient.java:123)
 at com.alipay.api.DefaultAlipayClient.execute(DefaultAlipayClient.java:110)
 at com.alipay.api.DefaultAlipayClient.execute(DefaultAlipayClient.java:104)
 at com.alipay.demo.trade.service.impl.AbsAlipayService.getResponse(AbsAlipayService.java:32)
 at com.alipay.demo.trade.service.impl.AbsAlipayTradeService.tradePrecreate(AbsAlipayTradeService.java:102)
 at com.alipay.demo.trade.service.impl.AlipayTradeServiceImpl.tradePrecreate(AlipayTradeServiceImpl.java:1)
 at com.alipay.demo.trade.Main.test_trade_precreate(Main.java:426)
 at com.alipay.demo.trade.Main.main(Main.java:101)
Caused by: java.net.SocketTimeoutException: Read timed out
 at java.base/java.net.SocketInputStream.socketRead0(Native Method)
 at java.base/java.net.SocketInputStream.socketRead(Unknown Source)
 at java.base/java.net.SocketInputStream.read(Unknown Source)
 at java.base/java.net.SocketInputStream.read(Unknown Source)
 at java.base/sun.security.ssl.SSLSocketInputRecord.read(Unknown Source)
 at java.base/sun.security.ssl.SSLSocketInputRecord.decode(Unknown Source)
 at java.base/sun.security.ssl.SSLSocketImpl.readRecord(Unknown Source)
 at java.base/sun.security.ssl.SSLSocketImpl.readRecord(Unknown Source)
 at java.base/sun.security.ssl.SSLSocketImpl.performInitialHandshake(Unknown Source)
 at java.base/sun.security.ssl.SSLSocketImpl.startHandshake(Unknown Source)
 at java.base/sun.security.ssl.SSLSocketImpl.startHandshake(Unknown Source)
 at java.base/sun.net.www.protocol.https.HttpsClient.afterConnect(Unknown Source)
 at java.base/sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(Unknown Source)
 at java.base/sun.net.www.protocol.http.HttpURLConnection.getOutputStream0(Unknown Source)
 at java.base/sun.net.www.protocol.http.HttpURLConnection.getOutputStream(Unknown Source)
 at java.base/sun.net.www.protocol.https.HttpsURLConnectionImpl.getOutputStream(Unknown Source)
 at com.alipay.api.internal.util.WebUtils.doPost(WebUtils.java:149)
 at com.alipay.api.internal.util.WebUtils.doPost(WebUtils.java:121)
 at com.alipay.api.DefaultAlipayClient.doPost(DefaultAlipayClient.java:479)
 ... 9 more
1月 04, 2018 5:27:14 下午 com.alipay.demo.trade.Main test_trade_precreate
严重: 系统异常,预下单状态未知!!!

问题解决

这个问题真是干扰了很久,去支付宝论坛发现也没有解决的办法,后来才发现是因为支付宝目前还不支持java10,而我用的就是java10.如果你改用java7,8就不会出现这种问题了。其实关于付宝目前还不支持java10这个,好像官方人员都没有一个合理的说明,反正你用java10就是不行,运行不了,用java7,8就是可以。

12-24 00:08