|
@@ -16,6 +16,7 @@ import com.zanxiang.sdk.domain.bo.WxPayConfigBO;
|
|
|
import com.zanxiang.sdk.service.OrderPayService;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.commons.io.IOUtils;
|
|
|
+import org.apache.commons.lang.StringEscapeUtils;
|
|
|
import org.apache.logging.log4j.util.Strings;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
@@ -31,8 +32,6 @@ import java.io.InputStream;
|
|
|
import java.nio.charset.StandardCharsets;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.Map;
|
|
|
-import java.util.SortedMap;
|
|
|
-import java.util.TreeMap;
|
|
|
|
|
|
/**
|
|
|
* @author xufeng
|
|
@@ -106,12 +105,16 @@ public class WxPayServiceImpl extends PayService implements OrderPayService {
|
|
|
String requestStr = IOUtils.toString(inputStream, StandardCharsets.UTF_8);
|
|
|
log.info("微信支付回调 body:{}", requestStr);
|
|
|
// 解析xml成map
|
|
|
- Map<String, String> map = XmlUtil.xmlToMap(requestStr);
|
|
|
- log.info("微信支付回调 map:{}", JsonUtil.toString(map));
|
|
|
- // 过滤空 设置 TreeMap
|
|
|
- SortedMap<Object, Object> packageParams = new TreeMap<>();
|
|
|
- map.forEach((key, value) -> packageParams.put(key, value == null ? "" : value.trim()));
|
|
|
- ProductPayAttachParamBO attachBO = JsonUtil.toObj(JsonUtil.toString(packageParams.get("attach")), ProductPayAttachParamBO.class);
|
|
|
+ Map<String, String> packageParams = XmlUtil.xmlToMap(requestStr);
|
|
|
+ log.info("微信支付回调 map:{}", JsonUtil.toString(packageParams));
|
|
|
+ //获取订单信息
|
|
|
+ String attachStr = StringEscapeUtils.unescapeJava(packageParams.get("attach"));
|
|
|
+ log.info("微信支付回调 attachStr:{}", attachStr);
|
|
|
+ ProductPayAttachParamBO attachBO = JsonUtil.toObj(JsonUtil.toString(attachStr), ProductPayAttachParamBO.class);
|
|
|
+ if (attachBO == null) {
|
|
|
+ log.info("回调参数中attach值为空");
|
|
|
+ return null;
|
|
|
+ }
|
|
|
configInit(getPayConfig(attachBO.getGamePayWayId()));
|
|
|
// 账号信息
|
|
|
String key = config.getApiKey();
|
|
@@ -122,27 +125,27 @@ public class WxPayServiceImpl extends PayService implements OrderPayService {
|
|
|
}
|
|
|
log.info("微信支付成功回调");
|
|
|
// 处理业务开始
|
|
|
- String resXml;
|
|
|
-
|
|
|
- if (Constants.SUCCESS.equalsIgnoreCase(packageParams.get("result_code").toString())) {
|
|
|
- // 这里是支付成功
|
|
|
- String orderNo = (String) packageParams.get("out_trade_no");
|
|
|
+ Map<String, String> xmlMap = new HashMap<>();
|
|
|
+ BufferedOutputStream out = new BufferedOutputStream(response.getOutputStream());
|
|
|
+ if (!Constants.SUCCESS.equalsIgnoreCase(packageParams.get("result_code"))) {
|
|
|
+ log.info("支付失败,错误信息:{}", packageParams.get("err_code"));
|
|
|
+ xmlMap.put("return_code", "FAIL");
|
|
|
+ xmlMap.put("return_msg", "报文为空");
|
|
|
+ }
|
|
|
+ if (Constants.SUCCESS.equalsIgnoreCase(packageParams.get("result_code"))) {
|
|
|
+ String orderNo = packageParams.get("out_trade_no");
|
|
|
log.info("微信订单号{}付款成功", orderNo);
|
|
|
- if (paySuccess(attachBO.getOrderId(), String.valueOf(Float.parseFloat(packageParams.get("total_amount").toString()) / 100), packageParams.get("trade_no").toString(), attachBO.getGamePayWayId())) {
|
|
|
- return ResEnum.SUCCESS.getMsg();
|
|
|
+ if (paySuccess(attachBO.getOrderId(), String.valueOf(Float.parseFloat(packageParams.get("total_fee")) / 100), packageParams.get("transaction_id"), attachBO.getGamePayWayId())) {
|
|
|
+ // 通知微信.异步确认成功.必写.不然会一直通知后台.八次之后就认为交易失败了
|
|
|
+ xmlMap.put("return_code", "SUCCESS");
|
|
|
+ xmlMap.put("return_msg", "OK");
|
|
|
}
|
|
|
- // 通知微信.异步确认成功.必写.不然会一直通知后台.八次之后就认为交易失败了
|
|
|
- resXml = "<xml>" + "<return_code><![CDATA[SUCCESS]]></return_code>" + "<return_msg><![CDATA[OK]]></return_msg>" + "</xml> ";
|
|
|
- } else {
|
|
|
- log.info("支付失败,错误信息:{}", packageParams.get("err_code"));
|
|
|
- resXml = "<xml>" + "<return_code><![CDATA[FAIL]]></return_code>" + "<return_msg><![CDATA[报文为空]]></return_msg>" + "</xml> ";
|
|
|
}
|
|
|
// 处理业务完毕
|
|
|
- BufferedOutputStream out = new BufferedOutputStream(response.getOutputStream());
|
|
|
- out.write(resXml.getBytes());
|
|
|
+ out.write(XmlUtil.mapToXml(xmlMap).getBytes());
|
|
|
out.flush();
|
|
|
out.close();
|
|
|
- return null;
|
|
|
+ return ResEnum.SUCCESS.getMsg();
|
|
|
}
|
|
|
|
|
|
@Override
|