前端跳转回调
<p>编写UnionPayController.java文件</p>
<pre><code class="language-java">@RequestMapping("/recvWapFrontResponse")
@ApiOperation("接收银联页面跳转请求")
public void recvWapFrontResponse(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")) {
htmlCode = "<html><body><h1>数据签名错误<h1></body></html>";
} else {
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);
htmlCode = "<html><body><h1>商户已经接收到付款成功通知<h1></body></html>";
} else {
htmlCode = "<html><body><h1>付款失败<h1></body></html>";
}
response.setCharacterEncoding("UTF-8");
Writer writer = response.getWriter();
writer.write(htmlCode);
writer.close();
}
}
</code></pre>