支付结果通知回调controller开发
This commit is contained in:
parent
27d43affc7
commit
8eb8ab6c1c
@ -0,0 +1,96 @@
|
||||
package net.jieyuu.controller;
|
||||
|
||||
|
||||
import com.alipay.api.AlipayApiException;
|
||||
import com.alipay.api.internal.util.AlipaySignature;
|
||||
import io.swagger.annotations.Api;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import net.jieyuu.config.AlipayConfig;
|
||||
import net.jieyuu.enums.ProductOrderPayTypeEnum;
|
||||
import net.jieyuu.service.ProductOrderService;
|
||||
import net.jieyuu.utils.JsonData;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
@Api("订单回调通知模块")
|
||||
@Controller
|
||||
@RequestMapping("/api/callback/order/v1")
|
||||
@Slf4j
|
||||
public class CallbackController {
|
||||
|
||||
@Autowired
|
||||
private ProductOrderService productOrderService;
|
||||
|
||||
// @Autowired
|
||||
// private AlipayConfig alipayConfig;
|
||||
|
||||
|
||||
/**
|
||||
* 支付宝支付回调通知 post
|
||||
*
|
||||
* @param request
|
||||
* @param response
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("alipay")
|
||||
public String alipayCallback(HttpServletRequest request, HttpServletResponse response) {
|
||||
// return productOrderService.alipayCallback();
|
||||
// 将异步通知中收到的所有参数转化为map
|
||||
Map<String, String> paramsMap = convertRequestParamsToMap(request);
|
||||
|
||||
log.info("支付宝回调通知请求:{}", paramsMap);
|
||||
|
||||
|
||||
try {
|
||||
boolean signVerified = AlipaySignature.rsaCheckV1(paramsMap, AlipayConfig.ALIPAY_PUB_KEY, AlipayConfig.CHARSET, AlipayConfig.SIGN_TYPE);
|
||||
if (signVerified) {
|
||||
JsonData jsonData = productOrderService.handlerOrderCallbackMsg(ProductOrderPayTypeEnum.ALIPAY, paramsMap);
|
||||
if (jsonData.getCode() == 0) {
|
||||
// 通知结果确认成功,不然一直通知
|
||||
// 八次都没返回success判断为交易失败
|
||||
return "success";
|
||||
}
|
||||
|
||||
}
|
||||
} catch (AlipayApiException e) {
|
||||
log.info("支付宝回调验证签名失败:异常:{}", e, paramsMap);
|
||||
}
|
||||
|
||||
return "failure";
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 将request中的参数转换成Map
|
||||
*
|
||||
* @param request
|
||||
* @return
|
||||
*/
|
||||
private static Map<String, String> convertRequestParamsToMap(HttpServletRequest request) {
|
||||
Map<String, String> paramsMap = new HashMap<>(16);
|
||||
Set<Map.Entry<String, String[]>> entrySet = request.getParameterMap().entrySet();
|
||||
|
||||
for (Map.Entry<String, String[]> entry : entrySet) {
|
||||
String name = entry.getKey();
|
||||
String[] values = entry.getValue();
|
||||
int size = values.length;
|
||||
if (size == 1) {
|
||||
paramsMap.put(name, values[0]);
|
||||
} else {
|
||||
paramsMap.put(name, "");
|
||||
}
|
||||
}
|
||||
System.out.println(paramsMap);
|
||||
return paramsMap;
|
||||
}
|
||||
|
||||
}
|
@ -1,11 +1,14 @@
|
||||
package net.jieyuu.service;
|
||||
|
||||
import net.jieyuu.enums.ProductOrderPayTypeEnum;
|
||||
import net.jieyuu.model.OrderMessage;
|
||||
import net.jieyuu.model.ProductOrderDO;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import net.jieyuu.request.ConfirmOrderRequest;
|
||||
import net.jieyuu.utils.JsonData;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 服务类
|
||||
@ -38,4 +41,14 @@ public interface ProductOrderService extends IService<ProductOrderDO> {
|
||||
* @param orderMessage
|
||||
*/
|
||||
boolean closeProductOrder(OrderMessage orderMessage);
|
||||
|
||||
/**
|
||||
* 支付结果回调通知
|
||||
*
|
||||
* @param productOrderPayTypeEnum
|
||||
* @param paramsMap
|
||||
* @return
|
||||
*/
|
||||
JsonData handlerOrderCallbackMsg(ProductOrderPayTypeEnum productOrderPayTypeEnum, Map<String, String> paramsMap);
|
||||
|
||||
}
|
||||
|
@ -35,6 +35,7 @@ import java.math.BigDecimal;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
@ -405,4 +406,17 @@ public class ProductOrderServiceImpl extends ServiceImpl<ProductOrderMapper, Pro
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 支付结果通知更新订单状态
|
||||
*
|
||||
* @param productOrderPayTypeEnum
|
||||
* @param paramsMap
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public JsonData handlerOrderCallbackMsg(ProductOrderPayTypeEnum productOrderPayTypeEnum, Map<String, String> paramsMap) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user