Commit be82bb8a by caiyt

修复redis读取pickCode为空的问题,增加微信回调内容打印

parent 08790613
...@@ -173,10 +173,10 @@ public class WeixinServiceImpl { ...@@ -173,10 +173,10 @@ public class WeixinServiceImpl {
return sessionKeyOrOpenId; return sessionKeyOrOpenId;
} }
private LoginUser transLoginUser(Customer customer){ private LoginUser transLoginUser(Customer customer) {
SysUser user = new SysUser(); SysUser user = new SysUser();
user.setUserName(customer.getUserName()); user.setUserName(customer.getUserName());
LoginUser loginUser = new LoginUser(user,null); LoginUser loginUser = new LoginUser(user, null);
loginUser.setLoginTime(System.currentTimeMillis()); loginUser.setLoginTime(System.currentTimeMillis());
loginUser.setOpenId(customer.getId()); loginUser.setOpenId(customer.getId());
user.setPhonenumber(customer.getPhone()); user.setPhonenumber(customer.getPhone());
...@@ -209,9 +209,9 @@ public class WeixinServiceImpl { ...@@ -209,9 +209,9 @@ public class WeixinServiceImpl {
order.setOut_trade_no("wuyye9w8akwbq1nc60o4affwwqnxh9dn"); order.setOut_trade_no("wuyye9w8akwbq1nc60o4affwwqnxh9dn");
//order.setSign_type("MD5"); //order.setSign_type("MD5");
//生成签名 //生成签名
String sign = Signature.getSign(order,key); String sign = Signature.getSign(order, key);
order.setSign(sign); order.setSign(sign);
String result = restTemplate.postForObject(queryUrl,order,String.class); String result = restTemplate.postForObject(queryUrl, order, String.class);
System.out.println(result); System.out.println(result);
XStream xStream = new XStream(); XStream xStream = new XStream();
xStream.alias("xml", QueryReturnInfo.class); xStream.alias("xml", QueryReturnInfo.class);
...@@ -230,7 +230,7 @@ public class WeixinServiceImpl { ...@@ -230,7 +230,7 @@ public class WeixinServiceImpl {
@Autowired @Autowired
private WxPayService wxPayService; private WxPayService wxPayService;
public Map<String, String> weChatPay(HttpServletRequest r,String body,String orderNo,String openId,int money) { public Map<String, String> weChatPay(HttpServletRequest r, String body, String orderNo, String openId, int money) {
/** /**
* 处理内部业务,校验订单等 * 处理内部业务,校验订单等
*/ */
...@@ -248,7 +248,7 @@ public class WeixinServiceImpl { ...@@ -248,7 +248,7 @@ public class WeixinServiceImpl {
//回调的 URL 地址 //回调的 URL 地址
.notifyUrl("http://我们的域名/api/client/pay/weChatPayNotify") .notifyUrl("http://我们的域名/api/client/pay/weChatPayNotify")
.build(); .build();
WxPayUnifiedOrderResult wxPayUnifiedOrderResult =null; WxPayUnifiedOrderResult wxPayUnifiedOrderResult = null;
try { try {
wxPayUnifiedOrderResult = wxPayService.unifiedOrder(wxPayUnifiedOrderRequest); wxPayUnifiedOrderResult = wxPayService.unifiedOrder(wxPayUnifiedOrderRequest);
} catch (WxPayException e) { } catch (WxPayException e) {
...@@ -258,7 +258,7 @@ public class WeixinServiceImpl { ...@@ -258,7 +258,7 @@ public class WeixinServiceImpl {
return null; return null;
} }
public String refund(String orderNo,String refundNo,Integer totalFee,Integer refundFee) { public String refund(String orderNo, String refundNo, Integer totalFee, Integer refundFee) {
//申请退款 //申请退款
WxPayRefundRequest refundInfo = WxPayRefundRequest.newBuilder() WxPayRefundRequest refundInfo = WxPayRefundRequest.newBuilder()
//订单号 //订单号
...@@ -291,12 +291,8 @@ public class WeixinServiceImpl { ...@@ -291,12 +291,8 @@ public class WeixinServiceImpl {
} }
public Map<String, String> pay(HttpServletRequest r, String body, String orderNo, String openId, int money) {
try {
public Map<String, String> pay(HttpServletRequest r,String body,String orderNo,String openId,int money) {
try{
HttpClientUtils client = new HttpClientUtils(url); HttpClientUtils client = new HttpClientUtils(url);
//组装接口参数 //组装接口参数
Map<String, String> params = new HashMap<>(); Map<String, String> params = new HashMap<>();
...@@ -327,22 +323,22 @@ public class WeixinServiceImpl { ...@@ -327,22 +323,22 @@ public class WeixinServiceImpl {
Map<String, String> resultMap = WXPayUtil.xmlToMap(resultXml); Map<String, String> resultMap = WXPayUtil.xmlToMap(resultXml);
//错误处理 //错误处理
if("FAIL".equals(resultMap.get("return_code")) || "FAIL".equals(resultMap.get("result_code"))){ if ("FAIL".equals(resultMap.get("return_code")) || "FAIL".equals(resultMap.get("result_code"))) {
log.error("微信支付统一下单错误 ===> {} ", resultXml); log.error("微信支付统一下单错误 ===> {} ", resultXml);
throw new RuntimeException("微信支付统一下单错误"); throw new RuntimeException("微信支付统一下单错误");
} }
long time = System.currentTimeMillis() / 1000; long time = System.currentTimeMillis() / 1000;
Map<String,String> signInfo =new HashMap<>(); Map<String, String> signInfo = new HashMap<>();
signInfo.put("appId",appid); signInfo.put("appId", appid);
signInfo.put("timeStamp",String.valueOf(time)); signInfo.put("timeStamp", String.valueOf(time));
signInfo.put("nonceStr",WXPayUtil.generateNonceStr()); signInfo.put("nonceStr", WXPayUtil.generateNonceStr());
signInfo.put("repay_id","prepay_id=" + resultMap.get("prepay_id")); signInfo.put("repay_id", "prepay_id=" + resultMap.get("prepay_id"));
signInfo.put("signType","MD5"); signInfo.put("signType", "MD5");
//生成签名 //生成签名
Map<String, String> payInfo = new HashMap<>(); Map<String, String> payInfo = new HashMap<>();
payInfo.put("appId",appid); payInfo.put("appId", appid);
payInfo.put("timeStamp", signInfo.get("timeStamp")); payInfo.put("timeStamp", signInfo.get("timeStamp"));
payInfo.put("nonceStr", signInfo.get("nonceStr")); payInfo.put("nonceStr", signInfo.get("nonceStr"));
payInfo.put("package", signInfo.get("repay_id")); payInfo.put("package", signInfo.get("repay_id"));
...@@ -352,8 +348,8 @@ public class WeixinServiceImpl { ...@@ -352,8 +348,8 @@ public class WeixinServiceImpl {
// 此处可以写唤起支付前的业务逻辑 // 此处可以写唤起支付前的业务逻辑
// 业务逻辑结束 回传给小程序端唤起支付 // 业务逻辑结束 回传给小程序端唤起支付
return payInfo; return payInfo;
}catch (Exception e){ } catch (Exception e) {
log.error("微信支付发生异常",e); log.error("微信支付发生异常", e);
throw new ServiceException("微信支付异常"); throw new ServiceException("微信支付异常");
} }
} }
...@@ -364,9 +360,10 @@ public class WeixinServiceImpl { ...@@ -364,9 +360,10 @@ public class WeixinServiceImpl {
//处理通知参数 //处理通知参数
String body = this.readData(request); String body = this.readData(request);
log.info("wx notify receive: \n{}", body);
//验签 //验签
if(!WXPayUtil.isSignatureValid(body, key)) { if (!WXPayUtil.isSignatureValid(body, key)) {
log.error("通知验签失败"); log.error("通知验签失败");
//失败应答 //失败应答
returnMap.put("return_code", "FAIL"); returnMap.put("return_code", "FAIL");
...@@ -378,7 +375,7 @@ public class WeixinServiceImpl { ...@@ -378,7 +375,7 @@ public class WeixinServiceImpl {
//解析xml数据 //解析xml数据
Map<String, String> notifyMap = WXPayUtil.xmlToMap(body); Map<String, String> notifyMap = WXPayUtil.xmlToMap(body);
//判断通信和业务是否成功 //判断通信和业务是否成功
if(!"SUCCESS".equals(notifyMap.get("return_code")) || !"SUCCESS".equals(notifyMap.get("result_code"))) { if (!"SUCCESS".equals(notifyMap.get("return_code")) || !"SUCCESS".equals(notifyMap.get("result_code"))) {
log.error("失败"); log.error("失败");
//失败应答 //失败应答
returnMap.put("return_code", "FAIL"); returnMap.put("return_code", "FAIL");
...@@ -400,7 +397,7 @@ public class WeixinServiceImpl { ...@@ -400,7 +397,7 @@ public class WeixinServiceImpl {
// } // }
//处理订单 //处理订单
if(lock.tryLock()) { if (lock.tryLock()) {
Order order = new Order(); Order order = new Order();
order.setOrderNo(orderNo); order.setOrderNo(orderNo);
List<Order> orders = orderService.selectOrderList(order); List<Order> orders = orderService.selectOrderList(order);
...@@ -467,7 +464,7 @@ public class WeixinServiceImpl { ...@@ -467,7 +464,7 @@ public class WeixinServiceImpl {
Order order = new Order(); Order order = new Order();
order.setOrderNo(orderNo); order.setOrderNo(orderNo);
List<Order> orders = orderService.selectOrderList(order); List<Order> orders = orderService.selectOrderList(order);
if(orders.isEmpty()){ if (orders.isEmpty()) {
return "没有该订单"; return "没有该订单";
} }
...@@ -483,11 +480,11 @@ public class WeixinServiceImpl { ...@@ -483,11 +480,11 @@ public class WeixinServiceImpl {
// } // }
//处理订单 //处理订单
if(lock.tryLock()){ if (lock.tryLock()) {
try { try {
//处理重复的通知 //处理重复的通知
//接口调用的幂等性:无论接口被调用多少次,产生的结果是一致的。 //接口调用的幂等性:无论接口被调用多少次,产生的结果是一致的。
String orderStatus =order.getState(); String orderStatus = order.getState();
if (OrderStatusConstant.Unpaid.equals(orderStatus)) { if (OrderStatusConstant.Unpaid.equals(orderStatus)) {
//更新订单状态 //更新订单状态
order.setPayTime(new Date()); order.setPayTime(new Date());
...@@ -657,76 +654,76 @@ public class WeixinServiceImpl { ...@@ -657,76 +654,76 @@ public class WeixinServiceImpl {
shop1.setOrderState(1); shop1.setOrderState(1);
} }
String province = shop1.getProvince(); String province = shop1.getProvince();
if(proString.contains(province)){ if (proString.contains(province)) {
for (JSONObject provinceObject : proviceList) { for (JSONObject provinceObject : proviceList) {
if(province.equals(provinceObject.getString("value"))){ if (province.equals(provinceObject.getString("value"))) {
JSONArray cityChild = provinceObject.getJSONArray("children"); JSONArray cityChild = provinceObject.getJSONArray("children");
boolean cityboo =true; boolean cityboo = true;
for(int i=0;i<cityChild.size();i++){ for (int i = 0; i < cityChild.size(); i++) {
JSONObject city = cityChild.getJSONObject(i); JSONObject city = cityChild.getJSONObject(i);
if(shop1.getCity().equals(city.getString("value"))){ if (shop1.getCity().equals(city.getString("value"))) {
cityboo =false; cityboo = false;
JSONArray zooeObject = city.getJSONArray("children"); JSONArray zooeObject = city.getJSONArray("children");
boolean zoneBoo = true; boolean zoneBoo = true;
for(int j=0;j<zooeObject.size();j++){ for (int j = 0; j < zooeObject.size(); j++) {
JSONObject zooe = zooeObject.getJSONObject(j); JSONObject zooe = zooeObject.getJSONObject(j);
if(shop1.getZone().equals(zooe.getString("value"))){ if (shop1.getZone().equals(zooe.getString("value"))) {
zoneBoo = false; zoneBoo = false;
JSONArray shopInfos = zooe.getJSONArray("shops"); JSONArray shopInfos = zooe.getJSONArray("shops");
shopInfos.add(shop1); shopInfos.add(shop1);
ArrayList<Shop> shopList = (ArrayList<Shop>) shopInfos.toJavaList(Shop.class); ArrayList<Shop> shopList = (ArrayList<Shop>) shopInfos.toJavaList(Shop.class);
List<Shop> collect = shopList.stream().sorted((a, b) -> a.getDistance().compareTo(b.getDistance())).collect(Collectors.toList()); List<Shop> collect = shopList.stream().sorted((a, b) -> a.getDistance().compareTo(b.getDistance())).collect(Collectors.toList());
zooe.put("shops",collect); zooe.put("shops", collect);
} }
} }
if(zoneBoo){ if (zoneBoo) {
JSONObject zone =new JSONObject(); JSONObject zone = new JSONObject();
zone.put("value",shop1.getZone()); zone.put("value", shop1.getZone());
zone.put("name",JSONPath.read(areaData,String.format(zoneString,province,shop1.getCity(),shop1.getZone()))); zone.put("name", JSONPath.read(areaData, String.format(zoneString, province, shop1.getCity(), shop1.getZone())));
zooeObject.add(zone); zooeObject.add(zone);
List<Shop> shopList = new ArrayList<>(); List<Shop> shopList = new ArrayList<>();
shopList.add(shop1); shopList.add(shop1);
zone.put("shops",shopList); zone.put("shops", shopList);
} }
} }
} }
if(cityboo){ if (cityboo) {
JSONObject city = new JSONObject(); JSONObject city = new JSONObject();
city.put("value",shop1.getCity()); city.put("value", shop1.getCity());
city.put("name",JSONPath.read(areaData,String.format(cityString,province,shop1.getCity()))); city.put("name", JSONPath.read(areaData, String.format(cityString, province, shop1.getCity())));
cityChild.add(city); cityChild.add(city);
JSONObject zone =new JSONObject(); JSONObject zone = new JSONObject();
zone.put("value",shop1.getZone()); zone.put("value", shop1.getZone());
zone.put("name",JSONPath.read(areaData,String.format(zoneString,province,shop1.getCity(),shop1.getZone()))); zone.put("name", JSONPath.read(areaData, String.format(zoneString, province, shop1.getCity(), shop1.getZone())));
List<Shop> shopList = new ArrayList<>(); List<Shop> shopList = new ArrayList<>();
shopList.add(shop1); shopList.add(shop1);
zone.put("shops",shopList); zone.put("shops", shopList);
List<JSONObject> zones = new ArrayList<>(); List<JSONObject> zones = new ArrayList<>();
zones.add(zone); zones.add(zone);
city.put("children",zones); city.put("children", zones);
} }
} }
} }
}else{ } else {
proString.add(province); proString.add(province);
JSONObject provice = new JSONObject(); JSONObject provice = new JSONObject();
provice.put("value",province); provice.put("value", province);
String format = String.format(provinceString, province); String format = String.format(provinceString, province);
provice.put("name",JSONPath.read(areaData,format)); provice.put("name", JSONPath.read(areaData, format));
proviceList.add(provice); proviceList.add(provice);
JSONObject city = new JSONObject(); JSONObject city = new JSONObject();
city.put("value",shop1.getCity()); city.put("value", shop1.getCity());
city.put("name",JSONPath.read(areaData,String.format(cityString,province,shop1.getCity()))); city.put("name", JSONPath.read(areaData, String.format(cityString, province, shop1.getCity())));
List<JSONObject> citys =new ArrayList<>(); List<JSONObject> citys = new ArrayList<>();
citys.add(city); citys.add(city);
provice.put("children",citys); provice.put("children", citys);
JSONObject zone =new JSONObject(); JSONObject zone = new JSONObject();
zone.put("value",shop1.getZone()); zone.put("value", shop1.getZone());
zone.put("name",JSONPath.read(areaData,String.format(zoneString,province,shop1.getCity(),shop1.getZone()))); zone.put("name", JSONPath.read(areaData, String.format(zoneString, province, shop1.getCity(), shop1.getZone())));
List<Shop> shopList = new ArrayList<>(); List<Shop> shopList = new ArrayList<>();
shopList.add(shop1); shopList.add(shop1);
zone.put("shops", shopList); zone.put("shops", shopList);
......
...@@ -92,8 +92,10 @@ public class OrderServiceImpl implements IOrderService { ...@@ -92,8 +92,10 @@ public class OrderServiceImpl implements IOrderService {
public Order selectOrderById(Long id) { public Order selectOrderById(Long id) {
Order order = orderMapper.selectOrderById(id); Order order = orderMapper.selectOrderById(id);
order.setShop(shopMapper.selectShopById(order.getShopId())); order.setShop(shopMapper.selectShopById(order.getShopId()));
if (!StringUtils.isEmpty(order.getPickCode())) {
String pickCode = stringRedisTemplate.opsForValue().get(order.getPickCode()); String pickCode = stringRedisTemplate.opsForValue().get(order.getPickCode());
order.setPickCode(pickCode); order.setPickCode(pickCode);
}
OrderSnapshot orderSnapshot = orderSnapshotService.selectOrderSnapshotByOrderId(order.getId()); OrderSnapshot orderSnapshot = orderSnapshotService.selectOrderSnapshotByOrderId(order.getId());
String snapshot = orderSnapshot.getSnapshot(); String snapshot = orderSnapshot.getSnapshot();
List<OrderDetail> orderDetails = JSONObject.parseArray(snapshot, OrderDetail.class); List<OrderDetail> orderDetails = JSONObject.parseArray(snapshot, OrderDetail.class);
...@@ -615,8 +617,10 @@ public class OrderServiceImpl implements IOrderService { ...@@ -615,8 +617,10 @@ public class OrderServiceImpl implements IOrderService {
String waitTime = getWaitTimeByOrderId(order.getId()); String waitTime = getWaitTimeByOrderId(order.getId());
Map<String, String> map = new HashMap<>(); Map<String, String> map = new HashMap<>();
map.put("waitTime", waitTime); map.put("waitTime", waitTime);
if (StringUtils.isNotEmpty(order.getPickCode())) {
String pickCode = stringRedisTemplate.opsForValue().get(order.getPickCode()); String pickCode = stringRedisTemplate.opsForValue().get(order.getPickCode());
map.put("pickCode", pickCode); map.put("pickCode", pickCode);
}
map.put("orderNum", order.getOrderNum()); map.put("orderNum", order.getOrderNum());
map.put("state", order.getState()); map.put("state", order.getState());
return map; return map;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment