PayOrderApi.java 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. package com.caimei.controller;/*
  2. package com.caimei.controller;
  3. import com.alibaba.fastjson.JSON;
  4. import com.alibaba.fastjson.JSONObject;
  5. import com.caimei.model.ResponseJson;
  6. import com.caimei.model.dto.PaymentDto;
  7. import com.caimei.service.PayOrderService;
  8. import com.caimei.util.HttpRequest;
  9. import io.swagger.annotations.Api;
  10. import io.swagger.annotations.ApiOperation;
  11. import lombok.RequiredArgsConstructor;
  12. import lombok.extern.slf4j.Slf4j;
  13. import org.apache.commons.lang3.StringUtils;
  14. import org.springframework.beans.factory.annotation.Value;
  15. import org.springframework.http.HttpHeaders;
  16. import org.springframework.web.bind.annotation.*;
  17. import org.springframework.web.reactive.function.server.ServerRequest;
  18. import java.util.HashMap;
  19. import java.util.Map;
  20. */
  21. /**
  22. * Description
  23. *
  24. * @author : plf
  25. * @date : 2020/5/6
  26. *//*
  27. @Api(tags = "订单支付")
  28. @Slf4j
  29. @RestController
  30. @RequiredArgsConstructor
  31. @RequestMapping("/PayOrder")
  32. public class PayOrderApi {
  33. private final PayOrderService payOrderService;
  34. @Value("${caimei.notifyUrl}")
  35. private String notifyUrl;
  36. @Value("${wx.AppId}")
  37. private String appId;
  38. @Value("${wx.AppSecret}")
  39. private String appSecret;
  40. */
  41. /**
  42. * 获取线上支付开关状态
  43. *//*
  44. @ApiOperation("获取线上支付开关状态")
  45. @GetMapping("/onLineSwitch")
  46. public ResponseJson<Integer> onLineSwitch() {
  47. return payOrderService.getPayOnLineSwitch();
  48. }
  49. */
  50. /**
  51. * 微信线上支付
  52. *//*
  53. @ApiOperation("微信线上支付")
  54. @PostMapping("/miniWxPay")
  55. public ResponseJson<JSONObject> miniWxPay(@RequestBody PaymentDto payment, @RequestHeader HttpHeaders headers) {
  56. if (!"WEIXIN".equals(payment.getPayWay()) || payment.getPayAmount() == null || payment.getPayAmount() < 2) {
  57. return ResponseJson.error("参数异常", null);
  58. }
  59. String clientIp = headers.getFirst("X-CLIENT-IP");
  60. payment.setClientIp(clientIp);
  61. //小程序微信快捷支付
  62. payment.setPayType("MINIAPP_WEIXIN");
  63. String infos;
  64. try {
  65. // 获取当前微信小程序的环境
  66. String referer = headers.getFirst("Referer");
  67. log.info("referer-is----:" + referer);
  68. String requestUrl = "https://api.weixin.qq.com/sns/jscode2session";
  69. Map<String, String> requestUrlParam = new HashMap<String, String>(4);
  70. // 小程序appId
  71. requestUrlParam.put("appid", appId);
  72. // 小程序appSecret
  73. requestUrlParam.put("secret", appSecret);
  74. // 小程序端返回的code
  75. requestUrlParam.put("js_code", payment.getCode());
  76. // 默认参数
  77. requestUrlParam.put("grant_type", "authorization_code");
  78. // 发送post请求读取调用微信接口获取openid用户唯一标识
  79. infos = HttpRequest.sendPost(requestUrl, requestUrlParam);
  80. } catch (Exception e) {
  81. log.error("错误信息", e);
  82. return ResponseJson.error("wx小程序获取openid失败", null);
  83. }
  84. // 解析相应内容(转换成json对象)
  85. JSONObject jsonObject = JSON.parseObject(infos);
  86. String openId = jsonObject.getString("openid");
  87. String errCode = jsonObject.getString("errcode");
  88. String errMsg = jsonObject.getString("errmsg");
  89. boolean errFlag = StringUtils.isNotEmpty(errCode) && ("-1".equals(errCode) || "40029".equals(errCode) || "45011".equals(errCode));
  90. if (errFlag) {
  91. return ResponseJson.error(-1, errMsg, null);
  92. }
  93. if (openId == null) {
  94. return ResponseJson.error("wx获取openid失败", null);
  95. }
  96. payment.setOpenid(openId);
  97. payment.setNotifyUrl(notifyUrl);
  98. log.info("wx支付openid>>>>>" + openId);
  99. return payOrderService.pay(payment);
  100. }
  101. */
  102. /**
  103. * 支付异步通知回调
  104. *//*
  105. @GetMapping("/paymentCallback")
  106. public String paymentCallback(String data) throws Exception {
  107. log.info("异步回调通知>>>>>>>start");
  108. if (StringUtils.isBlank(data)) {
  109. return "回调参数失败";
  110. }
  111. return payOrderService.paymentCallback(data);
  112. }
  113. */
  114. /**
  115. * 判断此次支付是否完成
  116. *//*
  117. @ApiOperation("判断此次支付是否完成")
  118. @GetMapping("/payWhetherSuccess")
  119. public ResponseJson<String> payWhetherSuccess(Integer orderId, Integer paySuccessCounter) {
  120. if (null == orderId || null == paySuccessCounter) {
  121. return ResponseJson.error("参数异常", null);
  122. }
  123. return payOrderService.payWhetherSuccess(orderId, paySuccessCounter);
  124. }
  125. */
  126. /**
  127. * 查询本次支付订单是否完成
  128. *//*
  129. @GetMapping("/findOrderStatus")
  130. public ResponseJson<JSONObject> findOrderStatus(String mbOrderId) {
  131. if (null == mbOrderId) {
  132. return ResponseJson.error("参数异常", null);
  133. }
  134. return payOrderService.findOrderStatus(mbOrderId);
  135. }
  136. */
  137. /**
  138. * 延时分账异步通知回调
  139. *//*
  140. @GetMapping("/delayedSplittingCallback")
  141. public String delayedSplittingCallback(String data) {
  142. log.info("延时分账异步通知>>>>>>>start");
  143. if (StringUtils.isBlank(data)) {
  144. return "回调参数失败";
  145. }
  146. return payOrderService.delayedSplittingCallback(data);
  147. }
  148. }
  149. */