创建前端回调方法
<p>编写UnionPayController.java</p>
<pre><code class="language-java">@RequestMapping("/recvFrontResponse")
@ApiOperation("接收银联页面跳转请求")
public void recvFrontResponse(HttpServletRequest request, HttpServletResponse response) throws Exception {
request.setCharacterEncoding("UTF-8");
HashMap<String, String> reqParam = new HashMap<>();
Enumeration<String> enumeration = request.getParameterNames();
while (enumeration.hasMoreElements()) {
String name = enumeration.nextElement();
String value = request.getParameter(name);
reqParam.put(name, value);
}
Map<String, String> valideData = null;
String htmlCode = null;
if (!reqParam.isEmpty()) {
Iterator<Map.Entry<String, String>> it = reqParam.entrySet().iterator();
valideData = new HashMap<String, String>(reqParam.size());
while (it.hasNext()) {
Map.Entry<String, String> e = it.next();
String key = (String) e.getKey();
String value = (String) e.getValue();
valideData.put(key, value);
}
}
if (acpService.validate(valideData, "UTF-8")) {
System.out.println("前端回调签名验证成功");
String respCode = request.getParameter("respCode");
String queryId = request.getParameter("queryId");
String code = request.getParameter("orderId");
if ("00".equals(respCode)) {
UpdateWrapper updateWrapper = new UpdateWrapper();
updateWrapper.eq("code", code);
updateWrapper.set("status", 2);
updateWrapper.set("payment_type", 3);
updateWrapper.set("prepay_id", queryId);
orderService.update(updateWrapper);
}
}
response.sendRedirect(orderUrl);
}</code></pre>