主动查询付款结果
<h3>封装查询支付结果的WEB方法</h3>
<p>编写ZfbController.java代码</p>
<pre><code class="language-java">@Login
@PostMapping("/updateOrderStatus")
@ApiOperation("更新商品订单状态")
public R updateOrderStatus(@RequestBody UpdateOrderStatusForm form, @RequestHeader HashMap header) {
ValidatorUtils.validateEntity(form);
String token = header.get("token").toString();
int userId = Integer.parseInt(jwtUtils.getClaimByToken(token).getSubject());
int orderId = form.getOrderId();
OrderEntity orderEntity = new OrderEntity();
orderEntity.setUserId(userId);
orderEntity.setId(orderId);
QueryWrapper wrapper = new QueryWrapper(orderEntity);
int count = orderService.count(wrapper);
if (count == 0) {
return R.error("用户与订单不匹配");
}
orderEntity = orderService.getOne(wrapper);
String code = orderEntity.getCode();
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>
<h3>发起页面刷新请求</h3>
<p>编写OrderActivity.java代码</p>
<pre><code class="language-javascript">@Override
protected void onResume() {
super.onResume();
OrderActivity.this.runOnUiThread(new Runnable() {
@Override
public void run() {
orderView.loadUrl("file:///android_asset/order.html");
}
});
}</code></pre>