|
@@ -133,8 +133,10 @@ public class AliPayService {
|
|
|
* @param paynum
|
|
|
* @return
|
|
|
* https://docs.open.alipay.com/api_1/alipay.trade.query
|
|
|
+ * @throws Exception
|
|
|
*/
|
|
|
- public String query(String paynum) {
|
|
|
+ @SuppressWarnings("unchecked")
|
|
|
+ public boolean query(String paynum) throws Exception {
|
|
|
AlipayTradeQueryRequest request = new AlipayTradeQueryRequest();
|
|
|
AlipayTradeQueryModel queryModel = new AlipayTradeQueryModel();
|
|
|
queryModel.setOutTradeNo(paynum); // 商户订单号
|
|
@@ -146,16 +148,28 @@ public class AliPayService {
|
|
|
logger.error("请求支付宝查询接口异常: ", e);
|
|
|
}
|
|
|
logger.info("请求支付宝查询接口返回: {}", result);
|
|
|
- return result;
|
|
|
+ // {"alipay_trade_query_response":{"code":"10000","msg":"Success","buyer_logon_id":"ipb***@sandbox.com","buyer_pay_amount":"0.00","buyer_user_id":"2088102170394382","buyer_user_type":"PRIVATE","invoice_amount":"0.00","out_trade_no":"1529637131201603","point_amount":"0.00","receipt_amount":"0.00","send_pay_date":"2018-06-22 11:12:23","total_amount":"12.00","trade_no":"2018062221001004380200826678","trade_status":"TRADE_SUCCESS"},"sign":"gnWtxKDDhkRmoWnfwLVs2RGtt4GbiY+xaVs5+G47D5e9SnQHqGnElKme4jlDdnqhAroX3aqyJLVexohBjzA+DlpRzDhIu5EZLXnDr/B2FZEVjyiU66ImVH6vSyWyOVEjbGIgmVhUslhXqXYK5KxAx3QAdLrJLQeMO/gUdjs0qWcGO9yTU/suDy0YcdLSLlFyUutwD2MBz4Ri0tBk+uHjpxXoTZeb9/lQ7e4BixwCy+wB3hcESWN1b/m77YLKztmbLy67auhxzP9TRwQQ+6WRrTdMe/9rouIt6AW9T+6XSFd/LwL73Qo+1MfQa+iEUx2Iq+AYekhSgVyLJMRgz/qoZA=="}
|
|
|
+ Map<String, Object> resultMap = JsonUtil.toObject(result, HashMap.class);
|
|
|
+ Map<String, String> map = (Map<String, String>) resultMap.get("alipay_trade_query_response");
|
|
|
+ if(!"10000".equals(map.get("code"))) {
|
|
|
+ logger.error("支付宝查询: 接口状态异常: {}", map);
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ // 验证支付宝交易状态
|
|
|
+ if(!this.checkStatus(map)) {
|
|
|
+ logger.error("支付宝查询: 交易状态异常: {}", map);
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ return this.dispose(map);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 处理异步通知
|
|
|
+ * 处理通知
|
|
|
* @param map
|
|
|
* @return
|
|
|
* @throws Exception
|
|
|
*/
|
|
|
- public boolean doNotify(Map<String, String> map) throws Exception {
|
|
|
+ public boolean dispose(Map<String, String> map) throws Exception {
|
|
|
// 验证签名
|
|
|
if(!this.checkSign(map)) {
|
|
|
logger.error("支付宝异步通知: 签名验证失败: {}", map);
|
|
@@ -174,39 +188,6 @@ public class AliPayService {
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
-
|
|
|
- /**
|
|
|
- * 处理同步回调
|
|
|
- * @throws Exception
|
|
|
- */
|
|
|
- @SuppressWarnings("unchecked")
|
|
|
- public String doReturn(Map<String, String> map) throws Exception {
|
|
|
- // 验证签名
|
|
|
- if(!this.checkSign(map)) {
|
|
|
- logger.error("支付宝同步回调: 签名验证失败: {}", map);
|
|
|
- return null;
|
|
|
- }
|
|
|
- // 查询订单 (同步回调不可靠)
|
|
|
- String paynum = map.get("out_trade_no");
|
|
|
- String result = this.query(paynum);
|
|
|
- Map<String, Object> resultMap = JsonUtil.toObject(result, HashMap.class);
|
|
|
- // {"alipay_trade_query_response":{"code":"10000","msg":"Success","buyer_logon_id":"ipb***@sandbox.com","buyer_pay_amount":"0.00","buyer_user_id":"2088102170394382","buyer_user_type":"PRIVATE","invoice_amount":"0.00","out_trade_no":"1529637131201603","point_amount":"0.00","receipt_amount":"0.00","send_pay_date":"2018-06-22 11:12:23","total_amount":"12.00","trade_no":"2018062221001004380200826678","trade_status":"TRADE_SUCCESS"},"sign":"gnWtxKDDhkRmoWnfwLVs2RGtt4GbiY+xaVs5+G47D5e9SnQHqGnElKme4jlDdnqhAroX3aqyJLVexohBjzA+DlpRzDhIu5EZLXnDr/B2FZEVjyiU66ImVH6vSyWyOVEjbGIgmVhUslhXqXYK5KxAx3QAdLrJLQeMO/gUdjs0qWcGO9yTU/suDy0YcdLSLlFyUutwD2MBz4Ri0tBk+uHjpxXoTZeb9/lQ7e4BixwCy+wB3hcESWN1b/m77YLKztmbLy67auhxzP9TRwQQ+6WRrTdMe/9rouIt6AW9T+6XSFd/LwL73Qo+1MfQa+iEUx2Iq+AYekhSgVyLJMRgz/qoZA=="}
|
|
|
- Map<String, String> responseMap = (Map<String, String>) resultMap.get("alipay_trade_query_response");
|
|
|
- if(!"10000".equals(responseMap.get("code"))) {
|
|
|
- logger.error("支付宝同步回调: 查询状态异常: {}", responseMap);
|
|
|
- return null;
|
|
|
- }
|
|
|
- // 验证支付宝交易状态
|
|
|
- if(!this.checkStatus(responseMap)) {
|
|
|
- logger.error("支付宝同步回调: 交易状态异常: {}", responseMap);
|
|
|
- return null;
|
|
|
- }
|
|
|
- // 完成支付
|
|
|
- String tradenum = responseMap.get("trade_no"); // 支付宝交易号
|
|
|
- int totalAmount = DecimalUtil.toInt(map.get("total_amount")); // 实际支付金额
|
|
|
- return payService.finish(paynum, tradenum, totalAmount, PayService.FLAG_RETURN);
|
|
|
- }
|
|
|
-
|
|
|
/**
|
|
|
* 验证签名
|
|
|
* @param map
|