工商银行支付接口-处理工行支付成功后的消息通知

由于工行的支付接口目前是没有向B2B商户提供按订单号查询订单状态的,因此处理订单成功支付后的消息就显得非常重要了,以下为鲁炬在做银行支付项目时处理工行订单支付成功通知的核心代码。

  /**
   * 处理工行支付成功通知
   */
  public void notifyDate(String notifyDataBase64, String signMsg, String merVAR, String realPath) {
    String encoding = "gbk";
    log.debug("接收工行通知信息原文:notifyData:" + notifyDataBase64);
    log.debug("接收工行通知信息原文:signMsg:" + signMsg);
    log.debug("接收工行通知信息原文:merVAR:" + merVAR);
    byte[] notifyDataBytes = null;
    String notifyData = null;
    try {
      notifyDataBytes = ReturnValue.base64dec(notifyDataBase64.getBytes(encoding));
      notifyData = new String(notifyDataBytes, encoding);
      log.debug("接收工行通知信息:notifyData:base64解码后:" + notifyData);
    } catch(UnsupportedEncodingException e) {
      log.error("工行解析通知内容出错:", e);
      throw new RuntimeException(e);
    }
    String dir = realPath + "/resources/files/bank/icbc/crt/";
    //获取工行证书
    byte[] bCert = null;
    try {
      FileInputStream fis = new FileInputStream(dir + "admin.crt");
      bCert = new byte[fis.available()];
      fis.read(bCert);
      fis.close();
    } catch(IOException e) {
      log.error("读取admin.crt,文件出错:", e);
      throw new RuntimeException(e);
    }
    byte[] bSign = cn.com.infosec.icbc.ReturnValue.base64dec((signMsg.getBytes()));
    byte[] bSrc = notifyDataBytes;
    //开始验签
    int recode = -1;
    try {
      recode = cn.com.infosec.icbc.ReturnValue.verifySign(bSrc, bSrc.length, bCert, bSign);
    } catch(Exception e) {
      log.error("验签出错:", e);
      throw new RuntimeException(e);
    }
    if(recode != 0) {
      log.debug("工行验签失败验证返回码:" + recode);
      return;
    }
    log.debug("工行验签成功,开始解析通知内容");
    //解析通知内容 : 订单号、是否支付成功、金额
    //notifyData
    XmlParser xmlParser = new XmlParser(new ByteArrayInputStream(notifyDataBytes));
    String orderId = xmlParser.getElementText("/B2CRes/orderInfo/subOrderInfoList/subOrderInfo/orderid");
    String amount = xmlParser.getElementText("/B2CRes/orderInfo/subOrderInfoList/subOrderInfo/amount");
    String tranStat = xmlParser.getElementText("/B2CRes/bank/tranStat");
    log.debug("工行订单支付成功通知: 订单号:" + orderId + " 支付状态:" + tranStat + " 金额:" + amount);
    if(!"1".equals(tranStat)) {
      log.debug("订单状态为未支付成功,返回");
      return;
    }
    //查询订单信息
    ExamOrder examOrder = this.examOrderService.queryExamOrderByOrderNum(orderId);
    int examOrderMoney = (new Double(examOrder.getMoney() * 100)).intValue();
    if(!amount.equals(Integer.valueOf(examOrderMoney).toString())) {
      log.debug("实际支付订单金额与应付金额不等,返回");
      return;
    }
    //更新订单状态为已结算
    try {
      log.debug("更新订单" + orderId + "状态为已结算");
      this.examOrderService.updateSuccessOrder(orderId);
    } catch(Exception e) {
      log.error("更新订单状态为已结算出错", e);
      throw new RuntimeException(e);
    }
  }


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
根据提供的引用内容,以下是Java实现工商银行下单支付的示例代码: ```java import java.io.BufferedReader; import java.io.InputStreamReader; import java.io.OutputStream; import java.net.HttpURLConnection; import java.net.URL; public class ICBCPayment { public static void main(String[] args) { try { // 设置请求URL URL url = new URL("https://api.icbc.com.cn/api/ICBCAPI/order/pay"); // 创建连接 HttpURLConnection connection = (HttpURLConnection) url.openConnection(); connection.setRequestMethod("POST"); connection.setRequestProperty("Content-Type", "application/json"); connection.setDoOutput(true); // 设置请求参数 String requestData = "{\"orderNo\":\"123456789\",\"amount\":100.00,\"payType\":\"no_credit\"}"; // 发送请求 OutputStream outputStream = connection.getOutputStream(); outputStream.write(requestData.getBytes()); outputStream.flush(); // 获取响应 int responseCode = connection.getResponseCode(); BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream())); String line; StringBuilder response = new StringBuilder(); while ((line = reader.readLine()) != null) { response.append(line); } reader.close(); // 处理响应 if (responseCode == 200) { System.out.println("下单支付成功"); System.out.println("响应数据:" + response.toString()); } else { System.out.println("下单支付失败"); System.out.println("响应数据:" + response.toString()); } // 关闭连接 connection.disconnect(); } catch (Exception e) { e.printStackTrace(); } } } ``` 请注意,以上代码仅为示例,实际使用时需要根据具体的业务需求进行适当的修改和调整。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值