接收付款通知消息
<p>编写UnionPayController.java</p>
<pre><code class="language-java">@RequestMapping("/recvBackResponse")
@ApiOperation("接收银联付款通知")
public void recvBackResponse(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;
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();
value = new String(value.getBytes("UTF-8"), "UTF-8");
valideData.put(key, value);
}
}
//重要!验证签名前不要修改reqParam中的键值对的内容,否则会验签不过
if (!acpService.validate(valideData, "UTF-8")) {
//验签失败,需解决验签问题
System.out.println("签名验证失败");
response.setCharacterEncoding("UTF-8");
Writer writer = response.getWriter();
writer.write("签名验证失败");
writer.close();
} 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);
}
response.setCharacterEncoding("UTF-8");
Writer writer = response.getWriter();
writer.write("ok");
writer.close();
}
}
</code></pre>