|
@@ -0,0 +1,165 @@
|
|
|
+package com.caimei.controller.order;
|
|
|
+
|
|
|
+import com.caimei.module.base.entity.bo.JsonModel;
|
|
|
+import com.caimei.module.base.entity.bo.Payment;
|
|
|
+import com.caimei.module.base.entity.vo.OrderPayLinkVo;
|
|
|
+import com.caimei.module.pay.service.PayService;
|
|
|
+import com.caimei.utils.WxConfig;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.apache.commons.lang.StringUtils;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.beans.factory.annotation.Value;
|
|
|
+import org.springframework.web.bind.annotation.GetMapping;
|
|
|
+import org.springframework.web.bind.annotation.PostMapping;
|
|
|
+import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
+import org.springframework.web.bind.annotation.RestController;
|
|
|
+
|
|
|
+import javax.servlet.http.HttpServletRequest;
|
|
|
+import javax.servlet.http.HttpServletResponse;
|
|
|
+import java.io.IOException;
|
|
|
+import java.util.Map;
|
|
|
+
|
|
|
+/**
|
|
|
+ * Description
|
|
|
+ *
|
|
|
+ * @author : plf
|
|
|
+ * @date : 2020/5/6
|
|
|
+ */
|
|
|
+@Slf4j
|
|
|
+@RestController
|
|
|
+@RequestMapping("/PayOrder")
|
|
|
+public class PayOrderController {
|
|
|
+ private PayService payService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ public void setPayService(PayService payService) {
|
|
|
+ this.payService = payService;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Value("${miniprogram.notifyUrl}")
|
|
|
+ private String notifyUrl;
|
|
|
+
|
|
|
+ @Value("${miniprogram.redirectLink}")
|
|
|
+ private String redirectLink;
|
|
|
+
|
|
|
+ @Value("${miniprogram.linkPage}")
|
|
|
+ private String linkPage;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 收银台数据显示
|
|
|
+ */
|
|
|
+ @GetMapping("/checkoutCounter")
|
|
|
+ public JsonModel checkoutCounter(Integer orderId) {
|
|
|
+ return payService.checkoutCounter(orderId);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 微信线上支付
|
|
|
+ */
|
|
|
+ @PostMapping("/miniWxPay")
|
|
|
+ public JsonModel miniWxPay(Payment payment, HttpServletRequest request) {
|
|
|
+ JsonModel model = JsonModel.newInstance();
|
|
|
+ if (!"WEIXIN".equals(payment.getPayWay()) || payment.getPayAmount() == null || payment.getPayAmount() < 2) {
|
|
|
+ return model.error("参数异常");
|
|
|
+ }
|
|
|
+ Map<String, Object> map = null;
|
|
|
+ if (null == payment.getState()) {
|
|
|
+ //小程序微信快捷支付
|
|
|
+ payment.setPayType("MINIAPP_WEIXIN");
|
|
|
+ JsonModel wxJscode = WxConfig.getWxJscode(payment.getCode(), request);
|
|
|
+ if (wxJscode.getCode() == -1) {
|
|
|
+ return model.error(wxJscode.getMsg());
|
|
|
+ }
|
|
|
+ map = (Map<String, Object>) wxJscode.getData();
|
|
|
+ } else {
|
|
|
+ //pc微信扫码支付,微信公众号支付
|
|
|
+ payment.setPayType("JSAPI_WEIXIN");
|
|
|
+ try {
|
|
|
+ map = WxConfig.getAccessTokenMap(payment.getCode(), "crm");
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ return model.error("wx公众号获取openid失败");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ String openid = (String) map.get("openid");
|
|
|
+ if (openid == null) {
|
|
|
+ return model.error("wx获取openid失败");
|
|
|
+ }
|
|
|
+ payment.setOpenid(openid);
|
|
|
+ payment.setNotifyUrl(notifyUrl);
|
|
|
+ log.info("wx支付openid>>>>>" + openid);
|
|
|
+ return payService.pay(payment, request);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 支付异步通知回调
|
|
|
+ */
|
|
|
+ @GetMapping("/paymentCallback")
|
|
|
+ public String paymentCallback(HttpServletRequest request) throws Exception {
|
|
|
+ log.info("异步回调通知>>>>>>>start");
|
|
|
+ String data = request.getParameter("data");
|
|
|
+ if (StringUtils.isBlank(data)) {
|
|
|
+ return "回调参数失败";
|
|
|
+ }
|
|
|
+ return payService.paymentCallback(data);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 小程序生成网银支付链接
|
|
|
+ */
|
|
|
+ @PostMapping("/payLink")
|
|
|
+ public JsonModel payLink(OrderPayLinkVo orderPayLink) {
|
|
|
+ orderPayLink.setRedirectLink(redirectLink);
|
|
|
+ return payService.payLink(orderPayLink);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 支付链接重定向到页面
|
|
|
+ */
|
|
|
+ @GetMapping("/jumpPage")
|
|
|
+ public void jumpPage(String linkLogo, HttpServletResponse response) throws IOException {
|
|
|
+ payService.jumpPage(linkLogo, linkPage, response);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * pc端支付,银联,支付宝
|
|
|
+ */
|
|
|
+ @PostMapping("/pcMallPay")
|
|
|
+ public JsonModel pcMallPay(Payment payment, HttpServletRequest request) {
|
|
|
+ JsonModel model = JsonModel.newInstance();
|
|
|
+ if (null == payment || StringUtils.isBlank(payment.getPayWay()) || StringUtils.isBlank(payment.getReturnUrl()) || payment.getPayAmount() == null) {
|
|
|
+ return model.error("参数异常");
|
|
|
+ }
|
|
|
+ if ("UNIONPAY".equals(payment.getPayWay())) {
|
|
|
+ //银联支付
|
|
|
+ payment.setPayType("GATEWAY_UNIONPAY");
|
|
|
+ } else if ("ALIPAY".equals(payment.getPayWay())) {
|
|
|
+ //支付宝支付
|
|
|
+ payment.setPayType("ALIPAY_H5");
|
|
|
+ }
|
|
|
+ payment.setNotifyUrl(notifyUrl);
|
|
|
+ return payService.pay(payment, request);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 判断此次支付是否完成
|
|
|
+ */
|
|
|
+ @GetMapping("/payWhetherSuccess")
|
|
|
+ public JsonModel payWhetherSuccess(Integer orderId, Integer paySuccessCounter) {
|
|
|
+ if (null == orderId || null == paySuccessCounter) {
|
|
|
+ return JsonModel.newInstance().error("参数异常");
|
|
|
+ }
|
|
|
+ return payService.payWhetherSuccess(orderId, paySuccessCounter);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 查询本次支付订单是否完成
|
|
|
+ */
|
|
|
+ @GetMapping("/findOrderStatus")
|
|
|
+ public JsonModel findOrderStatus(String mbOrderId) {
|
|
|
+ if (null == mbOrderId) {
|
|
|
+ return JsonModel.newInstance().error("参数异常");
|
|
|
+ }
|
|
|
+ return payService.findOrderStatus(mbOrderId);
|
|
|
+ }
|
|
|
+}
|