博主在使用支付寶沙箱集成當面付接口時,遇到一個問題。原本按照按照官方的解釋,本身下載完demo之後,修改裏面的部分參數:java
# 支付寶網關名、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個問號,而後運行主方法就應該能夠獲得正確的代碼:express
十二月 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
可是實際運行的結果則是:api
嚴重: 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就是能夠。app