新零售支付全家桶


主动查询订单状态

<h2>根据付款结果消息更新商品订单状态</h2> <p>编写ZfbController.java文件</p> <pre><code class="language-java">@Login @PostMapping("/updateNativeOrderStatus") @ApiOperation("更新商品订单状态") public R updateNativeOrderStatus(@RequestBody UpdateNativeOrderStatusForm form, @RequestHeader HashMap header) { ValidatorUtils.validateEntity(form); String token = header.get("token").toString(); int userId = Integer.parseInt(jwtUtils.getClaimByToken(token).getSubject()); String code = form.getCode(); OrderEntity orderEntity = new OrderEntity(); orderEntity.setUserId(userId); orderEntity.setCode(code); QueryWrapper wrapper = new QueryWrapper(orderEntity); int count = orderService.count(wrapper); if (count == 0) { return R.error("用户与订单不匹配"); } try { AlipayClient client = new DefaultAlipayClient( gateway, microApp_appId, microApp_privateKey, "json", "UTF-8", microApp_publicKey, "RSA2" ); AlipayTradeQueryRequest request = new AlipayTradeQueryRequest(); request.setBizContent("{" + "\"out_trade_no\":\"" + code + "\"," + " \"query_options\":[" + " \"TRADE_SETTLE_INFO\"" + " ]" + " }"); AlipayTradeQueryResponse response = client.execute(request); if (response.isSuccess()) { String tradeStatus = response.getTradeStatus(); if ("TRADE_SUCCESS".equals(tradeStatus) || "TRADE_FINISHED".equals(tradeStatus)) { UpdateWrapper updateWrapper = new UpdateWrapper(); updateWrapper.eq("code", code); updateWrapper.set("status", 2); updateWrapper.set("payment_type", 2); updateWrapper.set("prepay_id", response.getTradeNo()); orderService.update(updateWrapper); return R.ok("订单状态已修改"); } else { return R.ok("订单状态未修改"); } } return R.ok("订单状态未修改"); } catch (Exception e) { e.printStackTrace(); return R.error("查询支付订单失败"); } }</code></pre>

页面列表

ITEM_HTML