package thyyxxk.wxservice_server.controller; import com.alibaba.fastjson.JSONObject; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; import thyyxxk.wxservice_server.entity.ResultVo; import thyyxxk.wxservice_server.entity.appointment.DoctorInfo; import thyyxxk.wxservice_server.entity.appointment.WeChatPayParam; import thyyxxk.wxservice_server.entity.wxapi.*; import thyyxxk.wxservice_server.service.WxRefundService; import thyyxxk.wxservice_server.service.PushWxMessageService; import thyyxxk.wxservice_server.service.WxApiService; import thyyxxk.wxservice_server.utils.PropertiesUtil; import thyyxxk.wxservice_server.utils.ResultVoUtil; import javax.servlet.http.HttpServletRequest; import java.io.IOException; import java.util.Map; /** * @author dj */ @Slf4j @RestController @RequestMapping("/wxApi") public class WxApiController { private final WxApiService service; private final WxRefundService refundService; private final PushWxMessageService pushWxMessageService; @Autowired public WxApiController(WxApiService payService, WxRefundService refundService, PushWxMessageService pushWxMessageService) { this.service = payService; this.refundService = refundService; this.pushWxMessageService = pushWxMessageService; } @GetMapping("/synchronizeAccessToken") public ResultVo synchronizeAccessToken(@RequestParam("token") String token) { PropertiesUtil.writeAccessToken("access_token", token); return ResultVoUtil.success("同步成功。"); } @GetMapping("/getJsApiSHA1") public ResultVo getJsApiSha1Sign(@RequestParam("url") String url) throws Exception { JsApiSHA1 data = new JsApiSHA1(); data.setUrl(url); return service.getJsapiSHA1Sign(data); } @PostMapping("/createPayOrder") public ResultVo createPayOrder(HttpServletRequest request, @RequestBody @Validated WeChatPayParam param) throws Exception { param.setClientIp(request.getRemoteAddr()); return service.createPayOrder(param); } @GetMapping("/queryOrderState") public ResultVo queryOrderState(@RequestParam("tradeNo") String tradeNo) { return service.queryOrderState(tradeNo); } @GetMapping("/queryOrderStateOnly") public ResultVo queryOrderStateOnly(@RequestParam("tradeNo") String tradeNo) throws IOException { return service.queryOrderStateOnly(tradeNo); } @PostMapping("/genMzPayQrcode") public ResultVo genMzPayQrcode(@RequestBody @Validated GenMzPayQrcodeParam param) throws Exception { return service.generateMzGuideBillPayQrcode(param); } @PostMapping("/pushMessage") public void pushMessage(@RequestBody @Validated PushMessageParam param) { pushWxMessageService.pushMessage2(param); } @PostMapping("/pushMessage2") public String pushMessage2(@RequestBody JSONObject param) { boolean result = pushWxMessageService.pushMessage2(param); return result ? "SUCCESS" : "FAIL"; } @PostMapping("/getWxPayQrcode") public ResultVo> getWxPayQrcode(@RequestBody WxPyQrcdPrm prm) throws Exception { return service.getWxPayQrcode(prm); } @PostMapping("/closeWxOrder") public ResultVo closeWxOrder(@RequestBody WxPayOrder order) throws Exception { return service.closeWxOrder(order); } @PostMapping("/refund") public ResultVo refund(@RequestBody @Validated RfndPrm prm) { return refundService.refund(prm); } @GetMapping("/getDoctorInfo") public ResultVo getDoctorInfo(@RequestParam("doctorCode") String doctorCode) { return service.getDoctorInfo(doctorCode); } }