| | |
| | | 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 cn.hutool.core.map.MapUtil; |
| | | import com.sandu.common.domain.ResponseVO; |
| | | import com.sandu.common.execption.BusinessException; |
| | | import com.sandu.common.object.BaseConditionVO; |
| | | import com.sandu.common.security.annotation.AnonymousAccess; |
| | | 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.C3mChargingChargeService; |
| | | 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 me.chanjar.weixin.common.error.WxErrorException; |
| | | import org.springframework.web.bind.annotation.*; |
| | | |
| | | import javax.servlet.http.HttpServletResponse; |
| | | import java.io.IOException; |
| | | import java.util.Date; |
| | | import java.util.HashMap; |
| | | import java.util.Map; |
| | | import javax.servlet.http.HttpServletRequest; |
| | | import java.math.BigDecimal; |
| | | import java.util.SortedMap; |
| | | |
| | | /** |
| | |
| | | private final C3ChargingService c3mService; |
| | | private final UsrAlipayConfigService alipayConfigService; |
| | | private final WxFastPayService wxPayService; |
| | | private final C3mChargingChargeService c3mChargingChargeService; |
| | | |
| | | |
| | | /** |
| | |
| | | * @return |
| | | */ |
| | | @PostMapping("/refond") |
| | | public ResponseVO<Object> refond(@RequestBody Map params) { |
| | | // c3mOrderService.orderRefund( (String)params.get("outTradeNo"), |
| | | // (Double)params.get("refundAmount")); |
| | | return ResponseUtil.success(c3mOrderService.orderRefund((String) params.get("outTradeNo"), |
| | | (Double) params.get("refundAmount"))); |
| | | |
| | | public ResponseVO<Object> refond(@RequestBody PayParam params) { |
| | | if (params.getOutTradeNo().isEmpty() || params.getOutTradeNo() == null) { |
| | | throw new BusinessException("退款参数不能为空"); |
| | | } |
| | | return ResponseUtil.success(c3mOrderService.orderRefund(params.getOutTradeNo())); |
| | | } |
| | | |
| | | /** |
| | |
| | | * |
| | | * @return |
| | | */ |
| | | @AnonymousAccess |
| | | @PostMapping("/advancePay") |
| | | public ResponseVO<Object> advancePayOrder(@RequestBody PayParam param) { |
| | | if (param.getTotalAmount() == 0d) { |
| | | throw new BusinessException("金额不能为0"); |
| | | public ResponseVO<Object> advancePayOrder(HttpServletRequest request, @RequestBody PayParam param) throws WxErrorException { |
| | | if (param.getOpenId().isEmpty()) { |
| | | throw new BusinessException("微信code不能为空"); |
| | | } |
| | | if (param.getPoleId() == null || param.getSubscribeChargingCapacity() == null) { |
| | | throw new BusinessException("充电桩id或充电容量不能为空"); |
| | | } |
| | | if (param.getSubscribeChargingCapacity() < 1) { |
| | | throw new BusinessException("充电容量不能小于1Kw/h"); |
| | | } |
| | | // C3充电桩实体 |
| | | C3mCharging c3m = c3mService.getC3mByPoleId(param.getPoleId()); |
| | | if (null == c3m) { |
| | | throw new BusinessException("未找到当前充电桩"); |
| | | } |
| | | C3mOrder c3mOrderEntity = c3mOrderService.advancePayOrder(param.getPoleId(), c3m, param.getOrderType() |
| | | , param.getTotalAmount(), param.getSubscribeChargingCapacity()); |
| | | if (null == c3mOrderEntity) { |
| | | throw new BusinessException("该充电桩正被使用!"); |
| | | } |
| | | // return R.ok().put("outTradeNo",c3mOrderEntity.getOutTradeNo()) |
| | | // .put("totalAmount",totalAmount); |
| | | //获取预付金额 |
| | | BigDecimal TotalAmount = c3mChargingChargeService.getCostByC3id(c3m.getC3Id(), param.getSubscribeChargingCapacity()); |
| | | //转换为double类型 |
| | | double totalAmount = TotalAmount.doubleValue(); |
| | | //生成订单 |
| | | C3mOrder c3mOrderEntity = c3mOrderService.advancePayOrder(param.getPoleId(), c3m, "wxpay" |
| | | , totalAmount, param.getSubscribeChargingCapacity(), param.getOpenId()); |
| | | |
| | | Map map = new HashMap(); |
| | | map.put("outTradeNo", c3mOrderEntity.getOutTradeNo()); |
| | | map.put("totalAmount", param.getTotalAmount()); |
| | | return ResponseUtil.success(map); |
| | | } |
| | | |
| | | |
| | | @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()); |
| | | |
| | | String s = WxFastPayService.parseWxAmount(c3mOrderEntity.getTotalAmount().toString()); |
| | | //生成微信预付订单 |
| | | SortedMap<Object, Object> result = wxPayService.miniAppPay(request,"扫码充电支付(C3充电桩)", c3mOrderEntity.getOutTradeNo(), Integer.valueOf(s), param.getPoleId(), param.getOpenId()); |
| | | return ResponseUtil.success(result); |
| | | } |
| | | |
| | | public ResponseVO<Object> queryPayStates(@RequestBody PayParam param) { |
| | | |
| | | // //String result = wxPayService.miniAppPay(outTradeNo, totalAmount, streetlightId); |
| | | ////支付宝交易号 |
| | | // String trade_no = WIDtrade_no.Text.Trim(); |
| | | ////支付宝交易号与商户网站订单号不能同时为空 |
| | | ////商户订单号 |
| | | // String out_trade_no = WIDout_trade_no.Text.Trim(); |
| | | ////把请求参数打包成数组 |
| | | // |
| | | // SortedDictionary<string, string> sParaTemp = new SortedDictionary<string, string>(); |
| | | // sParaTemp.Add("partner", Config.Partner); |
| | | // sParaTemp.Add("_input_charset", Config.Input_charset.ToLower()); |
| | | // sParaTemp.Add("service", "single_trade_query"); |
| | | // sParaTemp.Add("trade_no", trade_no); |
| | | // sParaTemp.Add("out_trade_no", out_trade_no); |
| | | ////建立请求 |
| | | // string sHtmlText = Submit.BuildRequest(sParaTemp); |
| | | // |
| | | ////请在这里加上商户的业务逻辑程序代码 |
| | | // |
| | | ////——请根据您的业务逻辑来编写程序(以下代码仅作参考)—— |
| | | // |
| | | // XmlDocument xmlDoc = new XmlDocument(); |
| | | // try |
| | | // { |
| | | // xmlDoc.LoadXml(sHtmlText); |
| | | // string strXmlResponse = xmlDoc.SelectSingleNode("/alipay").InnerText; |
| | | // Response.Write(strXmlResponse); |
| | | // } |
| | | // catch (Exception exp) |
| | | // { |
| | | // Response.Write(sHtmlText); |
| | | // } |
| | | |
| | | return ResponseUtil.success(null); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 订单状态查询 微信支付 |
| | | * |
| | | * @param param |
| | | * @return |
| | | */ |
| | | @RequestMapping("/queryOrder") |
| | | public ResponseVO<Object> queryOrder(@RequestBody PayParam param) { |
| | | if (param.getOrderId() == null) { |
| | |
| | | |
| | | } |
| | | |
| | | /** |
| | | * 订单列表 |
| | | * |
| | | * @param baseConditionVO |
| | | * @param keyword 灯杆名称 |
| | | * @param orderStatus 订单状态:// 未支付(0) 已支付(1),退款中(2),已退款(3),订单完成(4),退款失败5) |
| | | * @param timeType 时间 1:一个月 2:三个月 3:六个月 |
| | | * @return |
| | | */ |
| | | @GetMapping("/list") |
| | | public ResponseVO<Object> list(BaseConditionVO baseConditionVO, |
| | | @RequestParam(value = "keyword", required = false) String keyword, |
| | | @RequestParam(value = "orderStatus", required = false) Integer orderStatus, |
| | | @RequestParam(value = "timeType", required = false) Integer timeType) { |
| | | return ResponseUtil.successPage(c3mOrderService.orderList(baseConditionVO, keyword, orderStatus, timeType)); |
| | | } |
| | | |
| | | /** |
| | | * 获取wx的openid |
| | | */ |
| | | @AnonymousAccess |
| | | @PostMapping("/getWxOpenId") |
| | | public ResponseVO<Object> getWxOpenId(@RequestBody PayParam param) throws WxErrorException { |
| | | if (param.getWxCode() == null || param.getPoleId() == null || param.getWxCode().isEmpty()) { |
| | | throw new BusinessException("参数不能为空"); |
| | | } |
| | | String openId = wxPayService.getOpenId(param.getPoleId(), param.getWxCode()); |
| | | |
| | | return ResponseUtil.success(MapUtil.builder().put("openId", openId).build()); |
| | | } |
| | | |
| | | } |