新增 微信第三方平台 提交代码审核接口

This commit is contained in:
Lemon
2023-07-29 16:09:04 +08:00
parent 47d7b3f84b
commit 3ee5d726b8
6 changed files with 217 additions and 21 deletions

View File

@@ -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);
}
}