mirror of
https://codeup.aliyun.com/67c68d4e484ca2f0a13ac3c1/ydc/jsowell-charger-web.git
synced 2026-06-12 19:29:52 +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.core.controller.BaseController;
|
||||||
import com.jsowell.common.response.RestApiResponse;
|
import com.jsowell.common.response.RestApiResponse;
|
||||||
import com.jsowell.pile.domain.AuthorizationEventResult;
|
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.CommitCodeDTO;
|
||||||
import com.jsowell.pile.dto.agentDev.GetComponentTokenDTO;
|
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 com.jsowell.service.AgentDevService;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.http.HttpStatus;
|
import org.springframework.http.HttpStatus;
|
||||||
import org.springframework.http.ResponseEntity;
|
import org.springframework.http.ResponseEntity;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 代开发小程序Controller
|
* 代开发小程序Controller
|
||||||
*
|
*
|
||||||
@@ -95,8 +99,8 @@ public class AgentDevController extends BaseController {
|
|||||||
logger.info("使用授权码获取授权信息 params:{}", authorizationCode);
|
logger.info("使用授权码获取授权信息 params:{}", authorizationCode);
|
||||||
RestApiResponse<?> response = null;
|
RestApiResponse<?> response = null;
|
||||||
try {
|
try {
|
||||||
AuthInfo authInfo = agentDevService.getAuthInfoByAuthCode(authorizationCode);
|
AuthInfoVO authInfoVO = agentDevService.getAuthInfoByAuthCode(authorizationCode);
|
||||||
response = new RestApiResponse<>(authInfo);
|
response = new RestApiResponse<>(authInfoVO);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
logger.error("使用授权码获取授权信息 error,", e);
|
logger.error("使用授权码获取授权信息 error,", e);
|
||||||
response = new RestApiResponse<>(e);
|
response = new RestApiResponse<>(e);
|
||||||
@@ -126,4 +130,46 @@ public class AgentDevController extends BaseController {
|
|||||||
logger.info("提交代码并生成体验版小程序 result:{}", response);
|
logger.info("提交代码并生成体验版小程序 result:{}", response);
|
||||||
return 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;
|
package com.jsowell.service;
|
||||||
|
|
||||||
|
import com.alibaba.fastjson2.JSONArray;
|
||||||
import com.alibaba.fastjson2.JSONObject;
|
import com.alibaba.fastjson2.JSONObject;
|
||||||
import com.jsowell.common.constant.CacheConstants;
|
import com.jsowell.common.constant.CacheConstants;
|
||||||
import com.jsowell.common.core.redis.RedisCache;
|
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.AesException;
|
||||||
import com.jsowell.common.util.wxplatform.WXBizMsgCrypt;
|
import com.jsowell.common.util.wxplatform.WXBizMsgCrypt;
|
||||||
import com.jsowell.common.util.wxplatform.WXXmlToMapUtil;
|
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.domain.agentDev.CategoryInfo;
|
||||||
import com.jsowell.pile.dto.agentDev.CommitCodeDTO;
|
import com.jsowell.pile.dto.agentDev.CommitCodeDTO;
|
||||||
import com.jsowell.pile.dto.agentDev.GetComponentTokenDTO;
|
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.apache.commons.collections.MapUtils;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
@@ -219,7 +223,7 @@ public class AgentDevService {
|
|||||||
*
|
*
|
||||||
* @param authorizationCode
|
* @param authorizationCode
|
||||||
*/
|
*/
|
||||||
public AuthInfo getAuthInfoByAuthCode(String authorizationCode) {
|
public AuthInfoVO getAuthInfoByAuthCode(String authorizationCode) {
|
||||||
// 获取 component_access_token
|
// 获取 component_access_token
|
||||||
GetComponentTokenDTO dto = GetComponentTokenDTO.builder()
|
GetComponentTokenDTO dto = GetComponentTokenDTO.builder()
|
||||||
.appId(PLATFORM_APP_ID)
|
.appId(PLATFORM_APP_ID)
|
||||||
@@ -236,21 +240,21 @@ public class AgentDevService {
|
|||||||
|
|
||||||
String result = HttpUtils.sendPost(url, JSONObject.toJSONString(jsonObject));
|
String result = HttpUtils.sendPost(url, JSONObject.toJSONString(jsonObject));
|
||||||
logger.info("获取第三方平台 使用授权码获取授权信息 请求参数:{}, 请求结果:{}", JSONObject.toJSONString(jsonObject), result);
|
logger.info("获取第三方平台 使用授权码获取授权信息 请求参数:{}, 请求结果:{}", JSONObject.toJSONString(jsonObject), result);
|
||||||
AuthInfo authInfo = JSONObject.parseObject(result, AuthInfo.class);
|
AuthInfoVO authInfoVO = JSONObject.parseObject(result, AuthInfoVO.class);
|
||||||
if (authInfo == null) {
|
if (authInfoVO == null) {
|
||||||
throw new RuntimeException("获取第三方平台 使用授权码获取授权信息 error");
|
throw new RuntimeException("获取第三方平台 使用授权码获取授权信息 error");
|
||||||
}
|
}
|
||||||
String authorizerAccessToken = authInfo.getAuthorizerAccessToken(); // 接口调用令牌, 默认有效期 7200 秒
|
String authorizerAccessToken = authInfoVO.getAuthorizerAccessToken(); // 接口调用令牌, 默认有效期 7200 秒
|
||||||
String authorizerRefreshToken = authInfo.getAuthorizerRefreshToken(); // 刷新令牌 永久保存
|
String authorizerRefreshToken = authInfoVO.getAuthorizerRefreshToken(); // 刷新令牌 永久保存
|
||||||
String authorizerAppid = authInfo.getAuthorizerAppid(); // 授权方 appid
|
String authorizerAppid = authInfoVO.getAuthorizerAppid(); // 授权方 appid
|
||||||
|
|
||||||
String authAccessTokenKey = CacheConstants.AUTHORIZER_ACCESS_TOKEN + authorizerAppid;
|
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;
|
String authRefreshTokenKey = CacheConstants.AUTHORIZER_REFRESH_TOKEN + authorizerAppid;
|
||||||
redisCache.setCacheObject(authRefreshTokenKey, authorizerRefreshToken);
|
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) {
|
public List<CategoryInfo> getAllCategoryName(String authorizerAppid) {
|
||||||
String redisKey = CacheConstants.AUTHORIZER_ACCESS_TOKEN + authorizerAppid;
|
String redisKey = CacheConstants.AUTHORIZER_ACCESS_TOKEN + authorizerAppid;
|
||||||
String authAccessToken = redisCache.getCacheObject(redisKey);
|
String authAccessToken = redisCache.getCacheObject(redisKey);
|
||||||
@@ -300,14 +310,62 @@ public class AgentDevService {
|
|||||||
logger.error("获取第三方平台 获取类目名称信息 error:{}", resultJson.getString("errmsg"));
|
logger.error("获取第三方平台 获取类目名称信息 error:{}", resultJson.getString("errmsg"));
|
||||||
return new ArrayList<>();
|
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 static void main(String[] args) {
|
||||||
public String submitAudit() {
|
JSONArray array = new JSONArray();
|
||||||
|
array.set(0, "1");
|
||||||
|
array.set(1, "2");
|
||||||
return null;
|
array.set(2, "3");
|
||||||
|
List<String> list = array.toList(String.class);
|
||||||
|
System.out.println(list);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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;
|
||||||
|
}
|
||||||
@@ -1,10 +1,10 @@
|
|||||||
package com.jsowell.pile.vo.agentDev;
|
package com.jsowell.pile.domain.agentDev;
|
||||||
|
|
||||||
import com.alibaba.fastjson2.annotation.JSONField;
|
import com.alibaba.fastjson2.annotation.JSONField;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* TODO
|
* 权限集
|
||||||
*
|
*
|
||||||
* @author Lemon
|
* @author Lemon
|
||||||
* @Date 2023/7/29 9:24
|
* @Date 2023/7/29 9:24
|
||||||
@@ -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<AuditItem> auditItems;
|
||||||
|
}
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
package com.jsowell.pile.vo.agentDev;
|
package com.jsowell.pile.vo.agentDev;
|
||||||
|
|
||||||
import com.alibaba.fastjson2.annotation.JSONField;
|
import com.alibaba.fastjson2.annotation.JSONField;
|
||||||
|
import com.jsowell.pile.domain.agentDev.PermissionInfo;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -12,7 +13,7 @@ import java.util.List;
|
|||||||
* @Date 2023/7/29 9:18
|
* @Date 2023/7/29 9:18
|
||||||
*/
|
*/
|
||||||
@Data
|
@Data
|
||||||
public class AuthInfo {
|
public class AuthInfoVO {
|
||||||
/**
|
/**
|
||||||
* 授权方 appid
|
* 授权方 appid
|
||||||
*/
|
*/
|
||||||
Reference in New Issue
Block a user