新增 微信第三方平台 获取令牌接口

This commit is contained in:
Lemon
2023-07-28 14:47:26 +08:00
parent 82a964d70e
commit 162dec41d4
6 changed files with 163 additions and 25 deletions

View File

@@ -1,8 +1,11 @@
package com.jsowell.api.uniapp;
import com.alibaba.fastjson2.JSONObject;
import com.jsowell.common.annotation.Anonymous;
import com.jsowell.common.core.controller.BaseController;
import com.jsowell.common.response.RestApiResponse;
import com.jsowell.pile.domain.AuthorizationEventResult;
import com.jsowell.pile.dto.GetComponentTokenDTO;
import com.jsowell.service.AgentDevService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
@@ -24,7 +27,16 @@ public class AgentDevController extends BaseController {
@Autowired
private AgentDevService agentDevService;
@ApiOperation(value = "授权事件接收URL,验证票据")
/**
* 授权事件接收URL,验证票据
* 微信平台 10 分钟推送一次
*
* @param timestamp
* @param nonce
* @param msgSignature
* @param postData
* @return
*/
@PostMapping("/platform/event")
public ResponseEntity<AuthorizationEventResult> wechatPlatformEvent(@RequestParam("timestamp") String timestamp,
@RequestParam("nonce") String nonce,
@@ -32,11 +44,11 @@ public class AgentDevController extends BaseController {
@RequestBody String postData) {
AuthorizationEventResult<String> resultBean = new AuthorizationEventResult<>();
ResponseEntity<AuthorizationEventResult> responseEntity;
logger.debug("授权事件接收URL,验证票据");
logger.info("授权事件接收URL,验证票据");
try {
resultBean.setData(agentDevService.parseRequest(timestamp,nonce,msgSignature,postData));
resultBean.setData(agentDevService.parseRequest(timestamp, nonce, msgSignature, postData));
responseEntity = new ResponseEntity<>(resultBean, HttpStatus.OK);
logger.debug("第三方平台授权事件接收URL,验证票据成功");
logger.info("第三方平台授权事件接收URL,验证票据成功");
} catch (Exception e) {
logger.error("第三方平台授权事件接收URL,验证票据异常", e.getMessage(), e);
AuthorizationEventResult<String> errorResultBean = new AuthorizationEventResult<>();
@@ -49,6 +61,25 @@ public class AgentDevController extends BaseController {
}
/**
* 获取微信第三方平台令牌
*
* @param dto
* @return
*/
@PostMapping("/getComponentToken")
public RestApiResponse<?> getComponentToken(GetComponentTokenDTO dto) {
logger.info("获取第三方平台令牌 params:{}", JSONObject.toJSONString(dto));
RestApiResponse<?> response = null;
try {
String componentToken = agentDevService.getComponentToken(dto);
response = new RestApiResponse<>(componentToken);
} catch (Exception e) {
logger.error("获取第三方平台令牌 error", e);
response = new RestApiResponse<>(e);
}
logger.info("获取第三方平台令牌 result:{}", response);
return response;
}
}