| | |
| | | package com.ruoyi.payment.controller; |
| | | |
| | | import com.alipay.api.AlipayApiException; |
| | | import com.alipay.api.internal.util.AlipaySignature; |
| | | import com.ruoyi.common.core.domain.R; |
| | | import com.ruoyi.common.core.web.domain.AjaxResult; |
| | | import com.ruoyi.order.api.feignClient.ChargingOrderClient; |
| | | import com.ruoyi.order.api.feignClient.OrderClient; |
| | | import com.ruoyi.payment.ali.config.AliProperties; |
| | | import com.ruoyi.payment.ali.v2.AppletPayUtil; |
| | | import com.ruoyi.payment.api.model.*; |
| | |
| | | import org.springframework.web.bind.annotation.*; |
| | | |
| | | import javax.annotation.Resource; |
| | | import javax.servlet.http.HttpServletRequest; |
| | | import javax.servlet.http.HttpServletResponse; |
| | | import java.io.PrintWriter; |
| | | import java.util.HashMap; |
| | | import java.util.Iterator; |
| | | import java.util.Map; |
| | | |
| | | /** |
| | | * @author zhibing.pu |
| | |
| | | if(null != payment){ |
| | | AliPaymentResp aliPaymentResp = new AliPaymentResp(); |
| | | aliPaymentResp.setTradeNo(payment.getTradeNo()); |
| | | aliPaymentResp.setNotifyUrl(aliProperties.getNotifyUrl()); |
| | | return R.ok(aliPaymentResp); |
| | | } |
| | | return R.ok(); |
| | |
| | | } |
| | | |
| | | |
| | | @Resource |
| | | private OrderClient orderClient; |
| | | @Resource |
| | | private ChargingOrderClient chargingOrderClient; |
| | | @ResponseBody |
| | | @PostMapping(value = "/allCallBack") |
| | | public void chargingOrderALICallback(@RequestBody AliQueryOrder aliQueryOrder, HttpServletResponse response) { |
| | | @PostMapping(value = "/callBack") |
| | | public void chargingOrderALICallback(HttpServletRequest request, HttpServletResponse response) { |
| | | try { |
| | | String out_trade_no = aliQueryOrder.getOutTradeNo(); |
| | | String transaction_id = aliQueryOrder.getTradeNo(); |
| | | String attach = aliQueryOrder.getPassbackParams(); |
| | | // AjaxResult ajaxResult = chargingOrderService.chargingOrderCallback(2, out_trade_no, transaction_id, attach); |
| | | // if (ajaxResult.isSuccess()) { |
| | | // PrintWriter writer = response.getWriter(); |
| | | // writer.println("success"); |
| | | // writer.flush(); |
| | | // writer.close(); |
| | | // } |
| | | Map<String, String> callback = alipayCallback(request); |
| | | if(null != callback){ |
| | | String out_trade_no = callback.get("out_trade_no"); |
| | | String attach = callback.get("subject"); |
| | | String total_amount = callback.get("total_amount"); |
| | | String transaction_id = callback.get("trade_no"); |
| | | String substring = out_trade_no.substring(0, 2); |
| | | switch (substring){ |
| | | //购物订单 |
| | | case "GW": |
| | | R r = orderClient.callBack(out_trade_no, transaction_id); |
| | | System.err.println("----收到购物回调"); |
| | | break; |
| | | case "HY": |
| | | orderClient.vipCallBack(out_trade_no,transaction_id); |
| | | System.err.println("----收到会员回调"); |
| | | break; |
| | | case "CD": |
| | | chargingOrderClient.chargingOrderALICallback(out_trade_no, transaction_id, attach); |
| | | System.err.println("----充电支付回调"); |
| | | break; |
| | | } |
| | | PrintWriter writer = response.getWriter(); |
| | | writer.println("success"); |
| | | writer.flush(); |
| | | writer.close(); |
| | | } |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | public Map<String, String> alipayCallback(HttpServletRequest request){ |
| | | Map<String,String> params = new HashMap<String,String>(); |
| | | Map requestParams = request.getParameterMap(); |
| | | for (Iterator iter = requestParams.keySet().iterator(); iter.hasNext();) { |
| | | String name = (String) iter.next(); |
| | | String[] values = (String[]) 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); |
| | | } |
| | | try { |
| | | boolean flag = AlipaySignature.rsaCheckV1(params, aliProperties.getAlipayPublicKey(), "UTF-8","RSA2"); |
| | | if(flag){ |
| | | Map<String, String> map = new HashMap<>(); |
| | | String out_trade_no = params.get("out_trade_no"); |
| | | String subject = params.get("subject"); |
| | | String total_amount = params.get("total_amount"); |
| | | String trade_no = params.get("trade_no"); |
| | | map.put("out_trade_no", out_trade_no);//商家订单号 |
| | | map.put("subject", subject); |
| | | map.put("total_amount", total_amount); |
| | | map.put("trade_no", trade_no);//支付宝交易号 |
| | | return map; |
| | | } |
| | | |
| | | } catch (AlipayApiException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | } |