|
|
|
@@ -1,5 +1,7 @@ |
|
|
|
package com.iformall.pos.test; |
|
|
|
|
|
|
|
import com.alibaba.fastjson.JSON; |
|
|
|
import com.alibaba.fastjson.JSONArray; |
|
|
|
import com.alibaba.fastjson.JSONObject; |
|
|
|
import com.fasterxml.jackson.databind.ObjectMapper; |
|
|
|
import com.iformall.PosApplication; |
|
|
|
@@ -23,6 +25,8 @@ import org.springframework.test.web.servlet.request.MockMvcRequestBuilders; |
|
|
|
import org.springframework.test.web.servlet.result.MockMvcResultHandlers; |
|
|
|
import org.springframework.test.web.servlet.result.MockMvcResultMatchers; |
|
|
|
|
|
|
|
import java.text.SimpleDateFormat; |
|
|
|
import java.util.Date; |
|
|
|
import java.util.HashMap; |
|
|
|
import java.util.Map; |
|
|
|
|
|
|
|
@@ -41,6 +45,8 @@ public class PosAppTest { |
|
|
|
@Autowired |
|
|
|
private MockMvc mockMvc; |
|
|
|
|
|
|
|
private static final SimpleDateFormat neuDateFormat = new SimpleDateFormat("yyyyMMddHHmmssSSS"); |
|
|
|
|
|
|
|
private static final String devId = "neupos"; |
|
|
|
private static final String devReqKey = "qVH2YDmXJ$ok4a95"; |
|
|
|
private static final String devResKey = "VE#1fB2PhUe@&3Of"; |
|
|
|
@@ -51,6 +57,8 @@ public class PosAppTest { |
|
|
|
private static final String phone = "13120223636"; |
|
|
|
private static final String password = "drpos345"; |
|
|
|
|
|
|
|
private static final String posSN = "1"; |
|
|
|
|
|
|
|
/* |
|
|
|
可用的交易券, 支付可用(1, 2, 6), 核销可用(4, 6, 8, 9) |
|
|
|
coupon_order_id, coupon_type, 售价, 面额, cancellable |
|
|
|
@@ -106,20 +114,7 @@ public class PosAppTest { |
|
|
|
reqObj.put(WxPayConstant.TENANT_ID, tenantId); |
|
|
|
reqObj.put(WxPayConstant.PHONE, phone); |
|
|
|
reqObj.put(WxPayConstant.PASSWORD, password); |
|
|
|
reqObj.put(WxPayConstant.SIGN, WxPayment.createSignHMAC(reqObj, devReqKey)); |
|
|
|
String reqJsonStr = JSONObject.toJSONString(reqObj); |
|
|
|
MvcResult result = mockMvc.perform( |
|
|
|
MockMvcRequestBuilders.post("/checkUserPassword") |
|
|
|
.contentType(MediaType.APPLICATION_JSON) |
|
|
|
.content(reqJsonStr)) |
|
|
|
.andExpect(MockMvcResultMatchers.status().isOk()) |
|
|
|
.andDo(MockMvcResultHandlers.print()) |
|
|
|
.andReturn(); |
|
|
|
String responseStr = result.getResponse().getContentAsString(); |
|
|
|
ObjectMapper mapper = new ObjectMapper(); |
|
|
|
Map<String,String> respMap = mapper.readValue(responseStr, Map.class); |
|
|
|
boolean resSigned = WxPayment.verifyNotifyHMAC(respMap, devResKey); |
|
|
|
System.out.println("response sign: " + resSigned); |
|
|
|
boolean resSigned = sendAndRes("/checkUserPassword", reqObj); |
|
|
|
Assert.assertEquals(resSigned, true); |
|
|
|
} |
|
|
|
@Test |
|
|
|
@@ -128,20 +123,7 @@ public class PosAppTest { |
|
|
|
reqObj.put(WxPayConstant.NONCE_STR, "1"); |
|
|
|
reqObj.put(WxPayConstant.DEV_ID, devId); |
|
|
|
reqObj.put(WxPayConstant.TENANT_ID, tenantId); |
|
|
|
reqObj.put(WxPayConstant.SIGN, WxPayment.createSignHMAC(reqObj, devReqKey)); |
|
|
|
String reqJsonStr = JSONObject.toJSONString(reqObj); |
|
|
|
MvcResult result = mockMvc.perform( |
|
|
|
MockMvcRequestBuilders.post("/getPosMemConfig") |
|
|
|
.contentType(MediaType.APPLICATION_JSON) |
|
|
|
.content(reqJsonStr)) |
|
|
|
.andExpect(MockMvcResultMatchers.status().isOk()) |
|
|
|
.andDo(MockMvcResultHandlers.print()) |
|
|
|
.andReturn(); |
|
|
|
String responseStr = result.getResponse().getContentAsString(); |
|
|
|
ObjectMapper mapper = new ObjectMapper(); |
|
|
|
Map<String,String> respMap = mapper.readValue(responseStr, Map.class); |
|
|
|
boolean resSigned = WxPayment.verifyNotifyHMAC(respMap, devResKey); |
|
|
|
System.out.println("response sign: " + resSigned); |
|
|
|
boolean resSigned = sendAndRes("/getPosMemConfig", reqObj); |
|
|
|
Assert.assertEquals(resSigned, true); |
|
|
|
} |
|
|
|
|
|
|
|
@@ -151,19 +133,7 @@ public class PosAppTest { |
|
|
|
reqObj.put(WxPayConstant.NONCE_STR, "1"); |
|
|
|
reqObj.put(WxPayConstant.DEV_ID, devId); |
|
|
|
reqObj.put(WxPayConstant.TENANT_ID, tenantId); |
|
|
|
reqObj.put(WxPayConstant.SIGN, WxPayment.createSignHMAC(reqObj, devReqKey)); |
|
|
|
String reqJsonStr = JSONObject.toJSONString(reqObj); |
|
|
|
MvcResult result = mockMvc.perform( |
|
|
|
MockMvcRequestBuilders.post("/getQrCode") |
|
|
|
.contentType(MediaType.APPLICATION_JSON) |
|
|
|
.content(reqJsonStr)) |
|
|
|
.andExpect(MockMvcResultMatchers.status().isOk()) |
|
|
|
.andDo(MockMvcResultHandlers.print()) |
|
|
|
.andReturn(); |
|
|
|
String responseStr = result.getResponse().getContentAsString(); |
|
|
|
ObjectMapper mapper = new ObjectMapper(); |
|
|
|
Map<String,String> respMap = mapper.readValue(responseStr, Map.class); |
|
|
|
boolean resSigned = WxPayment.verifyNotifyHMAC(respMap, devResKey); |
|
|
|
boolean resSigned = sendAndRes("/getQrCode", reqObj); |
|
|
|
Assert.assertEquals(resSigned, true); |
|
|
|
} |
|
|
|
|
|
|
|
@@ -173,7 +143,22 @@ public class PosAppTest { |
|
|
|
String phone = "13910154397"; |
|
|
|
String posOrderId = "1"; |
|
|
|
String posAmount = "200"; |
|
|
|
doCheckMem(memId, phone, posOrderId, posAmount); |
|
|
|
Map<String, String> reqObj = new HashMap<>(); |
|
|
|
reqObj.put(WxPayConstant.NONCE_STR, "1"); |
|
|
|
reqObj.put(WxPayConstant.DEV_ID, devId); |
|
|
|
reqObj.put(WxPayConstant.TENANT_ID, tenantId); |
|
|
|
reqObj.put(WxPayConstant.MERCHANT_ID, merchantId); |
|
|
|
reqObj.put(WxPayConstant.BUSER_ID, buUserId); |
|
|
|
if (StringUtils.isNotBlank(memId)) { |
|
|
|
reqObj.put(WxPayConstant.MEM_ID, memId); |
|
|
|
} |
|
|
|
if (StringUtils.isNotBlank(phone)) { |
|
|
|
reqObj.put(WxPayConstant.MEM_PHONE, phone); |
|
|
|
} |
|
|
|
reqObj.put(WxPayConstant.POS_ORDER_ID, posOrderId); |
|
|
|
reqObj.put(WxPayConstant.POS_AMOUNT, posAmount); |
|
|
|
boolean resSigned = sendAndRes("/checkMem", reqObj); |
|
|
|
Assert.assertEquals(resSigned, true); |
|
|
|
} |
|
|
|
|
|
|
|
@Test |
|
|
|
@@ -182,7 +167,22 @@ public class PosAppTest { |
|
|
|
String phone = "13910154397"; |
|
|
|
String posAmount = "20000"; |
|
|
|
String selCoList = "[\"321877927162249216\"]"; |
|
|
|
doCalcMem(memId, phone, posAmount, selCoList); |
|
|
|
Map<String, String> reqObj = new HashMap<>(); |
|
|
|
reqObj.put(WxPayConstant.NONCE_STR, "1"); |
|
|
|
reqObj.put(WxPayConstant.DEV_ID, devId); |
|
|
|
reqObj.put(WxPayConstant.TENANT_ID, tenantId); |
|
|
|
reqObj.put(WxPayConstant.MERCHANT_ID, merchantId); |
|
|
|
reqObj.put(WxPayConstant.BUSER_ID, buUserId); |
|
|
|
if (StringUtils.isNotBlank(memId)) { |
|
|
|
reqObj.put(WxPayConstant.MEM_ID, memId); |
|
|
|
} |
|
|
|
if (StringUtils.isNotBlank(phone)) { |
|
|
|
reqObj.put(WxPayConstant.MEM_PHONE, phone); |
|
|
|
} |
|
|
|
reqObj.put(WxPayConstant.POS_AMOUNT, posAmount); |
|
|
|
reqObj.put(WxPayConstant.SELECTED_COUPON_ORDER_LIST, selCoList); |
|
|
|
boolean resSigned = sendAndRes("/calcMem", reqObj); |
|
|
|
Assert.assertEquals(resSigned, true); |
|
|
|
} |
|
|
|
|
|
|
|
@Test |
|
|
|
@@ -217,6 +217,57 @@ public class PosAppTest { |
|
|
|
doCouponOrderVerifyCancel(couponOrderId, posOrderId); |
|
|
|
} |
|
|
|
|
|
|
|
@Test |
|
|
|
public void verifySyncTest() throws Exception { |
|
|
|
String memId = "321178010928119808"; |
|
|
|
String memPhone = "13910154397"; |
|
|
|
String sceneType = "2"; // 核销 |
|
|
|
String posOrderId = "1"; |
|
|
|
String posAmount = "20000"; |
|
|
|
String posPayOrderId = "1"; |
|
|
|
String posPaymentType = "4"; |
|
|
|
String posPaymentTypeDes = "优惠券"; |
|
|
|
String posPaymentStatus = "0"; |
|
|
|
|
|
|
|
String couponOrderId = "321878223800205312"; |
|
|
|
|
|
|
|
Date curDate = new Date(); |
|
|
|
|
|
|
|
Map<String, String> payDetailOne = new HashMap<>(); |
|
|
|
payDetailOne.put(WxPayConstant.NEU_PAY_ORDER_ID, posPayOrderId); |
|
|
|
payDetailOne.put(WxPayConstant.NEU_PAY_ORDER_TIME, neuDateFormat.format(curDate)); |
|
|
|
payDetailOne.put(WxPayConstant.NEU_PAY_ORDER_TYPE, posPaymentType); |
|
|
|
payDetailOne.put(WxPayConstant.NEU_PAY_ORDER_TYPE_DES, posPaymentTypeDes); |
|
|
|
payDetailOne.put(WxPayConstant.NEU_PAY_ORDER_PARAM, "{}"); |
|
|
|
payDetailOne.put(WxPayConstant.NEU_PAY_ORDER_STATUS, posPaymentStatus); |
|
|
|
payDetailOne.put(WxPayConstant.NEU_PAY_ORDER_OUT_NO, couponOrderId); |
|
|
|
payDetailOne.put(WxPayConstant.NEU_PAY_ORDER_AMOUNT, posAmount); |
|
|
|
payDetailOne.put(WxPayConstant.NEU_PAY_ORDER_OUT_TIME, neuDateFormat.format(curDate)); |
|
|
|
|
|
|
|
JSONArray payDetailList = new JSONArray(); |
|
|
|
payDetailList.add(payDetailOne); |
|
|
|
|
|
|
|
Map<String, String> reqObj = new HashMap<>(); |
|
|
|
reqObj.put(WxPayConstant.NONCE_STR, "1"); |
|
|
|
reqObj.put(WxPayConstant.DEV_ID, devId); |
|
|
|
reqObj.put(WxPayConstant.NEU_TENANT_ID, tenantId); |
|
|
|
reqObj.put(WxPayConstant.NEU_MERCHANT_ID, merchantId); |
|
|
|
reqObj.put(WxPayConstant.NEU_BU_USER_ID, buUserId); |
|
|
|
reqObj.put(WxPayConstant.NEU_MEM_ID, memId); |
|
|
|
reqObj.put(WxPayConstant.NEU_MEM_PHONE, memPhone); |
|
|
|
reqObj.put(WxPayConstant.NEU_ORDER_SCENE_TYPE, sceneType); |
|
|
|
reqObj.put(WxPayConstant.NEU_ORDER_ID, posOrderId); |
|
|
|
reqObj.put(WxPayConstant.NEU_ORDER_TIME, neuDateFormat.format(curDate)); |
|
|
|
reqObj.put(WxPayConstant.NEU_ORDER_AMOUNT, posAmount); |
|
|
|
reqObj.put(WxPayConstant.NEU_ORDER_CREATE_SN, posSN); |
|
|
|
reqObj.put(WxPayConstant.NEU_ORDER_STATUS, "0"); |
|
|
|
JSONObject payDetail = new JSONObject(); |
|
|
|
payDetail.put(WxPayConstant.NEU_PAY_DETAIL_LIST, JSON.toJSONString(payDetailList)); |
|
|
|
reqObj.put(WxPayConstant.NEU_PAY_DETAIL, JSON.toJSONString(payDetail)); |
|
|
|
boolean resSigned = sendAndRes("/posOrderSync", reqObj); |
|
|
|
Assert.assertEquals(resSigned, true); |
|
|
|
} |
|
|
|
|
|
|
|
@Test |
|
|
|
public void couponOrderPreVerifyTest() throws Exception { |
|
|
|
String couponOrderId = "321877927162249216"; |
|
|
|
@@ -264,67 +315,7 @@ public class PosAppTest { |
|
|
|
doCardPayPreCancel(cardId, cardSpendId, posOrderId); |
|
|
|
} |
|
|
|
|
|
|
|
private void doCheckMem(String memId, String phone, String posOrderId, String posAmount) throws Exception { |
|
|
|
Map<String, String> reqObj = new HashMap<>(); |
|
|
|
reqObj.put(WxPayConstant.NONCE_STR, "1"); |
|
|
|
reqObj.put(WxPayConstant.DEV_ID, devId); |
|
|
|
reqObj.put(WxPayConstant.TENANT_ID, tenantId); |
|
|
|
reqObj.put(WxPayConstant.MERCHANT_ID, merchantId); |
|
|
|
reqObj.put(WxPayConstant.BUSER_ID, buUserId); |
|
|
|
if (StringUtils.isNotBlank(memId)) { |
|
|
|
reqObj.put(WxPayConstant.MEM_ID, memId); |
|
|
|
} |
|
|
|
if (StringUtils.isNotBlank(phone)) { |
|
|
|
reqObj.put(WxPayConstant.MEM_PHONE, phone); |
|
|
|
} |
|
|
|
reqObj.put(WxPayConstant.POS_ORDER_ID, posOrderId); |
|
|
|
reqObj.put(WxPayConstant.POS_AMOUNT, posAmount); |
|
|
|
reqObj.put(WxPayConstant.SIGN, WxPayment.createSignHMAC(reqObj, devReqKey)); |
|
|
|
String reqJsonStr = JSONObject.toJSONString(reqObj); |
|
|
|
MvcResult result = mockMvc.perform( |
|
|
|
MockMvcRequestBuilders.post("/checkMem") |
|
|
|
.contentType(MediaType.APPLICATION_JSON) |
|
|
|
.content(reqJsonStr)) |
|
|
|
.andExpect(MockMvcResultMatchers.status().isOk()) |
|
|
|
.andDo(MockMvcResultHandlers.print()) |
|
|
|
.andReturn(); |
|
|
|
String responseStr = result.getResponse().getContentAsString(); |
|
|
|
ObjectMapper mapper = new ObjectMapper(); |
|
|
|
Map<String,String> respMap = mapper.readValue(responseStr, Map.class); |
|
|
|
boolean resSigned = WxPayment.verifyNotifyHMAC(respMap, devResKey); |
|
|
|
Assert.assertEquals(resSigned, true); |
|
|
|
} |
|
|
|
|
|
|
|
private void doCalcMem(String memId, String phone, String posAmount, String selCoList) throws Exception { |
|
|
|
Map<String, String> reqObj = new HashMap<>(); |
|
|
|
reqObj.put(WxPayConstant.NONCE_STR, "1"); |
|
|
|
reqObj.put(WxPayConstant.DEV_ID, devId); |
|
|
|
reqObj.put(WxPayConstant.TENANT_ID, tenantId); |
|
|
|
reqObj.put(WxPayConstant.MERCHANT_ID, merchantId); |
|
|
|
reqObj.put(WxPayConstant.BUSER_ID, buUserId); |
|
|
|
if (StringUtils.isNotBlank(memId)) { |
|
|
|
reqObj.put(WxPayConstant.MEM_ID, memId); |
|
|
|
} |
|
|
|
if (StringUtils.isNotBlank(phone)) { |
|
|
|
reqObj.put(WxPayConstant.MEM_PHONE, phone); |
|
|
|
} |
|
|
|
reqObj.put(WxPayConstant.POS_AMOUNT, posAmount); |
|
|
|
reqObj.put(WxPayConstant.SELECTED_COUPON_ORDER_LIST, selCoList); |
|
|
|
reqObj.put(WxPayConstant.SIGN, WxPayment.createSignHMAC(reqObj, devReqKey)); |
|
|
|
String reqJsonStr = JSONObject.toJSONString(reqObj); |
|
|
|
MvcResult result = mockMvc.perform( |
|
|
|
MockMvcRequestBuilders.post("/calcMem") |
|
|
|
.contentType(MediaType.APPLICATION_JSON) |
|
|
|
.content(reqJsonStr)) |
|
|
|
.andExpect(MockMvcResultMatchers.status().isOk()) |
|
|
|
.andDo(MockMvcResultHandlers.print()) |
|
|
|
.andReturn(); |
|
|
|
String responseStr = result.getResponse().getContentAsString(); |
|
|
|
ObjectMapper mapper = new ObjectMapper(); |
|
|
|
Map<String,String> respMap = mapper.readValue(responseStr, Map.class); |
|
|
|
boolean resSigned = WxPayment.verifyNotifyHMAC(respMap, devResKey); |
|
|
|
Assert.assertEquals(resSigned, true); |
|
|
|
} |
|
|
|
|
|
|
|
private void doCheckCouponOrder(String couponOrderId, String sceneType, String posOrderId, String posAmount) throws Exception { |
|
|
|
Map<String, String> reqObj = new HashMap<>(); |
|
|
|
@@ -337,19 +328,7 @@ public class PosAppTest { |
|
|
|
reqObj.put(WxPayConstant.SCENE_TYPE, sceneType); |
|
|
|
reqObj.put(WxPayConstant.POS_ORDER_ID, posOrderId); |
|
|
|
reqObj.put(WxPayConstant.POS_AMOUNT, posAmount); |
|
|
|
reqObj.put(WxPayConstant.SIGN, WxPayment.createSignHMAC(reqObj, devReqKey)); |
|
|
|
String reqJsonStr = JSONObject.toJSONString(reqObj); |
|
|
|
MvcResult result = mockMvc.perform( |
|
|
|
MockMvcRequestBuilders.post("/checkCouponOrder") |
|
|
|
.contentType(MediaType.APPLICATION_JSON) |
|
|
|
.content(reqJsonStr)) |
|
|
|
.andExpect(MockMvcResultMatchers.status().isOk()) |
|
|
|
.andDo(MockMvcResultHandlers.print()) |
|
|
|
.andReturn(); |
|
|
|
String responseStr = result.getResponse().getContentAsString(); |
|
|
|
ObjectMapper mapper = new ObjectMapper(); |
|
|
|
Map<String, String> respMap = mapper.readValue(responseStr, Map.class); |
|
|
|
boolean resSigned = WxPayment.verifyNotifyHMAC(respMap, devResKey); |
|
|
|
boolean resSigned = sendAndRes("/checkCouponOrder", reqObj); |
|
|
|
Assert.assertEquals(resSigned, true); |
|
|
|
} |
|
|
|
|
|
|
|
@@ -362,20 +341,7 @@ public class PosAppTest { |
|
|
|
reqObj.put(WxPayConstant.BUSER_ID, buUserId); |
|
|
|
reqObj.put(WxPayConstant.COUPON_ORDER_ID, couponOrderId); |
|
|
|
reqObj.put(WxPayConstant.POS_ORDER_ID, posOrderId); |
|
|
|
reqObj.put(WxPayConstant.SIGN, WxPayment.createSignHMAC(reqObj, devReqKey)); |
|
|
|
String reqJsonStr = JSONObject.toJSONString(reqObj); |
|
|
|
MvcResult result = mockMvc.perform( |
|
|
|
MockMvcRequestBuilders.post("/couponOrderVerify") |
|
|
|
.contentType(MediaType.APPLICATION_JSON) |
|
|
|
.content(reqJsonStr)) |
|
|
|
.andExpect(MockMvcResultMatchers.status().isOk()) |
|
|
|
.andDo(MockMvcResultHandlers.print()) |
|
|
|
.andReturn(); |
|
|
|
String responseStr = result.getResponse().getContentAsString(); |
|
|
|
|
|
|
|
ObjectMapper mapper = new ObjectMapper(); |
|
|
|
Map<String,String> respMap = mapper.readValue(responseStr, Map.class); |
|
|
|
boolean resSigned = WxPayment.verifyNotifyHMAC(respMap, devResKey); |
|
|
|
boolean resSigned = sendAndRes("/couponOrderVerify", reqObj); |
|
|
|
Assert.assertEquals(resSigned, true); |
|
|
|
} |
|
|
|
|
|
|
|
@@ -388,19 +354,7 @@ public class PosAppTest { |
|
|
|
reqObj.put(WxPayConstant.BUSER_ID, buUserId); |
|
|
|
reqObj.put(WxPayConstant.COUPON_ORDER_ID, couponOrderId); |
|
|
|
reqObj.put(WxPayConstant.POS_ORDER_ID, posOrderId); |
|
|
|
reqObj.put(WxPayConstant.SIGN, WxPayment.createSignHMAC(reqObj, devReqKey)); |
|
|
|
String reqJsonStr = JSONObject.toJSONString(reqObj); |
|
|
|
MvcResult result = mockMvc.perform( |
|
|
|
MockMvcRequestBuilders.post("/couponOrderVerifyCancel") |
|
|
|
.contentType(MediaType.APPLICATION_JSON) |
|
|
|
.content(reqJsonStr)) |
|
|
|
.andExpect(MockMvcResultMatchers.status().isOk()) |
|
|
|
.andDo(MockMvcResultHandlers.print()) |
|
|
|
.andReturn(); |
|
|
|
String responseStr = result.getResponse().getContentAsString(); |
|
|
|
ObjectMapper mapper = new ObjectMapper(); |
|
|
|
Map<String,String> respMap = mapper.readValue(responseStr, Map.class); |
|
|
|
boolean resSigned = WxPayment.verifyNotifyHMAC(respMap, devResKey); |
|
|
|
boolean resSigned = sendAndRes("/couponOrderVerifyCancel", reqObj); |
|
|
|
Assert.assertEquals(resSigned, true); |
|
|
|
} |
|
|
|
|
|
|
|
@@ -414,19 +368,7 @@ public class PosAppTest { |
|
|
|
reqObj.put(WxPayConstant.COUPON_ORDER_ID, couponOrderId); |
|
|
|
reqObj.put(WxPayConstant.POS_ORDER_ID, posOrderId); |
|
|
|
reqObj.put(WxPayConstant.POS_AMOUNT, posAmount); |
|
|
|
reqObj.put(WxPayConstant.SIGN, WxPayment.createSignHMAC(reqObj, devReqKey)); |
|
|
|
String reqJsonStr = JSONObject.toJSONString(reqObj); |
|
|
|
MvcResult result = mockMvc.perform( |
|
|
|
MockMvcRequestBuilders.post("/couponOrderPreVerify") |
|
|
|
.contentType(MediaType.APPLICATION_JSON) |
|
|
|
.content(reqJsonStr)) |
|
|
|
.andExpect(MockMvcResultMatchers.status().isOk()) |
|
|
|
.andDo(MockMvcResultHandlers.print()) |
|
|
|
.andReturn(); |
|
|
|
String responseStr = result.getResponse().getContentAsString(); |
|
|
|
ObjectMapper mapper = new ObjectMapper(); |
|
|
|
Map<String,String> respMap = mapper.readValue(responseStr, Map.class); |
|
|
|
boolean resSigned = WxPayment.verifyNotifyHMAC(respMap, devResKey); |
|
|
|
boolean resSigned = sendAndRes("/couponOrderPreVerify", reqObj); |
|
|
|
Assert.assertEquals(resSigned, true); |
|
|
|
} |
|
|
|
|
|
|
|
@@ -440,19 +382,7 @@ public class PosAppTest { |
|
|
|
reqObj.put(WxPayConstant.BUSER_ID, buUserId); |
|
|
|
reqObj.put(WxPayConstant.COUPON_ORDER_ID, couponOrderId); |
|
|
|
reqObj.put(WxPayConstant.POS_ORDER_ID, posOrderId); |
|
|
|
reqObj.put(WxPayConstant.SIGN, WxPayment.createSignHMAC(reqObj, devReqKey)); |
|
|
|
String reqJsonStr = JSONObject.toJSONString(reqObj); |
|
|
|
MvcResult result = mockMvc.perform( |
|
|
|
MockMvcRequestBuilders.post("/couponOrderPreVerifyCancel") |
|
|
|
.contentType(MediaType.APPLICATION_JSON) |
|
|
|
.content(reqJsonStr)) |
|
|
|
.andExpect(MockMvcResultMatchers.status().isOk()) |
|
|
|
.andDo(MockMvcResultHandlers.print()) |
|
|
|
.andReturn(); |
|
|
|
String responseStr = result.getResponse().getContentAsString(); |
|
|
|
ObjectMapper mapper = new ObjectMapper(); |
|
|
|
Map<String,String> respMap = mapper.readValue(responseStr, Map.class); |
|
|
|
boolean resSigned = WxPayment.verifyNotifyHMAC(respMap, devResKey); |
|
|
|
boolean resSigned = sendAndRes("/couponOrderPreVerifyCancel", reqObj); |
|
|
|
Assert.assertEquals(resSigned, true); |
|
|
|
} |
|
|
|
|
|
|
|
@@ -466,19 +396,7 @@ public class PosAppTest { |
|
|
|
reqObj.put(WxPayConstant.COUPON_ORDER_ID, couponOrderId); |
|
|
|
reqObj.put(WxPayConstant.POS_ORDER_ID, posOrderId); |
|
|
|
reqObj.put(WxPayConstant.POS_AMOUNT, posAmount); |
|
|
|
reqObj.put(WxPayConstant.SIGN, WxPayment.createSignHMAC(reqObj, devReqKey)); |
|
|
|
String reqJsonStr = JSONObject.toJSONString(reqObj); |
|
|
|
MvcResult result = mockMvc.perform( |
|
|
|
MockMvcRequestBuilders.post("/couponOrderPayVerifyOne") |
|
|
|
.contentType(MediaType.APPLICATION_JSON) |
|
|
|
.content(reqJsonStr)) |
|
|
|
.andExpect(MockMvcResultMatchers.status().isOk()) |
|
|
|
.andDo(MockMvcResultHandlers.print()) |
|
|
|
.andReturn(); |
|
|
|
String responseStr = result.getResponse().getContentAsString(); |
|
|
|
ObjectMapper mapper = new ObjectMapper(); |
|
|
|
Map<String,String> respMap = mapper.readValue(responseStr, Map.class); |
|
|
|
boolean resSigned = WxPayment.verifyNotifyHMAC(respMap, devResKey); |
|
|
|
boolean resSigned = sendAndRes("/couponOrderPayVerifyOne", reqObj); |
|
|
|
Assert.assertEquals(resSigned, true); |
|
|
|
} |
|
|
|
|
|
|
|
@@ -492,19 +410,7 @@ public class PosAppTest { |
|
|
|
reqObj.put(WxPayConstant.SELECTED_COUPON_ORDER_LIST, couponOrderIdList); |
|
|
|
reqObj.put(WxPayConstant.POS_ORDER_ID, posOrderId); |
|
|
|
reqObj.put(WxPayConstant.POS_AMOUNT, posAmount); |
|
|
|
reqObj.put(WxPayConstant.SIGN, WxPayment.createSignHMAC(reqObj, devReqKey)); |
|
|
|
String reqJsonStr = JSONObject.toJSONString(reqObj); |
|
|
|
MvcResult result = mockMvc.perform( |
|
|
|
MockMvcRequestBuilders.post("/couponOrderPayVerifyList") |
|
|
|
.contentType(MediaType.APPLICATION_JSON) |
|
|
|
.content(reqJsonStr)) |
|
|
|
.andExpect(MockMvcResultMatchers.status().isOk()) |
|
|
|
.andDo(MockMvcResultHandlers.print()) |
|
|
|
.andReturn(); |
|
|
|
String responseStr = result.getResponse().getContentAsString(); |
|
|
|
ObjectMapper mapper = new ObjectMapper(); |
|
|
|
Map<String,String> respMap = mapper.readValue(responseStr, Map.class); |
|
|
|
boolean resSigned = WxPayment.verifyNotifyHMAC(respMap, devResKey); |
|
|
|
boolean resSigned = sendAndRes("/couponOrderPayVerifyList", reqObj); |
|
|
|
Assert.assertEquals(resSigned, true); |
|
|
|
} |
|
|
|
|
|
|
|
@@ -518,19 +424,7 @@ public class PosAppTest { |
|
|
|
reqObj.put(WxPayConstant.POS_ORDER_ID, posOrderId); |
|
|
|
reqObj.put(WxPayConstant.POS_AMOUNT, posAmount); |
|
|
|
reqObj.put(WxPayConstant.CARD_ID, cardId); |
|
|
|
reqObj.put(WxPayConstant.SIGN, WxPayment.createSignHMAC(reqObj, devReqKey)); |
|
|
|
String reqJsonStr = JSONObject.toJSONString(reqObj); |
|
|
|
MvcResult result = mockMvc.perform( |
|
|
|
MockMvcRequestBuilders.post("/cardPayPre") |
|
|
|
.contentType(MediaType.APPLICATION_JSON) |
|
|
|
.content(reqJsonStr)) |
|
|
|
.andExpect(MockMvcResultMatchers.status().isOk()) |
|
|
|
.andDo(MockMvcResultHandlers.print()) |
|
|
|
.andReturn(); |
|
|
|
String responseStr = result.getResponse().getContentAsString(); |
|
|
|
ObjectMapper mapper = new ObjectMapper(); |
|
|
|
Map<String,String> respMap = mapper.readValue(responseStr, Map.class); |
|
|
|
boolean resSigned = WxPayment.verifyNotifyHMAC(respMap, devResKey); |
|
|
|
boolean resSigned = sendAndRes("/cardPayPre", reqObj); |
|
|
|
Assert.assertEquals(resSigned, true); |
|
|
|
} |
|
|
|
|
|
|
|
@@ -545,72 +439,23 @@ public class PosAppTest { |
|
|
|
reqObj.put(WxPayConstant.POS_ORDER_ID, posOrderId); |
|
|
|
reqObj.put(WxPayConstant.CARD_ID, cardId); |
|
|
|
reqObj.put(WxPayConstant.CARD_SPEND_ID, cardSpendId); |
|
|
|
reqObj.put(WxPayConstant.SIGN, WxPayment.createSignHMAC(reqObj, devReqKey)); |
|
|
|
String reqJsonStr = JSONObject.toJSONString(reqObj); |
|
|
|
MvcResult result = mockMvc.perform( |
|
|
|
MockMvcRequestBuilders.post("/cardPayPreCancel") |
|
|
|
.contentType(MediaType.APPLICATION_JSON) |
|
|
|
.content(reqJsonStr)) |
|
|
|
.andExpect(MockMvcResultMatchers.status().isOk()) |
|
|
|
.andDo(MockMvcResultHandlers.print()) |
|
|
|
.andReturn(); |
|
|
|
String responseStr = result.getResponse().getContentAsString(); |
|
|
|
ObjectMapper mapper = new ObjectMapper(); |
|
|
|
Map<String,String> respMap = mapper.readValue(responseStr, Map.class); |
|
|
|
boolean resSigned = WxPayment.verifyNotifyHMAC(respMap, devResKey); |
|
|
|
Assert.assertEquals(resSigned, true); |
|
|
|
} |
|
|
|
|
|
|
|
private void doCardPay(String cardId, String posOrderId, String posAmount) throws Exception { |
|
|
|
Map<String, String> reqObj = new HashMap<>(); |
|
|
|
reqObj.put(WxPayConstant.NONCE_STR, "1"); |
|
|
|
reqObj.put(WxPayConstant.DEV_ID, devId); |
|
|
|
reqObj.put(WxPayConstant.TENANT_ID, tenantId); |
|
|
|
reqObj.put(WxPayConstant.MERCHANT_ID, merchantId); |
|
|
|
reqObj.put(WxPayConstant.BUSER_ID, buUserId); |
|
|
|
reqObj.put(WxPayConstant.POS_ORDER_ID, posOrderId); |
|
|
|
reqObj.put(WxPayConstant.POS_AMOUNT, posAmount); |
|
|
|
reqObj.put(WxPayConstant.CARD_ID, cardId); |
|
|
|
reqObj.put(WxPayConstant.SIGN, WxPayment.createSignHMAC(reqObj, devReqKey)); |
|
|
|
String reqJsonStr = JSONObject.toJSONString(reqObj); |
|
|
|
MvcResult result = mockMvc.perform( |
|
|
|
MockMvcRequestBuilders.post("/cardPay") |
|
|
|
.contentType(MediaType.APPLICATION_JSON) |
|
|
|
.content(reqJsonStr)) |
|
|
|
.andExpect(MockMvcResultMatchers.status().isOk()) |
|
|
|
.andDo(MockMvcResultHandlers.print()) |
|
|
|
.andReturn(); |
|
|
|
String responseStr = result.getResponse().getContentAsString(); |
|
|
|
ObjectMapper mapper = new ObjectMapper(); |
|
|
|
Map<String,String> respMap = mapper.readValue(responseStr, Map.class); |
|
|
|
boolean resSigned = WxPayment.verifyNotifyHMAC(respMap, devResKey); |
|
|
|
boolean resSigned = sendAndRes("/cardPayPreCancel", reqObj); |
|
|
|
Assert.assertEquals(resSigned, true); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private void doCardPayCancel(String cardId, String cardSpendId, String posOrderId) throws Exception { |
|
|
|
Map<String, String> reqObj = new HashMap<>(); |
|
|
|
reqObj.put(WxPayConstant.NONCE_STR, "1"); |
|
|
|
reqObj.put(WxPayConstant.DEV_ID, devId); |
|
|
|
reqObj.put(WxPayConstant.TENANT_ID, tenantId); |
|
|
|
reqObj.put(WxPayConstant.MERCHANT_ID, merchantId); |
|
|
|
reqObj.put(WxPayConstant.BUSER_ID, buUserId); |
|
|
|
reqObj.put(WxPayConstant.POS_ORDER_ID, posOrderId); |
|
|
|
reqObj.put(WxPayConstant.CARD_ID, cardId); |
|
|
|
reqObj.put(WxPayConstant.CARD_SPEND_ID, cardSpendId); |
|
|
|
reqObj.put(WxPayConstant.SIGN, WxPayment.createSignHMAC(reqObj, devReqKey)); |
|
|
|
String reqJsonStr = JSONObject.toJSONString(reqObj); |
|
|
|
MvcResult result = mockMvc.perform( |
|
|
|
MockMvcRequestBuilders.post("/cardPayCancel") |
|
|
|
.contentType(MediaType.APPLICATION_JSON) |
|
|
|
.content(reqJsonStr)) |
|
|
|
.andExpect(MockMvcResultMatchers.status().isOk()) |
|
|
|
.andDo(MockMvcResultHandlers.print()) |
|
|
|
.andReturn(); |
|
|
|
String responseStr = result.getResponse().getContentAsString(); |
|
|
|
ObjectMapper mapper = new ObjectMapper(); |
|
|
|
Map<String,String> respMap = mapper.readValue(responseStr, Map.class); |
|
|
|
boolean resSigned = WxPayment.verifyNotifyHMAC(respMap, devResKey); |
|
|
|
Assert.assertEquals(resSigned, true); |
|
|
|
} |
|
|
|
private boolean sendAndRes(String url, Map<String, String> reqObj) throws Exception { |
|
|
|
reqObj.put(WxPayConstant.SIGN, WxPayment.createSignHMAC(reqObj, devReqKey)); |
|
|
|
String reqJsonStr = JSONObject.toJSONString(reqObj); |
|
|
|
MvcResult result = mockMvc.perform( |
|
|
|
MockMvcRequestBuilders.post(url) |
|
|
|
.contentType(MediaType.APPLICATION_JSON) |
|
|
|
.content(reqJsonStr)) |
|
|
|
.andExpect(MockMvcResultMatchers.status().isOk()) |
|
|
|
.andDo(MockMvcResultHandlers.print()) |
|
|
|
.andReturn(); |
|
|
|
String responseStr = result.getResponse().getContentAsString(); |
|
|
|
ObjectMapper mapper = new ObjectMapper(); |
|
|
|
Map<String,String> respMap = mapper.readValue(responseStr, Map.class); |
|
|
|
return WxPayment.verifyNotifyHMAC(respMap, devResKey); |
|
|
|
} |
|
|
|
} |