diff --git a/jsowell-admin/src/main/java/com/jsowell/api/uniapp/AgentDevController.java b/jsowell-admin/src/main/java/com/jsowell/api/uniapp/AgentDevController.java index 01768fc4f..08c6b2ed8 100644 --- a/jsowell-admin/src/main/java/com/jsowell/api/uniapp/AgentDevController.java +++ b/jsowell-admin/src/main/java/com/jsowell/api/uniapp/AgentDevController.java @@ -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 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; + } + } diff --git a/jsowell-admin/src/main/java/com/jsowell/service/AgentDevService.java b/jsowell-admin/src/main/java/com/jsowell/service/AgentDevService.java index c9e570591..15f3e05ea 100644 --- a/jsowell-admin/src/main/java/com/jsowell/service/AgentDevService.java +++ b/jsowell-admin/src/main/java/com/jsowell/service/AgentDevService.java @@ -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 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 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 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 list = array.toList(String.class); + System.out.println(list); } } diff --git a/jsowell-pile/src/main/java/com/jsowell/pile/domain/agentDev/AuditItem.java b/jsowell-pile/src/main/java/com/jsowell/pile/domain/agentDev/AuditItem.java new file mode 100644 index 000000000..c0201f53e --- /dev/null +++ b/jsowell-pile/src/main/java/com/jsowell/pile/domain/agentDev/AuditItem.java @@ -0,0 +1,66 @@ +package com.jsowell.pile.domain.agentDev; + +import lombok.Data; + +/** + * 审核项目 + * + * @author Lemon + * @Date 2023/7/29 15:37 + */ +@Data +public class AuditItem { + /** + * 小程序的页面 N + * 可通过"获取小程序的页面列表getCodePage"接口获得 + */ + private String address; + + /** + * 小程序的标签 N + * 用空格分隔,标签至多 10 个,标签长度至多 20 + */ + private String tag; + + /** + * 一级类目名称 Y + * 可通过"getAllCategoryName"接口获取 + */ + private String first_class; + + /** + * 二级类目名称 Y + * 可通过"getAllCategoryName"接口获取 + */ + private String second_class; + + /** + * 三级类目名称 N + * 可通过"getAllCategoryName"接口获取 + */ + private String third_class; + + /** + * 小程序页面的标题 N + * 标题长度至多 32 + */ + private String title; + + /** + * 一级类目id Y + * 可通过"getAllCategoryName"接口获取 + */ + private String first_id; + + /** + * 二级类目id Y + * 可通过"getAllCategoryName"接口获取 + */ + private String second_id; + + /** + * 三级类目id Y + * 可通过"getAllCategoryName"接口获取 + */ + private String third_id; +} diff --git a/jsowell-pile/src/main/java/com/jsowell/pile/vo/agentDev/PermissionInfo.java b/jsowell-pile/src/main/java/com/jsowell/pile/domain/agentDev/PermissionInfo.java similarity index 83% rename from jsowell-pile/src/main/java/com/jsowell/pile/vo/agentDev/PermissionInfo.java rename to jsowell-pile/src/main/java/com/jsowell/pile/domain/agentDev/PermissionInfo.java index e23130a97..4e0b15900 100644 --- a/jsowell-pile/src/main/java/com/jsowell/pile/vo/agentDev/PermissionInfo.java +++ b/jsowell-pile/src/main/java/com/jsowell/pile/domain/agentDev/PermissionInfo.java @@ -1,10 +1,10 @@ -package com.jsowell.pile.vo.agentDev; +package com.jsowell.pile.domain.agentDev; import com.alibaba.fastjson2.annotation.JSONField; import lombok.Data; /** - * TODO + * 权限集 * * @author Lemon * @Date 2023/7/29 9:24 diff --git a/jsowell-pile/src/main/java/com/jsowell/pile/dto/agentDev/SubmitAuditDTO.java b/jsowell-pile/src/main/java/com/jsowell/pile/dto/agentDev/SubmitAuditDTO.java new file mode 100644 index 000000000..ec87d795a --- /dev/null +++ b/jsowell-pile/src/main/java/com/jsowell/pile/dto/agentDev/SubmitAuditDTO.java @@ -0,0 +1,25 @@ +package com.jsowell.pile.dto.agentDev; + +import com.alibaba.fastjson2.annotation.JSONField; +import com.jsowell.pile.domain.agentDev.AuditItem; +import lombok.Data; + +import java.util.List; + +/** + * 提交代码审核DTO + * + * @author Lemon + * @Date 2023/7/29 15:29 + */ +@Data +public class SubmitAuditDTO { + + /** + * 用户授权的appid + */ + private String authorizerAppid; + + // 审核项列表 + private List auditItems; +} diff --git a/jsowell-pile/src/main/java/com/jsowell/pile/vo/agentDev/AuthInfo.java b/jsowell-pile/src/main/java/com/jsowell/pile/vo/agentDev/AuthInfoVO.java similarity index 93% rename from jsowell-pile/src/main/java/com/jsowell/pile/vo/agentDev/AuthInfo.java rename to jsowell-pile/src/main/java/com/jsowell/pile/vo/agentDev/AuthInfoVO.java index 5bbf4bff9..17a97e3a7 100644 --- a/jsowell-pile/src/main/java/com/jsowell/pile/vo/agentDev/AuthInfo.java +++ b/jsowell-pile/src/main/java/com/jsowell/pile/vo/agentDev/AuthInfoVO.java @@ -1,6 +1,7 @@ package com.jsowell.pile.vo.agentDev; import com.alibaba.fastjson2.annotation.JSONField; +import com.jsowell.pile.domain.agentDev.PermissionInfo; import lombok.Data; import java.util.List; @@ -12,7 +13,7 @@ import java.util.List; * @Date 2023/7/29 9:18 */ @Data -public class AuthInfo { +public class AuthInfoVO { /** * 授权方 appid */