|
@@ -1,24 +1,28 @@
|
|
|
package com.ym.mec.collectfee.controller;
|
|
|
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
+import com.fasterxml.jackson.annotation.JsonTypeInfo;
|
|
|
import com.ym.mec.collectfee.entity.Order;
|
|
|
import com.ym.mec.collectfee.service.OrderService;
|
|
|
import com.ym.mec.collectfee.service.YqPayService;
|
|
|
import com.ym.mec.collectfee.service.YqQueryService;
|
|
|
import com.ym.mec.collectfee.service.impl.OrderServiceImpl;
|
|
|
import com.ym.mec.collectfee.utils.GenerateNum;
|
|
|
-import com.ym.mec.collectfee.utils.yqpay.Msg;
|
|
|
-import com.ym.mec.collectfee.utils.yqpay.YqPayUtil;
|
|
|
+import com.ym.mec.collectfee.utils.yqpay.*;
|
|
|
+import org.hibernate.validator.constraints.SafeHtml;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
+import org.springframework.validation.annotation.Validated;
|
|
|
import org.springframework.web.bind.annotation.ModelAttribute;
|
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
|
|
|
import java.math.BigDecimal;
|
|
|
+import java.util.Date;
|
|
|
import java.util.LinkedHashMap;
|
|
|
import java.util.Map;
|
|
|
+import java.util.zip.Inflater;
|
|
|
|
|
|
@RestController
|
|
|
@RequestMapping("yqPay")
|
|
@@ -40,45 +44,32 @@ public class YqPayController {
|
|
|
*/
|
|
|
@RequestMapping("/toPay")
|
|
|
@Transactional
|
|
|
- public Msg toPay(@ModelAttribute Order order) throws Exception {
|
|
|
+ public Msg toPay(@ModelAttribute @Validated Order order) throws Exception {
|
|
|
String orderNo = GenerateNum.getInstance().GenerateOrderNo();
|
|
|
- orderService.insert(order);
|
|
|
+ order.setOrderNo(orderNo);
|
|
|
+ order.setCreateTime(new Date());
|
|
|
+ order.setStatus(1);
|
|
|
+ Long id = orderService.insert(order);
|
|
|
|
|
|
/*卖家双乾商户号*/
|
|
|
String sellerNo = "0022652"; //某笔定义到某个商户
|
|
|
- /*支付渠道*/
|
|
|
- String payChannels = "weChatPay";
|
|
|
- /*卖家双乾商户号*/
|
|
|
/*订单信息*/
|
|
|
String orderBody = "大雅乐盟培训课程";
|
|
|
- /*金额*/
|
|
|
- String payAmount = "50";
|
|
|
- /*API支付类型1-即时支付,2-担保支付,3-预授权支付*/
|
|
|
- String apiPayType = "1";
|
|
|
- /*API商户订单号*/
|
|
|
- String merMerOrderNo = "0855555322";
|
|
|
- /*买家商户号*/
|
|
|
- String buyerNo = "";
|
|
|
- /*不参与优惠计算的金额*/
|
|
|
- String undiscountableAmount = "";
|
|
|
/*订单标题*/
|
|
|
String orderSubject = "培训订单";
|
|
|
/*商品列表信息*/
|
|
|
String goodsDetail = "";
|
|
|
- /*交易类型1—充值,0—收款*/
|
|
|
- String tradeType = "0";
|
|
|
-
|
|
|
|
|
|
String notifyUrl = "http://47.99.212.176:9000/yqpay/notify";
|
|
|
String returnUrl = "http://47.99.212.176:9000/yqpay/notify";//前台页面通知地址(银联H5必填)
|
|
|
|
|
|
Map<String, Object> resultMap = new LinkedHashMap<String, Object>();
|
|
|
resultMap.put("sellerNo", sellerNo); //收款商户号
|
|
|
- resultMap.put("payChannels", "unionPay"); //支付方式(支付渠道)
|
|
|
+ resultMap.put("payChannels", order.getBank()); //支付方式(支付渠道)
|
|
|
resultMap.put("orderBody", orderBody); //订单信息
|
|
|
- resultMap.put("payAmount", payAmount); //支付金额
|
|
|
+ resultMap.put("payAmount", order.getAmount()); //支付金额
|
|
|
resultMap.put("apiPayType", "1"); //*API支付类型1-即时支付,2-担保支付,3-预授权支付*/
|
|
|
- resultMap.put("tradeType", tradeType); //*交易类型1—充值,0—收款*
|
|
|
+ resultMap.put("tradeType", "0"); //*交易类型1—充值,0—收款*
|
|
|
resultMap.put("merMerOrderNo", orderNo); //商户订单号
|
|
|
resultMap.put("orderSubject", orderSubject); //订单标题
|
|
|
resultMap.put("returnUrl", returnUrl); //前台页面通知地址(银联H5必填)
|
|
@@ -89,10 +80,13 @@ public class YqPayController {
|
|
|
resultMap.put("goodsDetail", goodsDetail);
|
|
|
Map<String, Object> requestMap = new YqPayUtil(notifyUrl, resultMap).getRequestMap();
|
|
|
Msg msg = yqPayService.toPay(requestMap);
|
|
|
- if(!msg.getResponseParameters().isEmpty()){
|
|
|
- Object parse = JSON.parse(msg.getResponseParameters());
|
|
|
+ if (!msg.getResponseParameters().isEmpty()) {
|
|
|
+ RspMsg rspMsg = JSON.parseObject(msg.getResponseParameters(), RspMsg.class);
|
|
|
+ String merOrderNo = rspMsg.getMerOrderNo();
|
|
|
+ order.setId(id.intValue());
|
|
|
+ order.setPayId(merOrderNo); //乾易付订单号
|
|
|
+ orderService.update(order);
|
|
|
}
|
|
|
- System.out.println(parse);
|
|
|
return msg;
|
|
|
}
|
|
|
|
|
@@ -164,6 +158,48 @@ public class YqPayController {
|
|
|
return yqPayService.platformTransferAcc(requestMap);
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 提现发送短信
|
|
|
+ *
|
|
|
+ * @return
|
|
|
+ * @throws Exception
|
|
|
+ */
|
|
|
+ public Msg sendSms(@ModelAttribute Intfc intfc) throws Exception {
|
|
|
+ String notifyUrl = ""; //回调地址
|
|
|
+ String merMerOrderNo = GenerateNum.getInstance().GenerateOrderNo();
|
|
|
+ Map<String, Object> resultMap = new LinkedHashMap<>();
|
|
|
+ resultMap.put("wdMerNo", intfc.getWdMerNo()); //提现商户号
|
|
|
+ resultMap.put("merMerOrderNo", merMerOrderNo); //商户订单号
|
|
|
+ resultMap.put("amount", intfc.getAmount()); //提现金额
|
|
|
+ resultMap.put("cardNo", intfc.getCardNo()); //提现银行卡号
|
|
|
+ resultMap.put("phone", intfc.getPhone()); //预留手机号(选填)
|
|
|
+ resultMap.put("cardType", intfc.getCardType()); //卡类型 0-个人银行卡,1-企业银行卡。(选填)
|
|
|
+ Map<String, Object> requestMap = new YqPayUtil(notifyUrl, resultMap).getRequestMap();
|
|
|
+ return yqPayService.intfc(requestMap);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 提现
|
|
|
+ *
|
|
|
+ * @return
|
|
|
+ * @throws Exception
|
|
|
+ */
|
|
|
+ public Msg intfc(@ModelAttribute Intfc intfc) throws Exception {
|
|
|
+ String notifyUrl = "http://47.99.212.176:9000/yqpay/notify"; //回调地址
|
|
|
+ String merMerOrderNo = GenerateNum.getInstance().GenerateOrderNo();
|
|
|
+ Map<String, Object> resultMap = new LinkedHashMap<>();
|
|
|
+ resultMap.put("wdMerNo", intfc.getWdMerNo()); //提现商户号
|
|
|
+ resultMap.put("merMerOrderNo", merMerOrderNo); //商户订单号
|
|
|
+ resultMap.put("amount", intfc.getAmount()); //提现金额
|
|
|
+ resultMap.put("cardNo", intfc.getCardNo()); //提现银行卡号
|
|
|
+ resultMap.put("phone", intfc.getPhone()); //预留手机号(选填)
|
|
|
+ resultMap.put("cardType", intfc.getCardType()); //卡类型 0-个人银行卡,1-企业银行卡。(选填)
|
|
|
+ resultMap.put("seqNo", ""); //流水号(选填)
|
|
|
+ resultMap.put("smsCode", ""); //验证码(选填)
|
|
|
+ Map<String, Object> requestMap = new YqPayUtil(notifyUrl, resultMap).getRequestMap();
|
|
|
+ return yqPayService.intfc(requestMap);
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
/**
|
|
|
* 易乾异步通知接口
|
|
@@ -173,7 +209,7 @@ public class YqPayController {
|
|
|
* @throws Exception
|
|
|
*/
|
|
|
@RequestMapping("/notify")
|
|
|
- public Object notify(Msg msg) throws Exception {
|
|
|
+ public Msg notify(@ModelAttribute Msg msg) throws Exception {
|
|
|
Map<String, Object> rqMap = new LinkedHashMap<String, Object>();
|
|
|
rqMap.put("code", msg.getCode());
|
|
|
rqMap.put("msg", msg.getMsg());
|
|
@@ -181,10 +217,33 @@ public class YqPayController {
|
|
|
rqMap.put("responseParameters", msg.getResponseParameters());
|
|
|
rqMap.put("sign", msg.getSign());
|
|
|
boolean rs = YqPayUtil.verify(rqMap);
|
|
|
+ msg.setCode("");
|
|
|
+ msg.setMsg("fail");
|
|
|
+ Order order = null;
|
|
|
+ NotifyMsg notifyMsg = null;
|
|
|
if (rs) {
|
|
|
-
|
|
|
+ notifyMsg = JSON.parseObject(msg.getResponseParameters(), NotifyMsg.class);
|
|
|
+ String merMerOrderNo = notifyMsg.getMerMerOrderNo(); //自己系统订单号
|
|
|
+ order = orderService.getOrderByOrderNo(merMerOrderNo);
|
|
|
+ }
|
|
|
+ //支付中订单存在,更新状态
|
|
|
+ if (order != null && msg.getResponseType().equals("1")) {
|
|
|
+ //更新订单状态
|
|
|
+ int status = msg.getCode().equals("88") ? 0 : 2;
|
|
|
+ order.setStatus(status);
|
|
|
+ if (order.getOrderNo().isEmpty()) {
|
|
|
+ order.setPayId(notifyMsg.getOrderNo()); //更新易乾付订单号
|
|
|
+ }
|
|
|
+ if (status == 0) {
|
|
|
+ order.setPay(notifyMsg.getPayAmount());
|
|
|
+ order.setPayTime(new Date());
|
|
|
+ }
|
|
|
+ orderService.update(order);
|
|
|
+
|
|
|
+ msg.setCode("000000");
|
|
|
+ msg.setMsg("success");
|
|
|
}
|
|
|
- return "";
|
|
|
+ return msg;
|
|
|
}
|
|
|
|
|
|
|