diff --git a/.gitignore b/.gitignore index ce60be9..e65d643 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ /.idea/ *.iml /log/ -target/ \ No newline at end of file +target/ +*.project diff --git a/xxpay-common/src/main/java/org/xxpay/common/util/PayDigestUtil.java b/xxpay-common/src/main/java/org/xxpay/common/util/PayDigestUtil.java index 901cb10..588d209 100644 --- a/xxpay-common/src/main/java/org/xxpay/common/util/PayDigestUtil.java +++ b/xxpay-common/src/main/java/org/xxpay/common/util/PayDigestUtil.java @@ -142,7 +142,7 @@ public class PayDigestUtil { Field[] fields = cls.getDeclaredFields(); for (Field f : fields) { f.setAccessible(true); - if (f.get(o) != null && f.get(o) != "") { + if (f.get(o) != null && !"".equals(f.get(o))) { list.add(f.getName() + "=" + f.get(o) + "&"); } } @@ -164,7 +164,7 @@ public class PayDigestUtil { public static String getSign(Map map, String key){ ArrayList list = new ArrayList(); for(Map.Entry entry:map.entrySet()){ - if(!"".equals(entry.getValue())){ + if(!"".equals(entry.getValue()) && null != entry.getValue()){ list.add(entry.getKey() + "=" + entry.getValue() + "&"); } } diff --git a/xxpay4spring-boot/src/main/java/org/xxpay/boot/ctrl/PayOrderController.java b/xxpay4spring-boot/src/main/java/org/xxpay/boot/ctrl/PayOrderController.java index d97fd8b..9bfc57a 100644 --- a/xxpay4spring-boot/src/main/java/org/xxpay/boot/ctrl/PayOrderController.java +++ b/xxpay4spring-boot/src/main/java/org/xxpay/boot/ctrl/PayOrderController.java @@ -5,6 +5,8 @@ import com.alibaba.fastjson.JSONObject; import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.math.NumberUtils; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.MediaType; +import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; @@ -48,14 +50,19 @@ public class PayOrderController { */ @RequestMapping(value = "/api/pay/create_order") public String payOrder(@RequestParam String params) { - _log.info("###### 开始接收商户统一下单请求 ######"); + JSONObject po = JSONObject.parseObject(params); + return payOrder(po); + } + + @RequestMapping(value = "/api/pay/create_order", consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE) + public String payOrder(@RequestBody JSONObject params) { + _log.info("###### 开始接收商户统一下单请求 ######"); String logPrefix = "【商户统一下单】"; try { - JSONObject po = JSONObject.parseObject(params); JSONObject payContext = new JSONObject(); JSONObject payOrder = null; // 验证参数有效性 - Object object = validateParams(po, payContext); + Object object = validateParams(params, payContext); if (object instanceof String) { _log.info("{}参数校验不通过:{}", logPrefix, object); return XXPayUtil.makeRetFail(XXPayUtil.makeRetMap(PayConstant.RETURN_VALUE_FAIL, object.toString(), null, null)); diff --git a/xxpay4spring-boot/src/main/java/org/xxpay/boot/ctrl/QueryPayOrderController.java b/xxpay4spring-boot/src/main/java/org/xxpay/boot/ctrl/QueryPayOrderController.java index 4174472..818bc4b 100644 --- a/xxpay4spring-boot/src/main/java/org/xxpay/boot/ctrl/QueryPayOrderController.java +++ b/xxpay4spring-boot/src/main/java/org/xxpay/boot/ctrl/QueryPayOrderController.java @@ -3,6 +3,8 @@ package org.xxpay.boot.ctrl; import com.alibaba.fastjson.JSONObject; import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.MediaType; +import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; @@ -42,22 +44,27 @@ public class QueryPayOrderController { */ @RequestMapping(value = "/api/pay/query_order") public String queryPayOrder(@RequestParam String params) { + JSONObject po = JSONObject.parseObject(params); + return queryPayOrder(po); + } + + @RequestMapping(value = "/api/pay/query_order", consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE) + public String queryPayOrder(@RequestBody JSONObject params) { _log.info("###### 开始接收商户查询支付订单请求 ######"); String logPrefix = "【商户支付订单查询】"; try { - JSONObject po = JSONObject.parseObject(params); JSONObject payContext = new JSONObject(); // 验证参数有效性 - String errorMessage = validateParams(po, payContext); + String errorMessage = validateParams(params, payContext); if (!"success".equalsIgnoreCase(errorMessage)) { _log.warn(errorMessage); return XXPayUtil.makeRetFail(XXPayUtil.makeRetMap(PayConstant.RETURN_VALUE_FAIL, errorMessage, null, null)); } _log.debug("请求参数及签名校验通过"); - String mchId = po.getString("mchId"); // 商户ID - String mchOrderNo = po.getString("mchOrderNo"); // 商户订单号 - String payOrderId = po.getString("payOrderId"); // 支付订单号 - String executeNotify = po.getString("executeNotify"); // 是否执行回调 + String mchId = params.getString("mchId"); // 商户ID + String mchOrderNo = params.getString("mchOrderNo"); // 商户订单号 + String payOrderId = params.getString("payOrderId"); // 支付订单号 + String executeNotify = params.getString("executeNotify"); // 是否执行回调 JSONObject payOrder = payOrderService.queryPayOrder(mchId, payOrderId, mchOrderNo, executeNotify); _log.info("{}查询支付订单,结果:{}", logPrefix, payOrder); if (payOrder == null) { diff --git a/xxpay4spring-boot/src/main/java/org/xxpay/boot/service/impl/PayChannel4WxServiceImpl.java b/xxpay4spring-boot/src/main/java/org/xxpay/boot/service/impl/PayChannel4WxServiceImpl.java index 1e13657..5cb2736 100644 --- a/xxpay4spring-boot/src/main/java/org/xxpay/boot/service/impl/PayChannel4WxServiceImpl.java +++ b/xxpay4spring-boot/src/main/java/org/xxpay/boot/service/impl/PayChannel4WxServiceImpl.java @@ -97,12 +97,12 @@ public class PayChannel4WxServiceImpl extends BaseService implements IPayChannel configMap.put("appid", appId); // 此map用于客户端与微信服务器交互 payInfo.put("sign", SignUtils.createSign(configMap, wxPayConfig.getMchKey(), null)); - payInfo.put("prepayId", wxPayUnifiedOrderResult.getPrepayId()); - payInfo.put("partnerId", partnerId); - payInfo.put("appId", appId); - payInfo.put("packageValue", packageValue); - payInfo.put("timeStamp", timestamp); - payInfo.put("nonceStr", nonceStr); + payInfo.put("prepayid", wxPayUnifiedOrderResult.getPrepayId()); + payInfo.put("partnerid", partnerId); + payInfo.put("appid", appId); + payInfo.put("package", packageValue); + payInfo.put("timestamp", timestamp); + payInfo.put("noncestr", nonceStr); map.put("payParams", payInfo); break; }