JAVA全系列 教程
3762个小节阅读:7094.9k
目录
C语言快速入门
JAVA全系列 教程
面向对象的程序设计语言
Python全系列 教程
Python3.x版本,未来主流的版本
人工智能 教程
顺势而为,AI创新未来
大厂算法 教程
算法,程序员自我提升必经之路
C++ 教程
一门通用计算机编程语言
微服务 教程
目前业界流行的框架组合
web前端全系列 教程
通向WEB技术世界的钥匙
大数据全系列 教程
站在云端操控万千数据
AIGC全能工具班
A A
White Night
由于回调方法需要让支付宝服务器调用,而我们的项目只能在内网访问,所以我们需要搭建内网穿透服务,让外部可以访问订单api。
natapp -authtoken=生成的令牌
。启动natapp。在支付的时候,会报序列化Map异常,这是因为支付消费者在调用支付生产者验签时,会传入Request对象中的所有参数的Map,这个Map只能查询,不能修改键值对,而FastJson2在序列化Map时,会对键值对进行修改,所以会抛出异常,解决方法如下:
新建一个Map,将参数Map中的数据传入新Map中,构造parameterMap时传入新Map即可。
xxxxxxxxxx
/**
* 支付成功的回调方法,用户扫码支付后支付宝调用的
* @param request
* @return
*/
@PostMapping("/success/notify")
public BaseResult successNotify(HttpServletRequest request){
// 1.验签
Map<String, String[]> parameterMap = request.getParameterMap();
// 新Map
Map<String, String[]> newMap = new HashMap();
newMap.putAll(parameterMap);
Map<String, Object> paramMap = new HashMap();
paramMap.put("requestParameterMap",newMap);
zfbPayService.checkSign(paramMap);
String trade_status = request.getParameter("trade_status");// 订单状态
String out_trade_no = request.getParameter("out_trade_no");// 订单编号
// 如果支付成功
if (trade_status.equals("TRADE_SUCCESS")){
// 2.修改订单状态
Orders orders = ordersService.findById(out_trade_no);
orders.setStatus(2); // 订单状态为已付款
orders.setPaymentType(2);// 支付宝支付
orders.setPaymentTime(new Date());
ordersService.update(orders);
// 3.添加交易记录
Payment payment = new Payment();
payment.setOrderId(out_trade_no); // 订单编号
payment.setTransactionId(out_trade_no); // 交易号
payment.setTradeType("支付宝支付"); // 交易类型
payment.setTradeState(trade_status); // 交易状态
payment.setPayerTotal(orders.getPayment()); // 付款金额
payment.setContent(JSON.toJSONString(request.getParameterMap())); // 支付详情
payment.setCreateTime(new Date()); // 支付时间
zfbPayService.addPayment(payment);
}
return BaseResult.ok();
}