PayController.java 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292
  1. package com.fs.app.controller;
  2. import cn.hutool.core.bean.BeanUtil;
  3. import cn.hutool.json.JSONUtil;
  4. import com.alibaba.fastjson.JSON;
  5. import com.alibaba.fastjson.JSONObject;
  6. import com.fs.common.config.FSSysConfig;
  7. import com.fs.common.core.controller.BaseController;
  8. import com.fs.common.core.redis.RedisCache;
  9. import com.fs.common.utils.StringUtils;
  10. import com.fs.common.utils.spring.SpringUtils;
  11. import com.fs.company.service.ICompanyService;
  12. import com.fs.company.service.ICompanyUserService;
  13. import com.fs.erp.service.IErpOrderService;
  14. import com.fs.huifuPay.domain.HuiFuOnlinePay;
  15. import com.fs.huifuPay.domain.HuiFuOnlineRefund;
  16. import com.fs.huifuPay.domain.HuiFuResult;
  17. import com.fs.huifuPay.dto.*;
  18. import com.fs.pay.pay.domain.OrderCallback;
  19. import com.fs.pay.pay.domain.OrderResult;
  20. import com.fs.pay.pay.dto.OrderQueryDTO;
  21. import com.fs.pay.pay.service.PayService;
  22. import com.fs.pay.pay.util.PayUtil;
  23. import com.fs.pay.service.dto.PayNotifyDTO;
  24. import com.fs.pay.service.dto.RefundNotifyDTO;
  25. import com.fs.pay.service.dto.TradeOrder;
  26. import com.fs.store.domain.FsStorePayment;
  27. import com.fs.store.domain.TzConfigInfoDTO;
  28. import com.fs.store.service.*;
  29. import com.fs.store.vo.PrescribeVO;
  30. import com.fs.system.domain.SysConfig;
  31. import com.fs.system.mapper.SysConfigMapper;
  32. import com.fs.tzBank.TzBankService;
  33. import com.fs.tzBank.dto.TzOrderInfoDTO;
  34. import com.fs.tzBank.dto.TzPaymentResultDTO;
  35. import com.fs.tzBank.dto.TzRefundOrderDTO;
  36. import com.fs.tzBank.utils.TzConfigUtils;
  37. import com.google.gson.Gson;
  38. import com.tzbank.util.CallBackUtil;
  39. import io.swagger.annotations.Api;
  40. import io.swagger.annotations.ApiOperation;
  41. import lombok.extern.slf4j.Slf4j;
  42. import org.slf4j.Logger;
  43. import org.slf4j.LoggerFactory;
  44. import org.springframework.beans.factory.annotation.Autowired;
  45. import org.springframework.context.ApplicationEventPublisher;
  46. import org.springframework.web.bind.annotation.*;
  47. import javax.servlet.http.HttpServletRequest;
  48. import java.math.BigDecimal;
  49. import java.util.Date;
  50. import java.util.HashMap;
  51. import java.util.List;
  52. import java.util.Map;
  53. @Api("第三方支付接口")
  54. @RestController
  55. @RequestMapping("/app/pay")
  56. public class PayController {
  57. protected final Logger logger = LoggerFactory.getLogger(BaseController.class);
  58. @Autowired
  59. private RedisCache redisCache;
  60. @Autowired
  61. private IFsStoreOrderService orderService;
  62. @Autowired
  63. private IFsStoreOrderStatusService orderStatusService;
  64. @Autowired
  65. private IFsUserBillService billService;
  66. @Autowired
  67. private IFsUserService userService;
  68. @Autowired
  69. private ApplicationEventPublisher publisher;
  70. @Autowired
  71. private FSSysConfig sysConfig;
  72. @Autowired
  73. IErpOrderService erpOrderService;
  74. @Autowired
  75. private IFsStoreOrderItemService storeOrderItemService;
  76. @Autowired
  77. private IFsStorePaymentService storePaymentService;
  78. @Autowired
  79. private IFsExpressService expressService;
  80. @Autowired
  81. private ICompanyService companyService;
  82. @Autowired
  83. PayService ybPayService;
  84. @Autowired
  85. TzBankService tzBankService;
  86. @Autowired
  87. private ICompanyUserService companyUserService;
  88. @ApiOperation("台州银行第三方支付回调")
  89. @PostMapping(value="/tzBkPayNotify")
  90. public String tzBkPayNotify( @RequestBody String decryptForm ) throws Exception {
  91. TzConfigInfoDTO tzConfigInfoDTO = TzConfigUtils.getConfig();
  92. String decrypt = CallBackUtil.decrypt( tzConfigInfoDTO.getAppSecret(),decryptForm);
  93. logger.info("台州银行第三方支付回调接口被调用,请求参数: {}", decrypt);
  94. String filteredString = decrypt.replaceAll("[^\\x20-\\x7E]", "");
  95. Gson gson = new Gson();
  96. TzPaymentResultDTO tzPaymentResultDTO = gson.fromJson(filteredString, TzPaymentResultDTO.class);
  97. //验证
  98. if(tzPaymentResultDTO.getStatus().equals("90")){
  99. String orderId = tzPaymentResultDTO.getOrderNo().replace("store","");
  100. if(StringUtils.isNotBlank(orderId)){
  101. orderService.payConfirm(1, null, tzPaymentResultDTO.getOrderNo(),
  102. tzPaymentResultDTO.getOrderFlowNo(),tzPaymentResultDTO.getChlTrxId(),tzPaymentResultDTO.getOrderFlowNo());
  103. }
  104. }
  105. return "success";
  106. }
  107. @ApiOperation("台州银行第三方退款回调")
  108. @PostMapping(value="/tzRefundNotify")
  109. public String tzRefundNotify(@RequestBody String decryptForm) throws Exception {
  110. TzConfigInfoDTO tzConfigInfoDTO = TzConfigUtils.getConfig();
  111. String decrypt = CallBackUtil.decrypt( tzConfigInfoDTO.getAppSecret(),decryptForm);
  112. logger.info("台州银行第三方退款回调,请求参数: {}", JSON.toJSONString(decrypt));
  113. // if(dto.getRefundOrdStatus().equals("90")){
  114. // FsStorePayment storePayment=storePaymentService.selectFsStorePaymentByCode(dto.getRefundOrderNo());
  115. // if(storePayment!=null){
  116. // storePaymentService.refund(dto.getRefundOrderNo());
  117. // Long orderId = storePayment.getOrderId();
  118. // orderService.refundOrder(orderId);
  119. // }
  120. // return "success";
  121. // }
  122. return "success";
  123. }
  124. @ApiOperation("易宝第三方支付回调")
  125. @PostMapping(value="/ybPayNotify")
  126. public String ybPayNotify( @RequestBody String jsonBody ) throws Exception {
  127. //验证
  128. OrderCallback o= JSONUtil.toBean(jsonBody, OrderCallback.class);
  129. if(o.getState().equals("0")){
  130. OrderQueryDTO orderQueryDTO = new OrderQueryDTO();
  131. orderQueryDTO.setLowOrderId(o.getLowOrderId());
  132. OrderResult orderResult = ybPayService.getOrder(orderQueryDTO);
  133. String[] order=o.getLowOrderId().split("-");
  134. switch (order[0]) {
  135. case "store":
  136. return orderService.payConfirm(1,null,order[1], o.getUpOrderId(),orderResult.getBankTrxId(),orderResult.getBankOrderId());
  137. case "store_remain":
  138. return orderService.payRemainConfirm( order[1], o.getUpOrderId(),orderResult.getBankTrxId(),orderResult.getBankOrderId());
  139. case "payment":
  140. return storePaymentService.payConfirm(order[1],o.getUpOrderId(),orderResult.getBankTrxId(),orderResult.getBankOrderId());
  141. }
  142. }
  143. return "";
  144. }
  145. @ApiOperation("汇付第三方支付回调")
  146. @PostMapping(value="/hfPayNotify")
  147. public String hfPayNotify(@RequestParam String resp_desc, @RequestParam String resp_code, @RequestParam String sign, @RequestParam String resp_data) throws Exception {
  148. //验证
  149. HuiFuResult o = JSON.parseObject(resp_data, HuiFuResult.class);
  150. logger.info("汇付支付回调:"+o);
  151. if(o.getResp_code().equals("00000000")){
  152. String[] order=o.getReq_seq_id().split("-");
  153. switch (order[0]) {
  154. case "store":
  155. return orderService.payConfirm(1,null,order[1], o.getHf_seq_id(),o.getOut_trans_id(),o.getParty_order_id());
  156. case "store_remain":
  157. return orderService.payRemainConfirm( order[1], o.getHf_seq_id(),o.getOut_trans_id(),o.getParty_order_id());
  158. case "payment":
  159. return storePaymentService.payConfirm(order[1],o.getHf_seq_id(),o.getOut_trans_id(),o.getParty_order_id());
  160. }
  161. }
  162. return "ok";
  163. }
  164. @RequestMapping("/payOnlineNotifyUrl")
  165. public String asyncHuFuOnlinePay(@RequestParam String resp_desc,@RequestParam String resp_code,@RequestParam String sign,@RequestParam String resp_data) {
  166. HuiFuOnlinePay huFuResult = JSON.parseObject(resp_data, HuiFuOnlinePay.class);
  167. return "ok";
  168. }
  169. @RequestMapping("/onlineRefund")
  170. public String onlineRefund(@RequestParam String resp_desc,@RequestParam String resp_code,@RequestParam String sign,@RequestParam String resp_data) {
  171. HuiFuOnlineRefund huFuResult = JSON.parseObject(resp_data, HuiFuOnlineRefund.class);
  172. return "ok";
  173. }
  174. @RequestMapping("/refundNotifyUrl")
  175. public String refundMessage(@RequestParam String resp_desc,@RequestParam String resp_code,@RequestParam String sign,@RequestParam String resp_data) {
  176. System.out.println(resp_data);
  177. return "ok";
  178. }
  179. @ApiOperation("小雨点第三方支付回调")
  180. @PostMapping(value="/payNotify")
  181. public String payNotify(HttpServletRequest request,PayNotifyDTO dto) throws Exception {
  182. if("SUCCESS".equals(dto.getOrderStatus())) {
  183. //订单号
  184. String tradeNo = dto.getMerchOrderNo();
  185. List<TradeOrder> tradeOrders= JSON.parseArray(dto.getTradeOrders(),TradeOrder.class);
  186. if(tradeOrders!=null&&tradeOrders.size()>0){
  187. for(TradeOrder tradeOrder:tradeOrders){
  188. String[] order=tradeOrder.getSubMerchOrderNo().split("-");
  189. switch (order[0]) {
  190. case "store":
  191. orderService.payConfirm(1,null,order[1], tradeNo,dto.getBankTransactionId(),dto.getBankSerialNo());
  192. return "success";
  193. case "store_remain":
  194. orderService.payRemainConfirm( order[1], tradeNo,dto.getBankTransactionId(),dto.getBankSerialNo());
  195. return "success";
  196. case "payment":
  197. return storePaymentService.payConfirm(order[1], tradeNo,dto.getBankTransactionId(),dto.getBankSerialNo());
  198. }
  199. }
  200. }
  201. }
  202. return "success";
  203. }
  204. @ApiOperation("小雨点第三方退款回调")
  205. @PostMapping(value="/refundNotify")
  206. public String refundNotify(HttpServletRequest request, RefundNotifyDTO dto) throws Exception {
  207. if("SUCCESS".equals(dto.getOrderStatus())) {
  208. String[] orderIds=dto.getOrigMerchOrderNo().split("-");
  209. FsStorePayment storePayment=null;
  210. switch (orderIds[0]) {
  211. case "store":
  212. storePayment=storePaymentService.selectFsStorePaymentByCode(orderIds[1]);
  213. if(storePayment!=null){
  214. storePayment.setRefundMoney(BigDecimal.valueOf(Double.parseDouble(dto.getAmount())));
  215. storePayment.setStatus(-1);
  216. storePayment.setRefundTime(new Date());
  217. storePaymentService.updateFsStorePayment(storePayment);
  218. }
  219. return "success";
  220. case "store_remain":
  221. storePayment=storePaymentService.selectFsStorePaymentByCode(orderIds[1]);
  222. if(storePayment!=null){
  223. storePayment.setRefundMoney(BigDecimal.valueOf(Double.parseDouble(dto.getAmount())));
  224. storePayment.setStatus(-1);
  225. storePayment.setRefundTime(new Date());
  226. storePaymentService.updateFsStorePayment(storePayment);
  227. }
  228. return "success";
  229. case "doctor":
  230. return "success";
  231. case "payment":
  232. storePaymentService.refund(orderIds[1]);
  233. return "success";
  234. }
  235. return "success";
  236. }
  237. return "success";
  238. }
  239. // @Transactional
  240. // public String paymentOp(String payCode,String tradeNo,String bankTransactionId,String bankSerialNo) {
  241. //
  242. // //更新订单状态
  243. // FsStorePayment storePayment=storePaymentService.selectFsStorePaymentByCode(payCode);
  244. // if(!storePayment.getStatus().equals(0)){
  245. // return "";
  246. // }
  247. // storePayment.setStatus(1);
  248. // storePayment.setPayTime(new Date());
  249. // storePayment.setTradeNo(tradeNo);
  250. // storePayment.setBankSerialNo(bankSerialNo);
  251. // storePayment.setBankTransactionId(bankTransactionId);
  252. // storePaymentService.updateFsStorePayment(storePayment);
  253. // //增加佣金
  254. // if(storePayment.getCompanyId()!=null&&storePayment.getCompanyId()>0){
  255. // companyService.addCompanyPaymentMoney(storePayment);
  256. // }
  257. // return "success";
  258. //
  259. // }
  260. }