Commit 2e51d49a by weijiguang

下单时校验订单中sku数量

parent 2ba99dc6
......@@ -8,6 +8,7 @@ import com.soss.common.utils.StringUtils;
import com.soss.framework.web.service.TokenService;
import com.soss.framework.web.service.WeixinServiceImpl;
import com.soss.system.domain.Customer;
import com.soss.system.domain.Order;
import com.soss.system.domain.Shop;
import com.soss.system.service.ICustomerService;
import com.soss.system.service.impl.AppServiceImpl;
......@@ -87,6 +88,16 @@ public class WeixinController {
return weixinService.wxNotify(request);
}
/**
* 测试支付通知
* 微信支付通过支付通知接口将用户支付成功消息通知给商户
*/
@PostMapping("/native/notify/test")
public String wxNotifyTest(@RequestBody Order order) throws Exception {
System.out.println("微信发送的回调");
return weixinService.wxNotifyTest(order);
}
@RequestMapping("/getShop")
public AjaxResult getShop(HttpServletRequest request, @RequestParam(required = false) String lng, @RequestParam(required = false) String lat) {
......
......@@ -435,6 +435,75 @@ public class WeixinServiceImpl {
return returnXml;
}
public String wxNotifyTest(Order orderPo) throws Exception {
// Map<String, String> returnMap = new HashMap<>();//应答对象
//处理通知参数
// String body = this.readData(request);
// //验签
// if(!WXPayUtil.isSignatureValid(body, key)) {
// log.error("通知验签失败");
// //失败应答
// returnMap.put("return_code", "FAIL");
// returnMap.put("return_msg", "验签失败");
// String returnXml = WXPayUtil.mapToXml(returnMap);
// return returnXml;
// }
//解析xml数据
// Map<String, String> notifyMap = WXPayUtil.xmlToMap(body);
// //判断通信和业务是否成功
// if(!"SUCCESS".equals(notifyMap.get("return_code")) || !"SUCCESS".equals(notifyMap.get("result_code"))) {
// log.error("失败");
// //失败应答
// returnMap.put("return_code", "FAIL");
// returnMap.put("return_msg", "失败");
// String returnXml = WXPayUtil.mapToXml(returnMap);
// return returnXml;
// }
//获取商户订单号
// String orderNo = notifyMap.get("out_trade_no");
Order order = new Order();
order.setOrderNo(orderPo.getOrderNo());
List<Order> orders = orderService.selectOrderList(order);
if(orders.isEmpty()){
return "没有该订单";
}
order = orders.get(0);
//并校验返回的订单金额是否与商户侧的订单金额一致
// if (order1 != null && order1.get() != Long.parseLong(notifyMap.get("total_fee"))) {
// log.error("金额校验失败");
// //失败应答
// returnMap.put("return_code", "FAIL");
// returnMap.put("return_msg", "金额校验失败");
// String returnXml = WXPayUtil.mapToXml(returnMap);
// return returnXml;
// }
//处理订单
if(lock.tryLock()){
try {
//处理重复的通知
//接口调用的幂等性:无论接口被调用多少次,产生的结果是一致的。
String orderStatus =order.getState();
if (OrderStatusConstant.Unpaid.equals(orderStatus)) {
//更新订单状态
order.setPayTime(new Date());
order.setState(OrderStatusConstant.Paid);
order.setPickCode(generatePickCode(order));
orderService.updateOrder(order);
}
} finally {
//要主动释放锁
lock.unlock();
}
}
return "支付成功,已应答";
}
public String generatePickCode(Order order) {
String uid = UUID.randomUUID().toString();
stringRedisTemplate.opsForValue().set(uid, String.valueOf(order.getId()));
......
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