| | |
| | | package com.sandu.ximon.admin.controller; |
| | | |
| | | import com.alipay.api.AlipayClient; |
| | | import com.alipay.api.DefaultAlipayClient; |
| | | import com.alipay.api.domain.AlipayTradeWapPayModel; |
| | | import com.alipay.api.request.AlipayTradeWapPayRequest; |
| | | import com.sandu.common.domain.ResponseVO; |
| | | import com.sandu.common.execption.BusinessException; |
| | | import com.sandu.common.util.ResponseUtil; |
| | | import com.sandu.ximon.admin.config.AlipayConfig; |
| | | import com.sandu.ximon.admin.param.PayParam; |
| | | import com.sandu.ximon.admin.pay.alipay.UsrAlipayConfigService; |
| | | import com.sandu.ximon.admin.pay.wx.WxFastPayService; |
| | | import com.sandu.ximon.admin.service.C3ChargingService; |
| | | import com.sandu.ximon.admin.service.C3mOrderService; |
| | | import com.sandu.ximon.admin.utils.AliPayUtils; |
| | | import com.sandu.ximon.admin.utils.ConfigCheckUtils; |
| | | import com.sandu.ximon.dao.domain.AliConfigEntity; |
| | | import com.sandu.ximon.dao.domain.C3mCharging; |
| | | import com.sandu.ximon.dao.domain.C3mOrder; |
| | | import com.sandu.ximon.dao.enums.OrderType; |
| | | import lombok.AllArgsConstructor; |
| | | import org.springframework.web.bind.annotation.PostMapping; |
| | | import org.springframework.web.bind.annotation.RequestBody; |
| | | import org.springframework.web.bind.annotation.RequestMapping; |
| | | import org.springframework.web.bind.annotation.RestController; |
| | | |
| | | import java.util.HashMap; |
| | | import javax.servlet.http.HttpServletResponse; |
| | | import java.io.IOException; |
| | | import java.util.Date; |
| | | import java.util.Map; |
| | | import java.util.SortedMap; |
| | | |
| | | /** |
| | | * @Author liuhaonan |
| | |
| | | |
| | | private final C3mOrderService c3mOrderService; |
| | | private final C3ChargingService c3mService; |
| | | private final UsrAlipayConfigService alipayConfigService; |
| | | private final WxFastPayService wxPayService; |
| | | |
| | | |
| | | /** |
| | | * 退款 |
| | | * |
| | | * @return |
| | | */ |
| | | @PostMapping("/refond") |
| | |
| | | */ |
| | | @PostMapping("/advancePay") |
| | | public ResponseVO<Object> advancePayOrder(@RequestBody PayParam param) { |
| | | if (param.getTotalAmount() == 0d) { |
| | | throw new BusinessException("金额不能为0"); |
| | | if (param.getTotalAmount() < 0) { |
| | | throw new BusinessException("金额必须大于0"); |
| | | } |
| | | // C3充电桩实体 |
| | | C3mCharging c3m = c3mService.getC3mByPoleId(param.getPoleId()); |
| | | if (null == c3m) { |
| | | throw new BusinessException("未找到当前充电桩"); |
| | | } |
| | | C3mOrder c3mOrderEntity = c3mOrderService.advancePayOrder(param.getPoleId(), c3m, param.getOrderType() |
| | | C3mOrder c3mOrderEntity = c3mOrderService.advancePayOrder(param.getPoleId(), c3m, "wxpay" |
| | | , param.getTotalAmount(), param.getSubscribeChargingCapacity()); |
| | | if (null == c3mOrderEntity) { |
| | | throw new BusinessException("该充电桩正被使用!"); |
| | |
| | | // return R.ok().put("outTradeNo",c3mOrderEntity.getOutTradeNo()) |
| | | // .put("totalAmount",totalAmount); |
| | | |
| | | Map map=new HashMap(); |
| | | map.put("outTradeNo",c3mOrderEntity.getOutTradeNo()); |
| | | map.put("totalAmount",param.getTotalAmount()); |
| | | return ResponseUtil.success(map); |
| | | param.setOutTradeNo(c3mOrderEntity.getOutTradeNo()); |
| | | param.setTotalAmount(c3mOrderEntity.getTotalAmount()); |
| | | String s = WxFastPayService.parseWxAmount(param.getTotalAmount().toString()); |
| | | SortedMap<Object, Object> result = wxPayService.miniAppPay("扫码充电支付(C3充电桩)", param.getOutTradeNo(),Integer.valueOf(s) , param.getPoleId()); |
| | | return ResponseUtil.success(result); |
| | | } |
| | | |
| | | |
| | | @PostMapping("/aliPay") |
| | | public ResponseVO<Object> c3AliPay(@RequestBody PayParam param, HttpServletResponse response) { |
| | | // 商户订单号,商户网站订单系统中唯一订单号,必填 |
| | | String out_trade_no = param.getOutTradeNo(); |
| | | System.out.println("订单号:" + out_trade_no); |
| | | // 订单名称,必填 |
| | | String subject = "扫码充电支付(C3充电桩)"; |
| | | // 付款金额,必填,单位为元,精确到小数点后两位,取值范围[0.01,100000000] |
| | | String total_amount = param.getTotalAmount().toString(); |
| | | // 商品描述,可空 |
| | | String body = "请勿付款,测试用"; |
| | | // 超时时间 可空 |
| | | String timeout_express = "5m"; |
| | | // 销售产品码 必填 |
| | | String product_code = "QUICK_WAP_WAY"; |
| | | /**********************/ |
| | | AliConfigEntity alipayConfigEntity = alipayConfigService.getConfigByPoleId(param.getPoleId()); |
| | | String checkStr = ConfigCheckUtils.checkAlipayConfig(alipayConfigEntity); |
| | | if (checkStr != null) { |
| | | try { |
| | | response.getWriter().write(checkStr); |
| | | return ResponseUtil.fail("支付完成失败"); |
| | | } catch (IOException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | //调用RSA签名方式 |
| | | AlipayClient client = new DefaultAlipayClient(AlipayConfig.gatewayUrl, alipayConfigEntity.getAppId(), alipayConfigEntity.getPrivateKey(), AlipayConfig.format, AlipayConfig.charset, alipayConfigEntity.getPublicKey(), AlipayConfig.sign_type); |
| | | AlipayTradeWapPayRequest alipay_request = new AlipayTradeWapPayRequest(); |
| | | |
| | | // 封装请求支付信息 |
| | | AlipayTradeWapPayModel model = new AlipayTradeWapPayModel(); |
| | | model.setOutTradeNo(out_trade_no); |
| | | model.setSubject(subject); |
| | | model.setTotalAmount(total_amount); |
| | | model.setBody(body); |
| | | model.setTimeoutExpress(timeout_express); |
| | | model.setProductCode(product_code); |
| | | model.setQuitUrl(C3mOrder.REQUEST_URL + param.getPoleId() + "/" + new Date().getTime()); |
| | | alipay_request.setBizModel(model); |
| | | // 设置异步通知地址 |
| | | alipay_request.setNotifyUrl(C3mOrder.REQUEST_URL + param.getPoleId() + "/" + new Date().getTime()); |
| | | // 设置同步地址 |
| | | alipay_request.setReturnUrl(C3mOrder.REQUEST_URL + param.getPoleId() + "/" + new Date().getTime()); |
| | | |
| | | // form表单生产 |
| | | String form = ""; |
| | | try { |
| | | // 调用SDK生成表单 |
| | | form = client.pageExecute(alipay_request).getBody(); |
| | | response.setContentType("text/html;charset=" + AlipayConfig.charset); |
| | | response.getWriter().write(form);//直接将完整的表单html输出到页面 |
| | | response.getWriter().flush(); |
| | | response.getWriter().close(); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | return ResponseUtil.success("支付完成"); |
| | | } |
| | | |
| | | // @RequestMapping("/wxpay") |
| | | // public ResponseVO<Object> c3Wxpay(@RequestBody PayParam param) { |
| | | // |
| | | // //String result = wxPayService.miniAppPay(outTradeNo, totalAmount, streetlightId); |
| | | // SortedMap<Object, Object> result = wxPayService.appPay("扫码充电支付(C3充电桩)", param.getOutTradeNo(), param.getWxPayTotalAmount(), param.getPoleId(),c3mOrderEntity); |
| | | // |
| | | // return ResponseUtil.success(result); |
| | | // } |
| | | |
| | | |
| | | @RequestMapping("/queryOrder") |
| | | public ResponseVO<Object> queryOrder(@RequestBody PayParam param) { |
| | | if (param.getOrderId() == null) { |
| | | throw new BusinessException("请输入正确的订单id"); |
| | | } |
| | | C3mOrder order = c3mOrderService.getById(param.getOrderId()); |
| | | if (order == null) { |
| | | throw new BusinessException("订单不存在"); |
| | | } |
| | | if ((OrderType.ALIPAY.getCode()).equals(order.getOrderType())) { |
| | | return ResponseUtil.success(AliPayUtils.alipayQuery(order.getOutTradeNo(), param.getPoleId())); |
| | | } else if ((OrderType.WXPAY.getCode()).equals(order.getOrderType())) { |
| | | return ResponseUtil.success(wxPayService.WxOrderQuery(param.getPoleId(), order.getOutTradeNo())); |
| | | } else { |
| | | return ResponseUtil.success("支付方式异常"); |
| | | } |
| | | |
| | | } |
| | | |
| | | } |