2023-07-27 16:44:48 +08:00
|
|
|
package com.jsowell.api.uniapp;
|
|
|
|
|
|
2023-07-28 14:47:26 +08:00
|
|
|
import com.alibaba.fastjson2.JSONObject;
|
2023-07-27 16:44:48 +08:00
|
|
|
import com.jsowell.common.annotation.Anonymous;
|
|
|
|
|
import com.jsowell.common.core.controller.BaseController;
|
2023-07-28 14:47:26 +08:00
|
|
|
import com.jsowell.common.response.RestApiResponse;
|
2023-07-27 16:44:48 +08:00
|
|
|
import com.jsowell.pile.domain.AuthorizationEventResult;
|
2023-07-28 14:47:26 +08:00
|
|
|
import com.jsowell.pile.dto.GetComponentTokenDTO;
|
2023-07-27 16:44:48 +08:00
|
|
|
import com.jsowell.service.AgentDevService;
|
|
|
|
|
import io.swagger.annotations.ApiOperation;
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
import org.springframework.http.HttpStatus;
|
|
|
|
|
import org.springframework.http.ResponseEntity;
|
|
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
|
|
|
|
/**
|
2023-07-27 16:51:39 +08:00
|
|
|
* 代开发小程序Controller
|
2023-07-27 16:44:48 +08:00
|
|
|
*
|
|
|
|
|
* @author Lemon
|
|
|
|
|
* @Date 2023/7/27 15:09
|
|
|
|
|
*/
|
|
|
|
|
@Anonymous
|
|
|
|
|
@RestController
|
|
|
|
|
@RequestMapping("/agentDev")
|
|
|
|
|
public class AgentDevController extends BaseController {
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private AgentDevService agentDevService;
|
|
|
|
|
|
2023-07-28 14:47:26 +08:00
|
|
|
/**
|
2023-07-28 17:03:10 +08:00
|
|
|
* 授权事件接收URL,验证票据、
|
2023-07-28 14:47:26 +08:00
|
|
|
*
|
|
|
|
|
* @param timestamp
|
|
|
|
|
* @param nonce
|
|
|
|
|
* @param msgSignature
|
|
|
|
|
* @param postData
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
2023-07-27 16:44:48 +08:00
|
|
|
@PostMapping("/platform/event")
|
|
|
|
|
public ResponseEntity<AuthorizationEventResult> wechatPlatformEvent(@RequestParam("timestamp") String timestamp,
|
|
|
|
|
@RequestParam("nonce") String nonce,
|
|
|
|
|
@RequestParam("msg_signature") String msgSignature,
|
|
|
|
|
@RequestBody String postData) {
|
|
|
|
|
AuthorizationEventResult<String> resultBean = new AuthorizationEventResult<>();
|
|
|
|
|
ResponseEntity<AuthorizationEventResult> responseEntity;
|
2023-07-28 17:03:10 +08:00
|
|
|
logger.info("第三方平台授权事件接收URL params:{}", postData);
|
2023-07-27 16:44:48 +08:00
|
|
|
try {
|
2023-07-28 14:47:26 +08:00
|
|
|
resultBean.setData(agentDevService.parseRequest(timestamp, nonce, msgSignature, postData));
|
2023-07-27 16:44:48 +08:00
|
|
|
responseEntity = new ResponseEntity<>(resultBean, HttpStatus.OK);
|
2023-07-28 17:03:10 +08:00
|
|
|
logger.info("第三方平台授权事件接收URL success");
|
2023-07-27 16:44:48 +08:00
|
|
|
} catch (Exception e) {
|
2023-07-28 17:03:10 +08:00
|
|
|
logger.error("第三方平台授权事件接收URL error:{}", e.getMessage(), e);
|
2023-07-27 16:44:48 +08:00
|
|
|
AuthorizationEventResult<String> errorResultBean = new AuthorizationEventResult<>();
|
2023-07-28 17:03:10 +08:00
|
|
|
errorResultBean.setMsg("第三方平台授权事件接收URL error");
|
2023-07-27 16:44:48 +08:00
|
|
|
errorResultBean.setErrorMsg(e.getMessage());
|
|
|
|
|
errorResultBean.setCode(422);
|
|
|
|
|
responseEntity = new ResponseEntity<>(errorResultBean, HttpStatus.UNPROCESSABLE_ENTITY);
|
|
|
|
|
}
|
2023-07-28 17:03:10 +08:00
|
|
|
logger.info("第三方平台授权事件接收URL result:{}", resultBean);
|
2023-07-27 16:44:48 +08:00
|
|
|
return responseEntity;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2023-07-28 14:47:26 +08:00
|
|
|
/**
|
|
|
|
|
* 获取微信第三方平台令牌
|
|
|
|
|
*
|
|
|
|
|
* @param dto
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
@PostMapping("/getComponentToken")
|
2023-07-28 15:35:06 +08:00
|
|
|
public RestApiResponse<?> getComponentToken(@RequestBody GetComponentTokenDTO dto) {
|
2023-07-28 14:47:26 +08:00
|
|
|
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;
|
2023-07-27 16:44:48 +08:00
|
|
|
|
2023-07-28 14:47:26 +08:00
|
|
|
}
|
2023-07-27 16:44:48 +08:00
|
|
|
}
|