| | |
| | | import com.kidgrow.common.utils.DateUtils; |
| | | import com.kidgrow.common.utils.QRCodeUtil; |
| | | import com.kidgrow.common.utils.StringUtils; |
| | | import com.kidgrow.oprationcenter.config.alipay.AlipayProperties; |
| | | import com.kidgrow.oprationcenter.alipay.AlipayProperties; |
| | | import com.kidgrow.oprationcenter.model.SaasClientPay; |
| | | import com.kidgrow.oprationcenter.service.ISaasClientPayService; |
| | | import io.swagger.annotations.Api; |
| | |
| | | @RequestMapping("alipay") |
| | | @Api(tags = "支付宝的支付controller") |
| | | public class AlipayController { |
| | | |
| | | |
| | | @Resource |
| | | private AlipayClient alipayClient; |
| | | @Resource |
| | |
| | | @PostMapping("/precreate") |
| | | public ResultBody precreate(HttpServletResponse response) throws Exception{ //商户预创建支付订单,生成二维码 |
| | | |
| | | String outTradeNo = UUID.randomUUID().toString().replaceAll("_", ""); |
| | | String outTradeNo = UUID.randomUUID().toString().replaceAll("-", ""); |
| | | QueryWrapper queryWrapper = new QueryWrapper(); |
| | | queryWrapper.eq("dia_id","1"); |
| | | queryWrapper.eq("pay_status",0); |
| | |
| | | java.security.Security.addProvider( |
| | | new org.bouncycastle.jce.provider.BouncyCastleProvider() |
| | | ); |
| | | request.setNotifyUrl(alipayProperties.getNotifyUrl()); |
| | | request.setReturnUrl(alipayProperties.getReturnUrl()); |
| | | AlipayTradePrecreateResponse alipayTradePrecreateResponse=alipayClient.execute(request); |
| | | if (StringUtils.isBlank(alipayTradePrecreateResponse.getQrCode())) { |
| | | return ResultBody.failed().data("生成二维码失败"); |
| | | } |
| | | String content=alipayTradePrecreateResponse.getQrCode(); |
| | | String base64 = QRCodeUtil.creatRrCode(content, 200, 200, 0); |
| | | String base64 = QRCodeUtil.creatRrCode(content, 200, 200, 0).replaceAll("\n","").replaceAll("\r",""); |
| | | System.out.println(base64); |
| | | return ResultBody.ok().data(base64); |
| | | } |
| | | //数据封装 |
| | | public SaasClientPay fengData(AlipayTradePrecreateModel model){ |
| | | SaasClientPay saasClientPay = new SaasClientPay(); |
| | | saasClientPay.setCreateHospitalDepartment(""); |
| | | saasClientPay.setCreateHospitalDepartid(""); |
| | | saasClientPay.setCreateHospitalId(Long.valueOf(1L)); |
| | | saasClientPay.setPayPrice(1); |
| | | saasClientPay.setOutTradeNo(model.getOutTradeNo()); |
| | | saasClientPay.setPayStatus(0); |
| | | saasClientPay.setPayMethod(1); |
| | | saasClientPay.setDiaId("1"); |
| | | saasClientPay.setId( UUID.randomUUID().toString().replaceAll("_", "")); |
| | | saasClientPay.setId( UUID.randomUUID().toString().replaceAll("-", "")); |
| | | saasClientPay.setCreateTime(new Date()); |
| | | saasClientPay.setCreateUserId(Long.valueOf(1L)); |
| | | saasClientPay.setCreateUserName(""); |
| | | return saasClientPay; |
| | | } |
| | | @ApiOperation(value = "取消订单,支付超时、支付结果未知是可撤销,超过24小时不可撤销-------暂时没有配置") |
| | |
| | | public ResultBody cancel() throws Exception{ //取消订单,支付超时、支付结果未知是可撤销,超过24小时不可撤销 |
| | | AlipayTradeCancelModel model=new AlipayTradeCancelModel(); |
| | | model.setOutTradeNo("300"); |
| | | |
| | | |
| | | AlipayTradeCancelRequest request=new AlipayTradeCancelRequest(); |
| | | request.setBizModel(model); |
| | | |
| | | |
| | | AlipayTradeCancelResponse response=alipayClient.execute(request); |
| | | return ResultBody.ok().data(response.getBody()); |
| | | } |
| | | |
| | | @ApiOperation(value = "trade_success状态下异步通知接口,端口异常的接口") |
| | | @PostMapping("/notify") |
| | | public ResultBody notify(HttpServletRequest request) throws Exception{ //trade_success状态下异步通知接口 |
| | | public String notify(HttpServletRequest request) throws Exception{ //trade_success状态下异步通知接口 |
| | | if (check(request.getParameterMap())){ |
| | | System.out.println(request.getParameter("trade_status")); |
| | | Map<String, String> requestMap = this.getRequestMap(request.getParameterMap()); |
| | | log.error("eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee"); |
| | | log.error(request.toString()); |
| | | log.error(requestMap.toString()); |
| | | log.error("eeeeeeeeeeeeeeeewwwwwwwwwwww:"); |
| | | if(requestMap.get("trade_status").equals("TRADE_SUCCESS")){ |
| | | log.error("wwwwwwwwwww"); |
| | | } |
| | | log.error("eeeeeeeeeeeeeeeeeeeeeeeeeeeeeee"); |
| | | System.out.println("异步通知 "+ Instant.now()); |
| | | }else { |
| | | System.out.println("验签失败"); |
| | | return "fail"; |
| | | } |
| | | return ResultBody.ok().data("订单失败"); |
| | | return "success"; |
| | | } |
| | | @ApiOperation(value = "订单支付成功后同步返回地址") |
| | | @PostMapping("/return") |
| | | public ResultBody returnUrl(HttpServletRequest request, Map<String,Object> map) throws Exception{ //订单支付成功后同步返回地址 |
| | | public ResultBody returnUrl(HttpServletRequest request,Map<String,Object> map) throws Exception{ //订单支付成功后同步返回地址 |
| | | if (check(request.getParameterMap())){ |
| | | Map<String, String> requestMap = this.getRequestMap(request.getParameterMap()); |
| | | log.error("wwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwww"); |
| | |
| | | return ResultBody.failed().data("false"); |
| | | } |
| | | } |
| | | private Map<String,String> getRequestMap(Map<String,String[]> requestParams){ |
| | | Map<String,String> params = new HashMap<>(); |
| | | 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); |
| | | System.out.println(name+" ==> "+valueStr); |
| | | } |
| | | return params; |
| | | } |
| | | private Map<String,String> getRequestMap(Map<String,String[]> requestParams){ |
| | | Map<String,String> params = new HashMap<>(); |
| | | 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); |
| | | System.out.println(name+" ==> "+valueStr); |
| | | } |
| | | return params; |
| | | } |
| | | private boolean check(Map<String,String[]> requestParams) throws Exception{ //对return、notify参数进行验签 |
| | | Map<String, String> requestMap = this.getRequestMap(requestParams); |
| | | return AlipaySignature.rsaCheckV1(requestMap, alipayProperties.getAlipayPublicKey(), |