|
|
@@ -1,6 +1,5 @@
|
|
|
package com.fdkankan.pay.util.wx;
|
|
|
|
|
|
-import com.alibaba.fastjson.JSONObject;
|
|
|
import com.fdkankan.pay.common.ResultCode;
|
|
|
import com.fdkankan.pay.entity.Order;
|
|
|
import com.fdkankan.pay.entity.WxConfig;
|
|
|
@@ -16,8 +15,6 @@ import org.springframework.stereotype.Service;
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
import java.io.BufferedOutputStream;
|
|
|
-import java.io.BufferedReader;
|
|
|
-import java.io.IOException;
|
|
|
import java.math.BigDecimal;
|
|
|
import java.net.URLEncoder;
|
|
|
import java.util.HashMap;
|
|
|
@@ -190,16 +187,26 @@ public class WechatPayService {
|
|
|
log.error("wx-callBack--wxConfig-notexist");
|
|
|
return false;
|
|
|
}
|
|
|
- Map<String, String> data = new HashMap<String, String>();
|
|
|
- data.put("out_trade_no", order.getOrderSn());
|
|
|
- Map<String, String> resp = WXPay.orderQuery(data,wxConfig.getAppid(),wxConfig.getMchId(),wxConfig.getMchKey());
|
|
|
- log.info("wx-callBack-queryOrder--req:{},resp:{}",data,resp);
|
|
|
-
|
|
|
- if (resp.get("trade_state") != null && resp.get("trade_state").equals(WXPayConstants.SUCCESS)) {
|
|
|
- payFlag = true;
|
|
|
- return true;
|
|
|
+ if(order.getPayType() == 0){
|
|
|
+ Map<String, String> resp = queryOrderH5(order, wxConfig);
|
|
|
+ Integer count = 0;
|
|
|
+ while (resp!=null){
|
|
|
+ count ++;
|
|
|
+ if (resp.get("trade_state") != null) {
|
|
|
+ if(resp.get("trade_state").equals(WXPayConstants.NOTPAY)){
|
|
|
+ Thread.sleep(1000L);
|
|
|
+ resp = queryOrderH5(order,wxConfig);
|
|
|
+ }else if(resp.get("trade_state").equals(WXPayConstants.SUCCESS)){
|
|
|
+ log.info("wx-callBack-queryOrder--查询订单成功,重试次数:{}",count);
|
|
|
+ payFlag = true;
|
|
|
+ return true;
|
|
|
+ }else if(resp.get("trade_state").equals(WXPayConstants.FAIL)){
|
|
|
+ payFlag = false;
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
-
|
|
|
String inputLine = "";
|
|
|
String notifyXml = "";
|
|
|
while((inputLine = request.getReader().readLine()) != null){
|
|
|
@@ -261,38 +268,16 @@ public class WechatPayService {
|
|
|
|
|
|
|
|
|
|
|
|
- public static String ReadAsChars(HttpServletRequest request) throws Exception{
|
|
|
-
|
|
|
- BufferedReader br = null;
|
|
|
- StringBuilder sb = new StringBuilder("");
|
|
|
- try
|
|
|
- {
|
|
|
- br = request.getReader();
|
|
|
- String str;
|
|
|
- while ((str = br.readLine()) != null)
|
|
|
- {
|
|
|
- sb.append(str);
|
|
|
- }
|
|
|
- br.close();
|
|
|
- }
|
|
|
- catch (IOException e)
|
|
|
- {
|
|
|
+ private Map<String, String> queryOrderH5(Order order, WxConfig wxConfig){
|
|
|
+ try {
|
|
|
+ Map<String, String> data = new HashMap<String, String>();
|
|
|
+ data.put("out_trade_no", order.getOrderSn());
|
|
|
+ Map<String, String> resp = WXPay.orderQuery(data,wxConfig.getAppid(),wxConfig.getMchId(),wxConfig.getMchKey());
|
|
|
+ log.info("wx-callBack-queryOrder--req:{},resp:{}",data,resp);
|
|
|
+ return resp;
|
|
|
+ }catch (Exception e){
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
- finally
|
|
|
- {
|
|
|
- if (null != br)
|
|
|
- {
|
|
|
- try
|
|
|
- {
|
|
|
- br.close();
|
|
|
- }
|
|
|
- catch (IOException e)
|
|
|
- {
|
|
|
- e.printStackTrace();
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- return sb.toString();
|
|
|
+ return null;
|
|
|
}
|
|
|
}
|