WxApiController.java 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. package thyyxxk.wxservice_server.controller;
  2. import com.alibaba.fastjson.JSONObject;
  3. import lombok.extern.slf4j.Slf4j;
  4. import org.springframework.beans.factory.annotation.Autowired;
  5. import org.springframework.validation.annotation.Validated;
  6. import org.springframework.web.bind.annotation.*;
  7. import thyyxxk.wxservice_server.entity.ResultVo;
  8. import thyyxxk.wxservice_server.entity.appointment.DoctorInfo;
  9. import thyyxxk.wxservice_server.entity.appointment.WeChatPayParam;
  10. import thyyxxk.wxservice_server.entity.wxapi.*;
  11. import thyyxxk.wxservice_server.service.WxRefundService;
  12. import thyyxxk.wxservice_server.service.PushWxMessageService;
  13. import thyyxxk.wxservice_server.service.WxApiService;
  14. import thyyxxk.wxservice_server.utils.PropertiesUtil;
  15. import thyyxxk.wxservice_server.utils.ResultVoUtil;
  16. import javax.servlet.http.HttpServletRequest;
  17. import java.io.IOException;
  18. import java.util.Map;
  19. /**
  20. * @author dj
  21. */
  22. @Slf4j
  23. @RestController
  24. @RequestMapping("/wxApi")
  25. public class WxApiController {
  26. private final WxApiService service;
  27. private final WxRefundService refundService;
  28. private final PushWxMessageService pushWxMessageService;
  29. @Autowired
  30. public WxApiController(WxApiService payService, WxRefundService refundService, PushWxMessageService pushWxMessageService) {
  31. this.service = payService;
  32. this.refundService = refundService;
  33. this.pushWxMessageService = pushWxMessageService;
  34. }
  35. @GetMapping("/synchronizeAccessToken")
  36. public ResultVo<String> synchronizeAccessToken(@RequestParam("token") String token) {
  37. PropertiesUtil.writeAccessToken("access_token", token);
  38. return ResultVoUtil.success("同步成功。");
  39. }
  40. @GetMapping("/getJsApiSHA1")
  41. public ResultVo<JsApiSHA1> getJsApiSha1Sign(@RequestParam("url") String url) throws Exception {
  42. JsApiSHA1 data = new JsApiSHA1();
  43. data.setUrl(url);
  44. return service.getJsapiSHA1Sign(data);
  45. }
  46. @PostMapping("/createPayOrder")
  47. public ResultVo<WxPayOrder> createPayOrder(HttpServletRequest request,
  48. @RequestBody @Validated WeChatPayParam param) throws Exception {
  49. param.setClientIp(request.getRemoteAddr());
  50. return service.createPayOrder(param);
  51. }
  52. @GetMapping("/queryOrderState")
  53. public ResultVo<Object> queryOrderState(@RequestParam("tradeNo") String tradeNo) {
  54. return service.queryOrderState(tradeNo);
  55. }
  56. @GetMapping("/queryOrderStateOnly")
  57. public ResultVo<Object> queryOrderStateOnly(@RequestParam("tradeNo") String tradeNo) throws IOException {
  58. return service.queryOrderStateOnly(tradeNo);
  59. }
  60. @PostMapping("/genMzPayQrcode")
  61. public ResultVo<String> genMzPayQrcode(@RequestBody @Validated GenMzPayQrcodeParam param) throws Exception {
  62. return service.generateMzGuideBillPayQrcode(param);
  63. }
  64. @PostMapping("/pushMessage")
  65. public void pushMessage(@RequestBody @Validated PushMessageParam param) {
  66. pushWxMessageService.pushMessage2(param);
  67. }
  68. @PostMapping("/pushMessage2")
  69. public String pushMessage2(@RequestBody JSONObject param) {
  70. boolean result = pushWxMessageService.pushMessage2(param);
  71. return result ? "SUCCESS" : "FAIL";
  72. }
  73. @PostMapping("/getWxPayQrcode")
  74. public ResultVo<Map<String, String>> getWxPayQrcode(@RequestBody WxPyQrcdPrm prm) throws Exception {
  75. return service.getWxPayQrcode(prm);
  76. }
  77. @PostMapping("/closeWxOrder")
  78. public ResultVo<String> closeWxOrder(@RequestBody WxPayOrder order) throws Exception {
  79. return service.closeWxOrder(order);
  80. }
  81. @PostMapping("/refund")
  82. public ResultVo<String> refund(@RequestBody @Validated RfndPrm prm) {
  83. return refundService.refund(prm);
  84. }
  85. @GetMapping("/getDoctorInfo")
  86. public ResultVo<DoctorInfo> getDoctorInfo(@RequestParam("doctorCode") String doctorCode) {
  87. return service.getDoctorInfo(doctorCode);
  88. }
  89. }