mirror of
https://codeup.aliyun.com/67c68d4e484ca2f0a13ac3c1/ydc/jsowell-charger-web.git
synced 2026-04-22 12:05:05 +08:00
新增 微信第三方平台 提交代码审核接口
This commit is contained in:
@@ -5,15 +5,19 @@ 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.domain.agentDev.CategoryInfo;
|
||||
import com.jsowell.pile.dto.agentDev.CommitCodeDTO;
|
||||
import com.jsowell.pile.dto.agentDev.GetComponentTokenDTO;
|
||||
import com.jsowell.pile.vo.agentDev.AuthInfo;
|
||||
import com.jsowell.pile.dto.agentDev.SubmitAuditDTO;
|
||||
import com.jsowell.pile.vo.agentDev.AuthInfoVO;
|
||||
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.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 代开发小程序Controller
|
||||
*
|
||||
@@ -95,8 +99,8 @@ public class AgentDevController extends BaseController {
|
||||
logger.info("使用授权码获取授权信息 params:{}", authorizationCode);
|
||||
RestApiResponse<?> response = null;
|
||||
try {
|
||||
AuthInfo authInfo = agentDevService.getAuthInfoByAuthCode(authorizationCode);
|
||||
response = new RestApiResponse<>(authInfo);
|
||||
AuthInfoVO authInfoVO = agentDevService.getAuthInfoByAuthCode(authorizationCode);
|
||||
response = new RestApiResponse<>(authInfoVO);
|
||||
} catch (Exception e) {
|
||||
logger.error("使用授权码获取授权信息 error,", e);
|
||||
response = new RestApiResponse<>(e);
|
||||
@@ -126,4 +130,46 @@ public class AgentDevController extends BaseController {
|
||||
logger.info("提交代码并生成体验版小程序 result:{}", response);
|
||||
return response;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取类目列表
|
||||
*
|
||||
* @param authorizerAppid 用户授权的appid
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/getAllCategoryName/{authorizerAppid}")
|
||||
public RestApiResponse<?> getAllCategoryName(@PathVariable("authorizerAppid") String authorizerAppid) {
|
||||
logger.info("获取类目列表 params:{}", authorizerAppid);
|
||||
RestApiResponse<?> response = null;
|
||||
try {
|
||||
List<CategoryInfo> categoryInfos = agentDevService.getAllCategoryName(authorizerAppid);
|
||||
response = new RestApiResponse<>(categoryInfos);
|
||||
} catch (Exception e) {
|
||||
logger.error("获取类目列表 error,", e);
|
||||
response = new RestApiResponse<>(e);
|
||||
}
|
||||
logger.info("获取类目列表 result:{}", response);
|
||||
return response;
|
||||
}
|
||||
|
||||
/**
|
||||
* 提交代码审核
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("/submitAudit")
|
||||
public RestApiResponse<?> submitAudit(@RequestBody SubmitAuditDTO dto) {
|
||||
logger.info("提交代码审核 params:{}", JSONObject.toJSONString(dto));
|
||||
RestApiResponse<?> response = null;
|
||||
try {
|
||||
String result = agentDevService.submitAudit(dto);
|
||||
response = new RestApiResponse<>(result);
|
||||
} catch (Exception e) {
|
||||
logger.error("提交代码审核 error,", e);
|
||||
response = new RestApiResponse<>(e);
|
||||
}
|
||||
logger.info("提交代码审核 result:{}", response);
|
||||
return response;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.jsowell.service;
|
||||
|
||||
import com.alibaba.fastjson2.JSONArray;
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import com.jsowell.common.constant.CacheConstants;
|
||||
import com.jsowell.common.core.redis.RedisCache;
|
||||
@@ -8,10 +9,13 @@ import com.jsowell.common.util.http.HttpUtils;
|
||||
import com.jsowell.common.util.wxplatform.AesException;
|
||||
import com.jsowell.common.util.wxplatform.WXBizMsgCrypt;
|
||||
import com.jsowell.common.util.wxplatform.WXXmlToMapUtil;
|
||||
import com.jsowell.pile.domain.agentDev.AuditItem;
|
||||
import com.jsowell.pile.domain.agentDev.CategoryInfo;
|
||||
import com.jsowell.pile.dto.agentDev.CommitCodeDTO;
|
||||
import com.jsowell.pile.dto.agentDev.GetComponentTokenDTO;
|
||||
import com.jsowell.pile.vo.agentDev.AuthInfo;
|
||||
import com.jsowell.pile.dto.agentDev.SubmitAuditDTO;
|
||||
import com.jsowell.pile.vo.agentDev.AuthInfoVO;
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
import org.apache.commons.collections.MapUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
@@ -219,7 +223,7 @@ public class AgentDevService {
|
||||
*
|
||||
* @param authorizationCode
|
||||
*/
|
||||
public AuthInfo getAuthInfoByAuthCode(String authorizationCode) {
|
||||
public AuthInfoVO getAuthInfoByAuthCode(String authorizationCode) {
|
||||
// 获取 component_access_token
|
||||
GetComponentTokenDTO dto = GetComponentTokenDTO.builder()
|
||||
.appId(PLATFORM_APP_ID)
|
||||
@@ -236,21 +240,21 @@ public class AgentDevService {
|
||||
|
||||
String result = HttpUtils.sendPost(url, JSONObject.toJSONString(jsonObject));
|
||||
logger.info("获取第三方平台 使用授权码获取授权信息 请求参数:{}, 请求结果:{}", JSONObject.toJSONString(jsonObject), result);
|
||||
AuthInfo authInfo = JSONObject.parseObject(result, AuthInfo.class);
|
||||
if (authInfo == null) {
|
||||
AuthInfoVO authInfoVO = JSONObject.parseObject(result, AuthInfoVO.class);
|
||||
if (authInfoVO == null) {
|
||||
throw new RuntimeException("获取第三方平台 使用授权码获取授权信息 error");
|
||||
}
|
||||
String authorizerAccessToken = authInfo.getAuthorizerAccessToken(); // 接口调用令牌, 默认有效期 7200 秒
|
||||
String authorizerRefreshToken = authInfo.getAuthorizerRefreshToken(); // 刷新令牌 永久保存
|
||||
String authorizerAppid = authInfo.getAuthorizerAppid(); // 授权方 appid
|
||||
String authorizerAccessToken = authInfoVO.getAuthorizerAccessToken(); // 接口调用令牌, 默认有效期 7200 秒
|
||||
String authorizerRefreshToken = authInfoVO.getAuthorizerRefreshToken(); // 刷新令牌 永久保存
|
||||
String authorizerAppid = authInfoVO.getAuthorizerAppid(); // 授权方 appid
|
||||
|
||||
String authAccessTokenKey = CacheConstants.AUTHORIZER_ACCESS_TOKEN + authorizerAppid;
|
||||
redisCache.setCacheObject(authAccessTokenKey, authorizerAccessToken, authInfo.getExpiredTime(), TimeUnit.SECONDS);
|
||||
redisCache.setCacheObject(authAccessTokenKey, authorizerAccessToken, authInfoVO.getExpiredTime(), TimeUnit.SECONDS);
|
||||
|
||||
String authRefreshTokenKey = CacheConstants.AUTHORIZER_REFRESH_TOKEN + authorizerAppid;
|
||||
redisCache.setCacheObject(authRefreshTokenKey, authorizerRefreshToken);
|
||||
|
||||
return authInfo;
|
||||
return authInfoVO;
|
||||
}
|
||||
|
||||
|
||||
@@ -283,6 +287,12 @@ public class AgentDevService {
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取类目列表
|
||||
*
|
||||
* @param authorizerAppid 用户appid
|
||||
* @return
|
||||
*/
|
||||
public List<CategoryInfo> getAllCategoryName(String authorizerAppid) {
|
||||
String redisKey = CacheConstants.AUTHORIZER_ACCESS_TOKEN + authorizerAppid;
|
||||
String authAccessToken = redisCache.getCacheObject(redisKey);
|
||||
@@ -300,14 +310,62 @@ public class AgentDevService {
|
||||
logger.error("获取第三方平台 获取类目名称信息 error:{}", resultJson.getString("errmsg"));
|
||||
return new ArrayList<>();
|
||||
}
|
||||
return null;
|
||||
// 将 jsonArray 转成 List
|
||||
JSONArray categoryList = resultJson.getJSONArray("category_list");
|
||||
List<CategoryInfo> categoryInfos = categoryList.toList(CategoryInfo.class);
|
||||
if (CollectionUtils.isEmpty(categoryInfos)) {
|
||||
logger.info("获取第三方平台 获取类目名称信息 error");
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
return categoryInfos;
|
||||
}
|
||||
|
||||
/**
|
||||
* 提交代码审核
|
||||
*
|
||||
* @param dto
|
||||
* @return
|
||||
*/
|
||||
public String submitAudit(SubmitAuditDTO dto) {
|
||||
String redisKey = CacheConstants.AUTHORIZER_ACCESS_TOKEN + dto.getAuthorizerAppid();
|
||||
String authAccessToken = redisCache.getCacheObject(redisKey);
|
||||
if (StringUtils.isBlank(authAccessToken)) {
|
||||
throw new RuntimeException("微信第三方平台 提交代码审核 error: authAccessToken为空");
|
||||
}
|
||||
List<AuditItem> itemList = dto.getAuditItems();
|
||||
String url = "https://api.weixin.qq.com/wxa/submit_audit?access_token=" + authAccessToken;
|
||||
|
||||
// List --> JsonArray
|
||||
JSONArray itemArray = JSONArray.parseArray(JSONObject.toJSONString(itemList));
|
||||
// 发送请求
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
jsonObject.put("item_list", itemArray);
|
||||
|
||||
String result = HttpUtils.sendPost(url, JSONObject.toJSONString(jsonObject));
|
||||
logger.info("微信第三方平台 提交代码审核 请求参数:{}, 请求结果:{}", JSONObject.toJSONString(jsonObject), result);
|
||||
// 将返回结果转为json对象
|
||||
JSONObject resultJson = JSONObject.parseObject(result);
|
||||
int errCode = (int) resultJson.get("errcode");
|
||||
if (errCode != 0) {
|
||||
String errMsg = resultJson.getString("errmsg");
|
||||
logger.info("微信第三方平台 提交代码审核 error, {}", errMsg);
|
||||
|
||||
return errMsg;
|
||||
}
|
||||
// 获取审核编码并返回
|
||||
long auditId = (long) resultJson.get("auditid");
|
||||
|
||||
return String.valueOf(auditId);
|
||||
}
|
||||
|
||||
|
||||
|
||||
public String submitAudit() {
|
||||
|
||||
|
||||
return null;
|
||||
public static void main(String[] args) {
|
||||
JSONArray array = new JSONArray();
|
||||
array.set(0, "1");
|
||||
array.set(1, "2");
|
||||
array.set(2, "3");
|
||||
List<String> list = array.toList(String.class);
|
||||
System.out.println(list);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user