通知支付结果代码示例

更新时间:
2024-07-19
下载文档

通知支付结果代码示例

本章主要介绍通知支付结果的 Java SDK 代码示例。

代码示例

@RequestMapping(method = RequestMethod.POST,value = "/your/path/to/trade/notify")
public AcopayNotifyResponseModel reciveNotify(HttpServletRequest httpServletRequest) {

  AcopayNotifyResponseModel notifyResponseModel = new AcopayNotifyResponseModel();
  try {
    String json = IOUtils.toString(httpServletRequest.getInputStream(), StandardCharsets.UTF_8);
    log.info("接收翼辉支付结果异步通知:{}", json);
    Map<String,Object> params = JSONObject.parseObject(json, Map.class);
    //验证签名
    AcopaySignUtil.verifySign(params,acopayPublicKey);
    //TODO 处理后续业务
    notifyResponseModel.setStatus(NOTIFY_SUCCESS);
    notifyResponseModel.setMessage("成功");
  } catch (Exception e) {
    log.error("接收异步通知失败:{}", e.getMessage());
    notifyResponseModel.setStatus(NOTIFY_FAIL);
    notifyResponseModel.setMessage("失败");
  }
  return notifyResponseModel;
}
文档内容是否对您有所帮助?
有帮助
没帮助