YqPayController.java 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258
  1. package com.ym.mec.collectfee.controller;
  2. import com.alibaba.fastjson.JSON;
  3. import com.ym.mec.collectfee.entity.Order;
  4. import com.ym.mec.collectfee.service.OrderService;
  5. import com.ym.mec.collectfee.service.YqPayService;
  6. import com.ym.mec.collectfee.service.YqQueryService;
  7. import com.ym.mec.collectfee.utils.GenerateNum;
  8. import com.ym.mec.collectfee.utils.yqpay.*;
  9. import io.swagger.annotations.Api;
  10. import io.swagger.annotations.ApiOperation;
  11. import lombok.extern.slf4j.Slf4j;
  12. import org.springframework.beans.factory.annotation.Autowired;
  13. import org.springframework.context.annotation.Lazy;
  14. import org.springframework.transaction.annotation.Transactional;
  15. import org.springframework.validation.annotation.Validated;
  16. import org.springframework.web.bind.annotation.ModelAttribute;
  17. import org.springframework.web.bind.annotation.PostMapping;
  18. import org.springframework.web.bind.annotation.RequestMapping;
  19. import org.springframework.web.bind.annotation.RestController;
  20. import springfox.documentation.annotations.ApiIgnore;
  21. import java.util.Date;
  22. import java.util.LinkedHashMap;
  23. import java.util.Map;
  24. @Api(description = "支付")
  25. @Slf4j
  26. @RestController
  27. @RequestMapping("yqPay")
  28. @ApiIgnore
  29. public class YqPayController {
  30. @Autowired
  31. @Lazy
  32. private YqPayService yqPayService;
  33. @Autowired
  34. @Lazy
  35. private YqQueryService yqQueryService;
  36. @Autowired
  37. private OrderService orderService;
  38. /**
  39. * 统一下单
  40. *
  41. * @return String
  42. * @throws Exception
  43. */
  44. @ApiOperation(value = "提交支付", notes = "易乾支付统一下单")
  45. @PostMapping("/toPay")
  46. @Transactional
  47. public Msg toPay(@ModelAttribute @Validated Order order) throws Exception {
  48. String orderNo = GenerateNum.getInstance().GenerateOrderNo();
  49. order.setOrderNo(orderNo);
  50. order.setCreateTime(new Date());
  51. order.setStatus(1);
  52. /*卖家双乾商户号*/
  53. String sellerNo = "0022652"; //某笔定义到某个商户
  54. order.setAccount(sellerNo);
  55. Long id = orderService.insert(order);
  56. /*订单信息*/
  57. String orderBody = "大雅乐盟培训课程";
  58. /*订单标题*/
  59. String orderSubject = "培训订单";
  60. /*商品列表信息*/
  61. String goodsDetail = "";
  62. String notifyUrl = "http://47.99.212.176:9000/yqpay/notify";
  63. String returnUrl = "http://47.99.212.176:9000/yqpay/notify";//前台页面通知地址(银联H5必填)
  64. Map<String, Object> resultMap = new LinkedHashMap<String, Object>();
  65. resultMap.put("sellerNo", sellerNo); //收款商户号
  66. resultMap.put("payChannels", order.getBank()); //支付方式(支付渠道)
  67. resultMap.put("orderBody", orderBody); //订单信息
  68. resultMap.put("payAmount", order.getAmount()); //支付金额
  69. resultMap.put("apiPayType", "1"); //*API支付类型1-即时支付,2-担保支付,3-预授权支付*/
  70. resultMap.put("tradeType", "0"); //*交易类型1—充值,0—收款*
  71. resultMap.put("merMerOrderNo", orderNo); //商户订单号
  72. resultMap.put("orderSubject", orderSubject); //订单标题
  73. resultMap.put("returnUrl", returnUrl); //前台页面通知地址(银联H5必填)
  74. resultMap.put("mchAppId", returnUrl); //填网站首页地址(银联H5必填)
  75. resultMap.put("mchAppName", returnUrl); //传wap网站名(银联H5必填)
  76. resultMap.put("deviceInfo", "AND_WAP"); //设置信息(银联H5必填)
  77. resultMap.put("clientIp", "27.18.213.149"); //客户端ip地址(银联H5必填)
  78. resultMap.put("goodsDetail", goodsDetail);
  79. Map<String, Object> requestMap = new YqPayUtil(notifyUrl, resultMap).getRequestMap();
  80. Msg msg = yqPayService.toPay(requestMap);
  81. if (!msg.getResponseParameters().isEmpty()) {
  82. RspMsg rspMsg = JSON.parseObject(msg.getResponseParameters(), RspMsg.class);
  83. String merOrderNo = rspMsg.getMerOrderNo();
  84. order.setId(id.intValue());
  85. order.setPayId(merOrderNo); //乾易付订单号
  86. orderService.update(order);
  87. }
  88. return msg;
  89. }
  90. /**
  91. * 交易查询
  92. *
  93. * @param merOrderNoList 用户订单号
  94. * @return
  95. * @throws Exception
  96. */
  97. @PostMapping("/query")
  98. public String query(String merOrderNoList) throws Exception {
  99. String notifyUrl = ""; //回调地址
  100. Map<String, Object> resultMap = new LinkedHashMap<>();
  101. resultMap.put("merOrderNoList", merOrderNoList);
  102. Map<String, Object> requestMap = new YqPayUtil(notifyUrl, resultMap).getRequestMap();
  103. return yqQueryService.orderQuery(requestMap);
  104. }
  105. /**
  106. * 用户信息(商户)查询
  107. *
  108. * @param sonMerNo 子商户号
  109. * @return
  110. * @throws Exception
  111. */
  112. @PostMapping("/queryaccount")
  113. public String queryAccount(String sonMerNo) throws Exception {
  114. String notifyUrl = ""; //回调地址
  115. Map<String, Object> resultMap = new LinkedHashMap<>();
  116. resultMap.put("merOrderNoList", sonMerNo);
  117. Map<String, Object> requestMap = new YqPayUtil(notifyUrl, resultMap).getRequestMap();
  118. return yqQueryService.queryAccount(requestMap);
  119. }
  120. /**
  121. * 对账查询(定时任务每天对账)
  122. *
  123. * @return
  124. */
  125. public String queryBill() throws Exception {
  126. String notifyUrl = ""; //回调地址
  127. Map<String, Object> resultMap = new LinkedHashMap<>();
  128. resultMap.put("tradeDate", ""); //交易日期
  129. resultMap.put("payState", ""); //订单状态
  130. resultMap.put("tradeType", ""); //交易类型,不填为全部
  131. resultMap.put("channelType", ""); //通道类型,不填为全部
  132. Map<String, Object> requestMap = new YqPayUtil(notifyUrl, resultMap).getRequestMap();
  133. return yqQueryService.billQuery(requestMap);
  134. }
  135. /**
  136. * 平台转账
  137. *
  138. * @return
  139. * @throws Exception
  140. */
  141. @PostMapping("/platformtransferacc")
  142. public String platformTransferAcc() throws Exception {
  143. String notifyUrl = ""; //回调地址
  144. Map<String, Object> resultMap = new LinkedHashMap<>();
  145. resultMap.put("payeeNo", ""); //收款方商户号
  146. resultMap.put("payeeName", ""); //收款方姓名
  147. resultMap.put("amount", ""); //金额
  148. resultMap.put("merOrderNo", ""); //商户订单号
  149. resultMap.put("remarks", ""); //备注
  150. Map<String, Object> requestMap = new YqPayUtil(notifyUrl, resultMap).getRequestMap();
  151. return yqPayService.platformTransferAcc(requestMap);
  152. }
  153. /**
  154. * 提现短信
  155. * @return
  156. * @throws Exception
  157. */
  158. @PostMapping("/sendsms")
  159. public Msg sendSms(@ModelAttribute Intfc intfc) throws Exception {
  160. String notifyUrl = ""; //回调地址
  161. String merMerOrderNo = GenerateNum.getInstance().GenerateOrderNo();
  162. Map<String, Object> resultMap = new LinkedHashMap<>();
  163. resultMap.put("wdMerNo", intfc.getWdMerNo()); //提现商户号
  164. resultMap.put("merMerOrderNo", merMerOrderNo); //商户订单号
  165. resultMap.put("amount", intfc.getAmount()); //提现金额
  166. resultMap.put("cardNo", intfc.getCardNo()); //提现银行卡号
  167. // resultMap.put("phone", intfc.getPhone()); //预留手机号(选填)
  168. // resultMap.put("cardType", intfc.getCardType()); //卡类型 0-个人银行卡,1-企业银行卡。(选填)
  169. Map<String, Object> requestMap = new YqPayUtil(notifyUrl, resultMap).getRequestMap();
  170. return yqPayService.intfc(requestMap);
  171. }
  172. /**
  173. * 提现
  174. * @return
  175. * @throws Exception
  176. */
  177. @PostMapping("/intfc")
  178. public Msg intfc(@ModelAttribute Intfc intfc) throws Exception {
  179. String notifyUrl = "http://47.99.212.176:9000/yqpay/notify"; //回调地址
  180. String merMerOrderNo = GenerateNum.getInstance().GenerateOrderNo();
  181. Map<String, Object> resultMap = new LinkedHashMap<>();
  182. resultMap.put("wdMerNo", intfc.getWdMerNo()); //提现商户号
  183. resultMap.put("merMerOrderNo", merMerOrderNo); //商户订单号
  184. resultMap.put("amount", intfc.getAmount()); //提现金额
  185. resultMap.put("cardNo", intfc.getCardNo()); //提现银行卡号
  186. // resultMap.put("phone", intfc.getPhone()); //预留手机号(选填)
  187. // resultMap.put("cardType", intfc.getCardType()); //卡类型 0-个人银行卡,1-企业银行卡。(选填)
  188. resultMap.put("seqNo", ""); //流水号(选填)
  189. resultMap.put("smsCode", ""); //验证码(选填)
  190. Map<String, Object> requestMap = new YqPayUtil(notifyUrl, resultMap).getRequestMap();
  191. return yqPayService.intfc(requestMap);
  192. }
  193. /**
  194. * 易乾异步通知接口
  195. *
  196. * @param msg
  197. * @return String
  198. * @throws Exception
  199. */
  200. @PostMapping("/notify")
  201. public Msg notify(@ModelAttribute Msg msg) throws Exception {
  202. log.info(msg.toString());
  203. Map<String, Object> rqMap = new LinkedHashMap<String, Object>();
  204. rqMap.put("code", msg.getCode());
  205. rqMap.put("msg", msg.getMsg());
  206. rqMap.put("responseType", msg.getResponseType());
  207. rqMap.put("responseParameters", msg.getResponseParameters());
  208. rqMap.put("sign", msg.getSign());
  209. boolean rs = YqPayUtil.verify(rqMap);
  210. msg.setCode("");
  211. msg.setMsg("fail");
  212. Order order = null;
  213. NotifyMsg notifyMsg = null;
  214. if (rs) {
  215. notifyMsg = JSON.parseObject(msg.getResponseParameters(), NotifyMsg.class);
  216. String merMerOrderNo = notifyMsg.getMerMerOrderNo(); //自己系统订单号
  217. order = orderService.getOrderByOrderNo(merMerOrderNo);
  218. }
  219. //支付中订单存在,更新状态
  220. if (order != null && msg.getResponseType().equals("1")) {
  221. //更新订单状态
  222. int status = msg.getCode().equals("88") ? 0 : 2;
  223. order.setStatus(status);
  224. if (order.getOrderNo().isEmpty()) {
  225. order.setPayId(notifyMsg.getOrderNo()); //更新易乾付订单号
  226. }
  227. if(status == 0){
  228. order.setPay(notifyMsg.getPayAmount());
  229. order.setPayTime(new Date());
  230. }
  231. orderService.update(order);
  232. msg.setCode("000000");
  233. msg.setMsg("success");
  234. }
  235. return msg;
  236. }
  237. }