Merge pull request #8 from cbwleft/feature/application_json

Feature/application json
This commit is contained in:
dingzhiwei 2018-04-13 14:01:50 +08:00 committed by GitHub
commit 708aa64b18
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 33 additions and 18 deletions

3
.gitignore vendored
View File

@ -1,4 +1,5 @@
/.idea/
*.iml
/log/
target/
target/
*.project

View File

@ -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<String,Object> map, String key){
ArrayList<String> list = new ArrayList<String>();
for(Map.Entry<String,Object> entry:map.entrySet()){
if(!"".equals(entry.getValue())){
if(!"".equals(entry.getValue()) && null != entry.getValue()){
list.add(entry.getKey() + "=" + entry.getValue() + "&");
}
}

View File

@ -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));

View File

@ -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) {

View File

@ -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;
}