/*生成二维码/
@PostMapping(value = “getQRCode”)
@RequestLog(“支付宝支付”)
@ApiOperation(“支付宝支付”)
@AnonAccess
public String qrCode(@Validated @RequestBody SysMemberRecordVo sysMemberRecordVo) throws AlipayApiException {
AlipayClient alipayClient = new DefaultAlipayClient(AliConstants.serverUrl,AliConstants.appId,AliConstants.privateKey,AliConstants.format,AliConstants.charset,AliConstants.alipayPublicKey,AliConstants.signType);
AlipayTradePagePayRequest request = new AlipayTradePagePayRequest();
//异步接收地址,仅支持http/https,公网可访问
request.setNotifyUrl(“xxx”);
//同步跳转地址,仅支持http/https就是前端界面地址,随便放一个
request.setReturnUrl(“xxxx”);
/必传参数/
JSONObject bizContent = new JSONObject();
String out_trade_no=getCurrentTimeStamp();
//商户订单号,商家自定义,保持唯一性
bizContent.put(“out_trade_no”, out_trade_no);
//支付金额,最小值0.01元
bizContent.put(“total_amount”, sysMemberRecordVo.getType().getValue());
//订单标题,不可使用特殊符号
bizContent.put(“subject”, sysMemberRecordVo.getType().getLabel());
//电脑网站支付场景固定传值FAST_INSTANT_TRADE_PAY
bizContent.put(“product_code”, “FAST_INSTANT_TRADE_PAY”);
request.setBizContent(bizContent.toString());
AlipayTradePagePayResponse response = alipayClient.pageExecute(request);
String result ="";
if(response.isSuccess()){
result = response.getBody();
//插入订单号和支付状态在本地数据库表(根据自己业务编写)
sysMemberRecordVo.setOutTradeNo(Long.valueOf(out_trade_no));
sysMemberRecordVo.setPayState((long)0);
sysMemberRecordFacade.createSysMemberRecord(sysMemberRecordVo);
System.out.println(response+"调用成功");
} else {
System.out.println(response+"调用失败");
}
return result;
}
@PostMapping (value = "/alinotify")
@RequestLog("支付宝支付回调")
@ApiOperation("支付宝支付回调")
@AnonAccess
public ResponseEntity<Object> alinotify(HttpServletRequest request){
String code =sysMemberRecordFacade.alinotify(request);
return new ResponseEntity<>(code, HttpStatus.OK);
}
@Override
public String alinotify(HttpServletRequest request) {
String code =“fail”;
Map<String, String> params = new HashMap<>();
Map<String, String[]> requestParams = request.getParameterMap();
for (String name : requestParams.keySet()) {
String[] values = requestParams.get(name);
String valueStr = “”;
for (int i = 0; i < values.length; i++) {
valueStr = (i == values.length - 1) ? valueStr + values[i]
: valueStr + values[i] + “,”;
}
params.put(name, valueStr);
}
Long out_trade_no=Long.valueOf(params.get(“out_trade_no”));
//根据订单号编写自己有业务
code= “OK”;
return code;
}
//生成订单号
public static String getCurrentTimeStamp(){
SimpleDateFormat sdf = new SimpleDateFormat(“yyyyMMddHHmmss”);
return sdf.format(new Date());
}
前端代码:
data是你要传的参数
response 是返回结果可自行做判断
memberRecord.getQRCode(data)
.then(response => {
console.log(response)
document.querySelector(‘body’).innerHTML = response
document.forms[0].submit()
})