mirror of
https://codeup.aliyun.com/67c68d4e484ca2f0a13ac3c1/ydc/jsowell-charger-web.git
synced 2026-04-21 03:25:12 +08:00
130 lines
5.0 KiB
Java
130 lines
5.0 KiB
Java
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.agentDev.CommitCodeDTO;
|
|
import com.jsowell.pile.dto.agentDev.GetComponentTokenDTO;
|
|
import com.jsowell.pile.vo.agentDev.AuthInfo;
|
|
import com.jsowell.service.AgentDevService;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.http.HttpStatus;
|
|
import org.springframework.http.ResponseEntity;
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
/**
|
|
* 代开发小程序Controller
|
|
*
|
|
* @author Lemon
|
|
* @Date 2023/7/27 15:09
|
|
*/
|
|
@Anonymous
|
|
@RestController
|
|
@RequestMapping("/agentDev")
|
|
public class AgentDevController extends BaseController {
|
|
|
|
@Autowired
|
|
private AgentDevService agentDevService;
|
|
|
|
/**
|
|
* 授权事件接收URL,验证票据、授权事件
|
|
*
|
|
* @param timestamp
|
|
* @param nonce
|
|
* @param msgSignature
|
|
* @param postData
|
|
* @return
|
|
*/
|
|
@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;
|
|
logger.info("第三方平台授权事件接收URL params:{}", postData);
|
|
try {
|
|
resultBean.setData(agentDevService.parseRequest(timestamp, nonce, msgSignature, postData));
|
|
responseEntity = new ResponseEntity<>(resultBean, HttpStatus.OK);
|
|
logger.info("第三方平台授权事件接收URL success");
|
|
} catch (Exception e) {
|
|
logger.error("第三方平台授权事件接收URL error:{}", e.getMessage(), e);
|
|
AuthorizationEventResult<String> errorResultBean = new AuthorizationEventResult<>();
|
|
errorResultBean.setMsg("第三方平台授权事件接收URL error");
|
|
errorResultBean.setErrorMsg(e.getMessage());
|
|
errorResultBean.setCode(422);
|
|
responseEntity = new ResponseEntity<>(errorResultBean, HttpStatus.UNPROCESSABLE_ENTITY);
|
|
}
|
|
logger.info("第三方平台授权事件接收URL result:{}", resultBean);
|
|
return responseEntity;
|
|
}
|
|
|
|
|
|
/**
|
|
* 获取微信第三方平台令牌
|
|
*
|
|
* @param dto
|
|
* @return
|
|
*/
|
|
@PostMapping("/getComponentToken")
|
|
public RestApiResponse<?> getComponentToken(@RequestBody 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;
|
|
|
|
}
|
|
|
|
/**
|
|
* 使用授权码获取授权信息
|
|
*
|
|
* @param authorizationCode
|
|
* @return
|
|
*/
|
|
@GetMapping("/getAuthInfo/{authorizationCode}")
|
|
public RestApiResponse<?> getAuthInfo(@PathVariable("authorizationCode") String authorizationCode) {
|
|
logger.info("使用授权码获取授权信息 params:{}", authorizationCode);
|
|
RestApiResponse<?> response = null;
|
|
try {
|
|
AuthInfo authInfo = agentDevService.getAuthInfoByAuthCode(authorizationCode);
|
|
response = new RestApiResponse<>(authInfo);
|
|
} catch (Exception e) {
|
|
logger.error("使用授权码获取授权信息 error,", e);
|
|
response = new RestApiResponse<>(e);
|
|
}
|
|
logger.info("使用授权码获取授权信息 result:{}", response);
|
|
return response;
|
|
}
|
|
|
|
|
|
/**
|
|
* 提交代码并生成体验版小程序
|
|
*
|
|
* @param dto
|
|
* @return
|
|
*/
|
|
@PostMapping("/commitCode")
|
|
public RestApiResponse<?> commitCode(@RequestBody CommitCodeDTO dto) {
|
|
logger.info("提交代码并生成体验版小程序 params:{}", JSONObject.toJSONString(dto));
|
|
RestApiResponse<?> response = null;
|
|
try {
|
|
String commitResult = agentDevService.commitCode(dto);
|
|
response = new RestApiResponse<>(commitResult);
|
|
} catch (Exception e) {
|
|
logger.error("提交代码并生成体验版小程序 error,", e);
|
|
response = new RestApiResponse<>(e);
|
|
}
|
|
logger.info("提交代码并生成体验版小程序 result:{}", response);
|
|
return response;
|
|
}
|
|
}
|