|
|
|
@@ -5,6 +5,7 @@ import com.fasterxml.jackson.databind.ObjectMapper; |
|
|
|
import com.iformall.PosApplication; |
|
|
|
import com.iformall.pay.WxPayConstant; |
|
|
|
import com.iformall.pay.WxPayment; |
|
|
|
import org.apache.commons.lang3.StringUtils; |
|
|
|
import org.junit.Assert; |
|
|
|
import org.junit.FixMethodOrder; |
|
|
|
import org.junit.Test; |
|
|
|
@@ -140,48 +141,95 @@ public class PosAppTest { |
|
|
|
|
|
|
|
@Test |
|
|
|
public void checkMemTest() throws Exception { |
|
|
|
Map<String, String> reqObj = new HashMap<>(); |
|
|
|
reqObj.put(WxPayConstant.DEV_ID, devId); |
|
|
|
reqObj.put(WxPayConstant.TENANT_ID, tenantId); |
|
|
|
reqObj.put(WxPayConstant.MERCHANT_ID, merchantId); |
|
|
|
// reqObj.put(WxPayConstant.MEM_ID, "321178010928119808"); |
|
|
|
reqObj.put(WxPayConstant.MEM_PHONE, "13910154397"); |
|
|
|
reqObj.put(WxPayConstant.POS_ORDER_ID, "1"); |
|
|
|
reqObj.put(WxPayConstant.POS_AMOUNT, "200"); |
|
|
|
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); |
|
|
|
String memId = "321178010928119808"; |
|
|
|
String phone = "13910154397"; |
|
|
|
String posOrderId = "1"; |
|
|
|
String posAmount = "200"; |
|
|
|
doCheckMem(memId, phone, posOrderId, posAmount); |
|
|
|
} |
|
|
|
|
|
|
|
@Test |
|
|
|
public void checkCouponOrderForIndeepdentVerifyTest() throws Exception { |
|
|
|
String couponOrderId = "321877927162249216"; |
|
|
|
String verifyType = "independent"; |
|
|
|
String posOrderId = "1"; |
|
|
|
String posAmount = "100"; |
|
|
|
doCheckVerify(couponOrderId, verifyType, posOrderId, posAmount); |
|
|
|
} |
|
|
|
|
|
|
|
@Test |
|
|
|
public void checkCouponOrderForPayVerifyTest() throws Exception { |
|
|
|
String couponOrderId = "321877927162249216"; |
|
|
|
String verifyType = "pay"; |
|
|
|
String posOrderId = "1"; |
|
|
|
String posAmount = "100"; |
|
|
|
doCheckVerify(couponOrderId, verifyType, posOrderId, posAmount); |
|
|
|
} |
|
|
|
|
|
|
|
@Test |
|
|
|
public void couponOrderIndependentVerifyTest() throws Exception { |
|
|
|
String couponOrderId = "321878223800205312"; |
|
|
|
String posOrderId = "1"; |
|
|
|
doIndependentVerify(couponOrderId, posOrderId); |
|
|
|
} |
|
|
|
|
|
|
|
@Test |
|
|
|
public void couponOrderVerifyCancelTest() throws Exception { |
|
|
|
String couponOrderId = "321878223800205312"; |
|
|
|
String posOrderId = "1"; |
|
|
|
doVerifyCancel(couponOrderId, posOrderId); |
|
|
|
} |
|
|
|
|
|
|
|
@Test |
|
|
|
public void couponOrderPreVerifyTest() throws Exception { |
|
|
|
String couponOrderId = "321877927162249216"; |
|
|
|
String posOrderId = "1"; |
|
|
|
String posAmount = "200"; |
|
|
|
doPreVerify(couponOrderId, posOrderId, posAmount); |
|
|
|
} |
|
|
|
|
|
|
|
@Test |
|
|
|
public void couponOrderPreVerifyCancelTest() throws Exception { |
|
|
|
String couponOrderId = "321877927162249216"; |
|
|
|
String posOrderId = "1"; |
|
|
|
doPreVerifyCancel(couponOrderId, posOrderId); |
|
|
|
} |
|
|
|
|
|
|
|
@Test |
|
|
|
public void couponOrderPayVerifyTest() throws Exception { |
|
|
|
String couponOrderId = "321877927162249216"; |
|
|
|
String posOrderId = "1"; |
|
|
|
String posAmount = "200"; |
|
|
|
doPayVerifyOne(couponOrderId, posOrderId, posAmount); |
|
|
|
} |
|
|
|
|
|
|
|
@Test |
|
|
|
public void couponOrderPayVerifyListTest() throws Exception { |
|
|
|
String couponOrderIdList = "[\"321878223800205312\"]"; |
|
|
|
String posOrderId = "1"; |
|
|
|
String posAmount = "200"; |
|
|
|
doPayVerifyList(couponOrderIdList, posOrderId, posAmount); |
|
|
|
} |
|
|
|
|
|
|
|
private void doCheckMem(String memId, String phone, String posOrderId, String posAmount) throws Exception { |
|
|
|
Map<String, String> reqObj = new HashMap<>(); |
|
|
|
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.COUPON_ORDER_ID, "321872988134408192"); |
|
|
|
reqObj.put(WxPayConstant.NONCE_STR, "1"); |
|
|
|
reqObj.put(WxPayConstant.VERIFY_TYPE, "independent"); |
|
|
|
reqObj.put(WxPayConstant.POS_ORDER_ID, "1"); |
|
|
|
reqObj.put(WxPayConstant.POS_AMOUNT, "100"); |
|
|
|
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("/checkCouponOrderForVerify") |
|
|
|
.contentType(MediaType.APPLICATION_JSON) |
|
|
|
.content(reqJsonStr)) |
|
|
|
MockMvcRequestBuilders.post("/checkMem") |
|
|
|
.contentType(MediaType.APPLICATION_JSON) |
|
|
|
.content(reqJsonStr)) |
|
|
|
.andExpect(MockMvcResultMatchers.status().isOk()) |
|
|
|
.andDo(MockMvcResultHandlers.print()) |
|
|
|
.andReturn(); |
|
|
|
@@ -192,50 +240,48 @@ public class PosAppTest { |
|
|
|
Assert.assertEquals(resSigned, true); |
|
|
|
} |
|
|
|
|
|
|
|
@Test |
|
|
|
public void checkCouponOrderForPayVerifyTest() throws Exception { |
|
|
|
private void doCheckVerify(String couponOrderId, String verifyType, String posOrderId, String posAmount) throws Exception { |
|
|
|
Map<String, String> reqObj = new HashMap<>(); |
|
|
|
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.COUPON_ORDER_ID, "321878223800205312"); |
|
|
|
reqObj.put(WxPayConstant.COUPON_ORDER_ID, couponOrderId); |
|
|
|
reqObj.put(WxPayConstant.NONCE_STR, "1"); |
|
|
|
reqObj.put(WxPayConstant.VERIFY_TYPE, "pay"); |
|
|
|
reqObj.put(WxPayConstant.POS_ORDER_ID, "1"); |
|
|
|
reqObj.put(WxPayConstant.POS_AMOUNT, "100"); |
|
|
|
reqObj.put(WxPayConstant.VERIFY_TYPE, verifyType); |
|
|
|
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("/checkCouponOrderForVerify") |
|
|
|
.contentType(MediaType.APPLICATION_JSON) |
|
|
|
.content(reqJsonStr)) |
|
|
|
.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); |
|
|
|
Map<String, String> respMap = mapper.readValue(responseStr, Map.class); |
|
|
|
boolean resSigned = WxPayment.verifyNotifyHMAC(respMap, devResKey); |
|
|
|
Assert.assertEquals(resSigned, true); |
|
|
|
} |
|
|
|
|
|
|
|
@Test |
|
|
|
public void couponOrderIndependentVerifyTest() throws Exception { |
|
|
|
private void doIndependentVerify(String couponOrderId, String posOrderId) throws Exception { |
|
|
|
Map<String, String> reqObj = new HashMap<>(); |
|
|
|
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.COUPON_ORDER_ID, "321878223800205312"); |
|
|
|
reqObj.put(WxPayConstant.COUPON_ORDER_ID, couponOrderId); |
|
|
|
reqObj.put(WxPayConstant.NONCE_STR, "1"); |
|
|
|
reqObj.put(WxPayConstant.POS_ORDER_ID, "1"); |
|
|
|
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("/couponOrderIndependentVerify") |
|
|
|
.contentType(MediaType.APPLICATION_JSON) |
|
|
|
.content(reqJsonStr)) |
|
|
|
.contentType(MediaType.APPLICATION_JSON) |
|
|
|
.content(reqJsonStr)) |
|
|
|
.andExpect(MockMvcResultMatchers.status().isOk()) |
|
|
|
.andDo(MockMvcResultHandlers.print()) |
|
|
|
.andReturn(); |
|
|
|
@@ -247,22 +293,21 @@ public class PosAppTest { |
|
|
|
Assert.assertEquals(resSigned, true); |
|
|
|
} |
|
|
|
|
|
|
|
@Test |
|
|
|
public void couponOrderVerifyCancelTest() throws Exception { |
|
|
|
private void doVerifyCancel(String couponOrderId, String posOrderId) throws Exception { |
|
|
|
Map<String, String> reqObj = new HashMap<>(); |
|
|
|
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.COUPON_ORDER_ID, "321878223800205312"); |
|
|
|
reqObj.put(WxPayConstant.COUPON_ORDER_ID, couponOrderId); |
|
|
|
reqObj.put(WxPayConstant.NONCE_STR, "1"); |
|
|
|
reqObj.put(WxPayConstant.POS_ORDER_ID, "1"); |
|
|
|
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)) |
|
|
|
.contentType(MediaType.APPLICATION_JSON) |
|
|
|
.content(reqJsonStr)) |
|
|
|
.andExpect(MockMvcResultMatchers.status().isOk()) |
|
|
|
.andDo(MockMvcResultHandlers.print()) |
|
|
|
.andReturn(); |
|
|
|
@@ -273,23 +318,22 @@ public class PosAppTest { |
|
|
|
Assert.assertEquals(resSigned, true); |
|
|
|
} |
|
|
|
|
|
|
|
@Test |
|
|
|
public void couponOrderPreVerifyTest() throws Exception { |
|
|
|
private void doPreVerify(String couponOrderId, String posOrderId, String posAmount) throws Exception { |
|
|
|
Map<String, String> reqObj = new HashMap<>(); |
|
|
|
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.COUPON_ORDER_ID, "321878223800205312"); |
|
|
|
reqObj.put(WxPayConstant.COUPON_ORDER_ID, couponOrderId); |
|
|
|
reqObj.put(WxPayConstant.NONCE_STR, "1"); |
|
|
|
reqObj.put(WxPayConstant.POS_ORDER_ID, "1"); |
|
|
|
reqObj.put(WxPayConstant.POS_AMOUNT, "200"); |
|
|
|
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)) |
|
|
|
.contentType(MediaType.APPLICATION_JSON) |
|
|
|
.content(reqJsonStr)) |
|
|
|
.andExpect(MockMvcResultMatchers.status().isOk()) |
|
|
|
.andDo(MockMvcResultHandlers.print()) |
|
|
|
.andReturn(); |
|
|
|
@@ -300,22 +344,22 @@ public class PosAppTest { |
|
|
|
Assert.assertEquals(resSigned, true); |
|
|
|
} |
|
|
|
|
|
|
|
@Test |
|
|
|
public void couponOrderPreVerifyCancelTest() throws Exception { |
|
|
|
|
|
|
|
private void doPreVerifyCancel(String couponOrderId, String posOrderId) throws Exception { |
|
|
|
Map<String, String> reqObj = new HashMap<>(); |
|
|
|
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.COUPON_ORDER_ID, "321878223800205312"); |
|
|
|
reqObj.put(WxPayConstant.COUPON_ORDER_ID, couponOrderId); |
|
|
|
reqObj.put(WxPayConstant.NONCE_STR, "1"); |
|
|
|
reqObj.put(WxPayConstant.POS_ORDER_ID, "1"); |
|
|
|
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)) |
|
|
|
.contentType(MediaType.APPLICATION_JSON) |
|
|
|
.content(reqJsonStr)) |
|
|
|
.andExpect(MockMvcResultMatchers.status().isOk()) |
|
|
|
.andDo(MockMvcResultHandlers.print()) |
|
|
|
.andReturn(); |
|
|
|
@@ -326,23 +370,22 @@ public class PosAppTest { |
|
|
|
Assert.assertEquals(resSigned, true); |
|
|
|
} |
|
|
|
|
|
|
|
@Test |
|
|
|
public void couponOrderPayVerifyTest() throws Exception { |
|
|
|
private void doPayVerifyOne(String couponOrderId, String posOrderId, String posAmount) throws Exception { |
|
|
|
Map<String, String> reqObj = new HashMap<>(); |
|
|
|
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.COUPON_ORDER_ID, "321878223800205312"); |
|
|
|
reqObj.put(WxPayConstant.COUPON_ORDER_ID, couponOrderId); |
|
|
|
reqObj.put(WxPayConstant.NONCE_STR, "1"); |
|
|
|
reqObj.put(WxPayConstant.POS_ORDER_ID, "1"); |
|
|
|
reqObj.put(WxPayConstant.POS_AMOUNT, "200"); |
|
|
|
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)) |
|
|
|
.contentType(MediaType.APPLICATION_JSON) |
|
|
|
.content(reqJsonStr)) |
|
|
|
.andExpect(MockMvcResultMatchers.status().isOk()) |
|
|
|
.andDo(MockMvcResultHandlers.print()) |
|
|
|
.andReturn(); |
|
|
|
@@ -353,23 +396,22 @@ public class PosAppTest { |
|
|
|
Assert.assertEquals(resSigned, true); |
|
|
|
} |
|
|
|
|
|
|
|
@Test |
|
|
|
public void couponOrderPayVerifyListTest() throws Exception { |
|
|
|
private void doPayVerifyList(String couponOrderIdList, String posOrderId, String posAmount) throws Exception { |
|
|
|
Map<String, String> reqObj = new HashMap<>(); |
|
|
|
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.SELECTED_COUPON_ORDER_LIST, "[\"321878223800205312\"]"); |
|
|
|
reqObj.put(WxPayConstant.SELECTED_COUPON_ORDER_LIST, couponOrderIdList); |
|
|
|
reqObj.put(WxPayConstant.NONCE_STR, "1"); |
|
|
|
reqObj.put(WxPayConstant.POS_ORDER_ID, "1"); |
|
|
|
reqObj.put(WxPayConstant.POS_AMOUNT, "200"); |
|
|
|
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)) |
|
|
|
.contentType(MediaType.APPLICATION_JSON) |
|
|
|
.content(reqJsonStr)) |
|
|
|
.andExpect(MockMvcResultMatchers.status().isOk()) |
|
|
|
.andDo(MockMvcResultHandlers.print()) |
|
|
|
.andReturn(); |
|
|
|
|