package com.demo.wjj.controller; import com.demo.wjj.bo.JsSdkResult; import com.demo.wjj.service.JsSdkService; import com.demo.wjj.utils.ApiResult; import org.apache.commons.lang3.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; /** * @author wangqing * @date 2018.12.02 */ @RequestMapping("/ticket") @RestController public class TicketController { private final Logger LOG = LoggerFactory.getLogger(getClass()); @Autowired private JsSdkService jsSdkService; /** * 获取ticket * @param agentId 商家id * @param url url * @return js-api 结果 */ @GetMapping("/getTicket") public ApiResult getTicket(@RequestParam(required = false) String agentId, @RequestParam(required = false) String url) { LOG.info("调用获取微信ticket(/ticket/getTicket)接口, agentId:{}, url:{}", agentId, url); if (StringUtils.isBlank(agentId)) { LOG.info("agentId为空"); return ApiResult.createFailure(); } if (StringUtils.isBlank(url)) { LOG.info("url为空"); return ApiResult.createFailure(); } try { final JsSdkResult jsSdkResult = jsSdkService.getJsSdkResult(agentId, url); ApiResult apiResult = jsSdkResult == null ? ApiResult.createFailure() : ApiResult.createSuccess(jsSdkResult); LOG.info("调用获取微信ticket(/ticket/getTicket)接口成功, apiResult:{}", apiResult); return apiResult; } catch (Exception e) { LOG.error("调用获取微信ticket(/ticket/getTicket)接口异常", e); return ApiResult.createFailure(); } } }