diff --git a/api/src/main/resources/application.yaml b/api/src/main/resources/application.yaml index 4a08b360..0929e1ce 100644 --- a/api/src/main/resources/application.yaml +++ b/api/src/main/resources/application.yaml @@ -59,6 +59,12 @@ spring: - Path=/api/pdd-api/** filters: - StripPrefix=2 + - id: wei_api_route + uri: lb://wei-api + predicates: + - Path=/api/wei-api/** + filters: + - StripPrefix=2 # - TokenFilter # default-filters: # - TokenFilter diff --git a/core/common/src/main/java/com/qihang/common/enums/EnumShopType.java b/core/common/src/main/java/com/qihang/common/enums/EnumShopType.java index 2ec3922d..343c1f08 100644 --- a/core/common/src/main/java/com/qihang/common/enums/EnumShopType.java +++ b/core/common/src/main/java/com/qihang/common/enums/EnumShopType.java @@ -11,6 +11,7 @@ public enum EnumShopType { TAO("淘宝天猫", 1), JD("京东", 2), DOUDIAN("抖音", 3), + WEI("微信视频号小店", 5), PDD("拼多多", 4); private String name; private int index; diff --git a/doc/sql/qihang-oms.sql b/doc/sql/qihang-oms.sql index 51def96a..a07da41a 100644 --- a/doc/sql/qihang-oms.sql +++ b/doc/sql/qihang-oms.sql @@ -11,7 +11,7 @@ Target Server Version : 80200 File Encoding : 65001 - Date: 24/03/2024 17:06:44 + Date: 24/03/2024 18:21:33 */ SET NAMES utf8mb4; @@ -2267,10 +2267,11 @@ CREATE TABLE `sys_platform` ( -- ---------------------------- -- Records of sys_platform -- ---------------------------- -INSERT INTO `sys_platform` VALUES (1, '天猫', 'TMALL', '', NULL, NULL, NULL); -INSERT INTO `sys_platform` VALUES (2, '京东', 'JD', '', NULL, NULL, NULL); -INSERT INTO `sys_platform` VALUES (3, '抖店', 'DOUDIAN', '', NULL, NULL, NULL); -INSERT INTO `sys_platform` VALUES (4, '拼多多', 'PDD', '', NULL, NULL, NULL); +INSERT INTO `sys_platform` VALUES (1, '天猫', 'TMALL', '12175777', '368dbbd183a77d551735be13f59bbcda', '', 'http://gw.api.taobao.com/router/rest'); +INSERT INTO `sys_platform` VALUES (2, '京东', 'JD', 'FB4CC3688E6F9065D4FF510A53BB60FF', '40e8c8b2427f4e6db8f4a39af27d719e', 'http://www.qumei.com', 'https://api.jd.com/routerjson'); +INSERT INTO `sys_platform` VALUES (3, '抖店', 'DOUDIAN', '7344938657423296019', '4e704882-832a-42e5-845f-6af991ce0ce2', '', NULL); +INSERT INTO `sys_platform` VALUES (4, '拼多多', 'PDD', 'b92194d1af904c8a86a2c9eff6f9bfb0', '8da714f8dcbfb12d3972626ef8acfc0737aacecb', 'http://www.qumei.com', NULL); +INSERT INTO `sys_platform` VALUES (5, '微信视频号小店', 'WEI', NULL, NULL, NULL, 'https://api.weixin.qq.com'); -- ---------------------------- -- Table structure for sys_shop @@ -2300,11 +2301,11 @@ CREATE TABLE `sys_shop` ( -- ---------------------------- -- Records of sys_shop -- ---------------------------- -INSERT INTO `sys_shop` VALUES (1, '天猫旗舰店', 1, '', 98, 1, 0, '', 0, '', '', '', NULL, NULL, NULL, NULL, 'http://gw.api.taobao.com/router/rest'); -INSERT INTO `sys_shop` VALUES (2, '京东旗舰店', 2, NULL, 9, 1, 0, NULL, 0, NULL, NULL, '', 31535999, NULL, '919b21a3b9d247d08d7701cb8bcc2432ote5', NULL, NULL); -INSERT INTO `sys_shop` VALUES (3, '抖音旗舰店', 3, 'http://openapi.jinritemai.com', 87, 1, 1653672695, NULL, 0, '', '', '', NULL, NULL, NULL, NULL, '2'); -INSERT INTO `sys_shop` VALUES (5, '拼多多旗舰店', 4, NULL, 99, 1, 1680698886, 'pdd10006159121', 0, NULL, NULL, '', NULL, NULL, NULL, NULL, NULL); -INSERT INTO `sys_shop` VALUES (6, '视频号小店', 5, NULL, 9, 0, 0, NULL, 0, 'wx2b826d52663c3ac5', '680867143a2cdf9caa350c947df76c37', '78_Dlbnrt1yqBv0C2ThdK5k80vh3Agg-sdgg0AvgEp6J28aiDQ0tlMteFHaLIr0sle-UXMiNBTkqzgdme-Z1zGR3XkCxGP4afeT9mB-mZPzWI6QE7Vdl6HwOv7tgY0FVZfADAZPT', NULL, NULL, NULL, NULL, NULL); +INSERT INTO `sys_shop` VALUES (1, '天猫旗舰店AB', 1, '', 98, 1, 0, '', 59972781, '31014100', '7b0769269b0c0ca88949791c14eb3a5c', '6102522199aaa4a42a2e6be95d0a5e18657c1576ec563a0351855490', NULL, NULL, NULL, NULL, 'http://gw.api.taobao.com/router/rest'); +INSERT INTO `sys_shop` VALUES (2, '京东旗舰店', 2, NULL, 9, 1, 0, NULL, 10706, NULL, NULL, '8abd974c62c34778935b34b5952e6f68izdk', 31535999, NULL, '919b21a3b9d247d08d7701cb8bcc2432ote5', NULL, NULL); +INSERT INTO `sys_shop` VALUES (3, '抖音旗舰店', 3, 'http://openapi.jinritemai.com', 87, 1, 1653672695, NULL, 90158786, '7249607407477720636', '36a12497-fb9d-4b54-8cd1-fd1617346687', '', NULL, NULL, NULL, NULL, '2'); +INSERT INTO `sys_shop` VALUES (4, '拼多多旗舰店', 4, NULL, 99, 1, 1680698886, '', 100061591, NULL, NULL, '87f8044d2a5f45a489aa3a952785b0d35e61788a', NULL, NULL, NULL, NULL, NULL); +INSERT INTO `sys_shop` VALUES (5, '视频号小店', 5, NULL, 9, 0, 0, NULL, 0, 'wx2b826d52663c3ac5', '680867143a2cdf9caa350c947df76c37', '78_xn2z6F4-Eq8OeElAYhn0PKCfAhcOfrS4M47w8xybtFThM2jusDxoVDPBY8XJDQ2q5-aTaSlHjiSuKotZPpYY1SH_w8E_VE8EeD0dc3ABVLfH1Eu1PJZvOYNIjbYMSFgAHASYL', NULL, NULL, NULL, NULL, NULL); -- ---------------------------- -- Table structure for sys_shop_pull_lasttime @@ -2432,7 +2433,7 @@ CREATE TABLE `sys_user` ( -- ---------------------------- -- Records of sys_user -- ---------------------------- -INSERT INTO `sys_user` VALUES (1, 103, 'admin', '启航oms', '00', '280645618@qq.com', '15888888888', '1', '', '$2a$10$7JB720yubVSZvUI0rEqK/.VqGOZTH.ulu33dHOiBE8ByOhJIrdAu2', '0', '0', '127.0.0.1', '2024-03-24 16:56:36', 'admin', '2023-08-07 19:31:37', '', '2024-03-24 16:56:35', '管理员'); +INSERT INTO `sys_user` VALUES (1, 103, 'admin', '启航oms', '00', '280645618@qq.com', '15888888888', '1', '', '$2a$10$7JB720yubVSZvUI0rEqK/.VqGOZTH.ulu33dHOiBE8ByOhJIrdAu2', '0', '0', '127.0.0.1', '2024-03-24 17:46:21', 'admin', '2023-08-07 19:31:37', '', '2024-03-24 17:46:21', '管理员'); INSERT INTO `sys_user` VALUES (100, NULL, 'qlp', 'a', '00', '', '15818590119', '0', '', '$2a$10$5YEoazvKfi3TTfvduAe8mOT5dtV7W4EeJo5x5T.4P0yOTBms2BDmy', '0', '0', '', NULL, 'admin', '2024-03-17 14:55:22', '', NULL, NULL); -- ---------------------------- diff --git a/dou-api/src/main/java/com/qihang/dou/service/impl/SysUserServiceImpl.java b/dou-api/src/main/java/com/qihang/dou/service/impl/SysUserServiceImpl.java index 240dd152..889dc235 100644 --- a/dou-api/src/main/java/com/qihang/dou/service/impl/SysUserServiceImpl.java +++ b/dou-api/src/main/java/com/qihang/dou/service/impl/SysUserServiceImpl.java @@ -290,4 +290,9 @@ public class SysUserServiceImpl implements ISysUserService return userMapper.deleteUserById(userId); } + @Override + public void checkUserDataScope(Long userId) { + + } + } diff --git a/pdd-api/src/main/java/com/qihang/pdd/controller/AjaxOrderPddController.java b/pdd-api/src/main/java/com/qihang/pdd/controller/AjaxOrderPddController.java index 62da54f0..fc32d9a5 100644 --- a/pdd-api/src/main/java/com/qihang/pdd/controller/AjaxOrderPddController.java +++ b/pdd-api/src/main/java/com/qihang/pdd/controller/AjaxOrderPddController.java @@ -9,7 +9,9 @@ import com.pdd.pop.sdk.http.api.pop.request.PddPopAuthTokenRefreshRequest; import com.pdd.pop.sdk.http.api.pop.response.PddOrderListGetResponse; import com.pdd.pop.sdk.http.api.pop.response.PddPopAuthTokenRefreshResponse; import com.pdd.pop.sdk.http.token.AccessTokenResponse; -import com.qihang.common.common.ApiResult; +import com.qihang.common.common.AjaxResult; +import com.qihang.common.common.ResultVo; +import com.qihang.common.common.ResultVoEnum; import com.qihang.common.enums.EnumShopType; import com.qihang.common.enums.HttpStatus; import com.qihang.pdd.domain.SysPlatform; @@ -49,29 +51,29 @@ public class AjaxOrderPddController { * @throws Exception */ @RequestMapping(value = "/pull_order", method = RequestMethod.POST) - public ApiResult getOrderList(@RequestBody OpenApiRequest reqData) + public AjaxResult getOrderList(@RequestBody OpenApiRequest reqData) throws Exception { Integer updType = reqData.getUpdType();//更新类型0拉取新订单1更新订单 String startDate = reqData.getStartDate();//reqData.getString("startTime"); String endDate = reqData.getEndDate();//reqData.getString("endTime"); var shop = shopService.selectShopById(reqData.getShopId()); - if(shop == null) return ApiResult.build(HttpStatus.PARAMS_ERROR, "店铺不存在!"); + if(shop == null) AjaxResult.error(HttpStatus.PARAMS_ERROR, "店铺不存在!"); if (shop.getType() != EnumShopType.PDD.getIndex()) { - return ApiResult.build(HttpStatus.PARAMS_ERROR, "参数错误,店铺不是PDD店铺"); + return AjaxResult.error(HttpStatus.PARAMS_ERROR, "参数错误,店铺不是PDD店铺"); } SysPlatform platform = platformService.selectById(EnumShopType.PDD.getIndex()); if(!StringUtils.hasText(platform.getAppKey())) { - return ApiResult.build(HttpStatus.PARAMS_ERROR, "平台配置错误,没有找到AppKey"); + return AjaxResult.error(HttpStatus.PARAMS_ERROR, "平台配置错误,没有找到AppKey"); } if(!StringUtils.hasText(platform.getAppSecret())) { - return ApiResult.build(HttpStatus.PARAMS_ERROR, "第三方平台配置错误,没有找到AppSercet"); - } - if(!StringUtils.hasText(platform.getRedirectUri())) { - return ApiResult.build(HttpStatus.PARAMS_ERROR, "第三方平台配置错误,没有找到RedirectUri"); + return AjaxResult.error(HttpStatus.PARAMS_ERROR, "第三方平台配置错误,没有找到AppSercet"); } +// if(!StringUtils.hasText(platform.getRedirectUri())) { +// return AjaxResult.error(HttpStatus.PARAMS_ERROR, "第三方平台配置错误,没有找到RedirectUri"); +// } // if(!StringUtils.hasText(platform.getServerUrl())) { // return ApiResult.build(HttpStatus.PARAMS_ERROR, "第三方平台配置错误,没有找到ServerUrl"); // } @@ -91,16 +93,16 @@ public class AjaxOrderPddController { params.setAccessToken(shop.getAccessToken()); params.setTokenRequestUrl("http://localhost:3000/pdd_api2/oauth"); params.setApiRequestUrl(shop.getApiRequestUrl()); - String url = "https://mms.pinduoduo.com/open.html?response_type=code&client_id=" + params.getAppKey() + "&redirect_uri=" + URLEncoder.encode(platform.getRedirectUri()); +// String url = "https://mms.pinduoduo.com/open.html?response_type=code&client_id=" + params.getAppKey() + "&redirect_uri=" + URLEncoder.encode(platform.getRedirectUri()); String accessToken = params.getAccessToken(); if(!StringUtils.hasText(accessToken)) { - return ApiResult.build(HttpStatus.PARAMS_ERROR, "参数错误:accessToken为空"); + return AjaxResult.error(HttpStatus.PARAMS_ERROR, "参数错误:accessToken为空"); } // if(!StringUtils.hasText(accessToken)) return new ApiResult<>(EnumResultVo.TokenFail.getIndex(), "参数错误:accessToken为空",params); // 获取店铺信息,判断店铺是否一致 var shopResult = PddApiUtils.getShopInfo(params.getAppKey(), params.getAppSecret(), accessToken); - if (shopResult.getCode() != HttpStatus.SUCCESS) { + if (shopResult.getCode() != ResultVoEnum.SUCCESS.getIndex()) { // if(shopResult.getCode() == HttpStatus.UNAUTHORIZED){ // // 生成AccessToken // PopAccessTokenClient accessTokenClient = new PopAccessTokenClient(params.getAppKey(), params.getAppSecret()); @@ -117,7 +119,7 @@ public class AjaxOrderPddController { // e.printStackTrace(); // } // } - return ApiResult.build(shopResult.getCode(), shopResult.getMsg(), params); + return AjaxResult.error(shopResult.getCode(), shopResult.getMsg(), params); }else{ // 看看是否需要刷新一下token PopClient client = new PopHttpClient(params.getAppKey(), params.getAppSecret()); @@ -130,10 +132,10 @@ public class AjaxOrderPddController { } if (shopResult.getData().getMallId().longValue() != shop.getSellerId().longValue()) { - return ApiResult.build(HttpStatus.UNAUTHORIZED, "该店铺不是授权店铺",params); + return AjaxResult.error(HttpStatus.UNAUTHORIZED, "该店铺不是授权店铺",params); } - ApiResult result = null;// 返回结果 + ResultVo result = null;// 返回结果 Long endTime = System.currentTimeMillis() / 1000;// 订单更新结束时间(默认值) Long startTime = endTime - 60 * 60 * 24 + 10;// 订单更新开始时间(默认值) @@ -193,7 +195,7 @@ public class AjaxOrderPddController { failCount += result.getData().getFailCount(); // log.info("查询到数据:"+result.getData().getTotalRecords()); } else if (result.getCode() > 0) - return ApiResult.build(result.getCode(), result.getMsg()); + return AjaxResult.error(result.getCode(), result.getMsg()); // 计算总页数 int totalPage = (result.getData().getTotalRecords() % pageSize == 0) ? result.getData().getTotalRecords() / pageSize @@ -229,9 +231,9 @@ public class AjaxOrderPddController { * log.info("添加更新日志错误"); } */ if (result.getCode() == 0) - return ApiResult.build(HttpStatus.SUCCESS, "SUCCESS"); + return AjaxResult.success(); else - return ApiResult.build(result.getCode(), result.getMsg()); + return AjaxResult.error(result.getCode(), result.getMsg()); } /** @@ -245,7 +247,7 @@ public class AjaxOrderPddController { * @return * @throws Exception */ - private ApiResult pullPddOrder( String clientId,String clientSecret,String accessToken,Integer pageNo, Integer pageSize, Long startTime, Long endTime, Long shopId) throws Exception { + private ResultVo pullPddOrder( String clientId,String clientSecret,String accessToken,Integer pageNo, Integer pageSize, Long startTime, Long endTime, Long shopId) throws Exception { PopClient client = new PopHttpClient(clientId, clientSecret); // 调取拼多多接口 pdd.order.list.get 订单列表查询接口(根据成交时间) @@ -268,9 +270,9 @@ public class AjaxOrderPddController { PddOrderListGetResponse pddOrderListGetResponse = client.syncInvoke(pddOrderListGetRequest, accessToken); if (pddOrderListGetResponse.getErrorResponse() != null) { if (pddOrderListGetResponse.getErrorResponse().getErrorCode().intValue() == 10019) { - return ApiResult.build(HttpStatus.UNAUTHORIZED, "Token过期"); + return ResultVo.error(HttpStatus.UNAUTHORIZED, "Token过期"); } else - return ApiResult.build(HttpStatus.ERROR, + return ResultVo.error(HttpStatus.ERROR, "接口调用失败:" + pddOrderListGetResponse.getErrorResponse().getErrorMsg()); } else { // 获取到了数据 @@ -370,7 +372,7 @@ public class AjaxOrderPddController { } else resp.setTotalRecords(0); } - return ApiResult.build(HttpStatus.SUCCESS, "SUCCESS", resp); + return ResultVo.success(resp); } diff --git a/pdd-api/src/main/java/com/qihang/pdd/controller/PddApiUtils.java b/pdd-api/src/main/java/com/qihang/pdd/controller/PddApiUtils.java index 337f58a8..7004aad6 100644 --- a/pdd-api/src/main/java/com/qihang/pdd/controller/PddApiUtils.java +++ b/pdd-api/src/main/java/com/qihang/pdd/controller/PddApiUtils.java @@ -5,7 +5,7 @@ import com.pdd.pop.sdk.http.PopClient; import com.pdd.pop.sdk.http.PopHttpClient; import com.pdd.pop.sdk.http.api.pop.request.PddMallInfoGetRequest; import com.pdd.pop.sdk.http.api.pop.response.PddMallInfoGetResponse; -import com.qihang.common.common.ApiResult; +import com.qihang.common.common.ResultVo; import com.qihang.common.enums.HttpStatus; public class PddApiUtils { @@ -17,7 +17,7 @@ public class PddApiUtils { * @return * @throws Exception */ - public static ApiResult getShopInfo(String clientId, String clientSecret, String accessToken) throws Exception { + public static ResultVo getShopInfo(String clientId, String clientSecret, String accessToken) throws Exception { PopClient client = new PopHttpClient(clientId, clientSecret); @@ -26,11 +26,11 @@ public class PddApiUtils { if (response.getErrorResponse() == null) { // 刷新一下token - return ApiResult.build(HttpStatus.SUCCESS, "SUCCESS", response.getMallInfoGetResponse()); + return ResultVo.success( response.getMallInfoGetResponse()); } else if (response.getErrorResponse().getErrorCode().intValue() == 10019) { - return ApiResult.build(HttpStatus.UNAUTHORIZED, "Token过期"); + return ResultVo.error(HttpStatus.UNAUTHORIZED, "Token过期"); }else - return ApiResult.build(HttpStatus.ERROR, "接口调用失败:"+response.getErrorResponse().getErrorMsg()); + return ResultVo.error(HttpStatus.ERROR, "接口调用失败:"+response.getErrorResponse().getErrorMsg()); } } diff --git a/pdd-api/src/main/java/com/qihang/pdd/service/impl/SysUserServiceImpl.java b/pdd-api/src/main/java/com/qihang/pdd/service/impl/SysUserServiceImpl.java index 0af46640..c1904d3c 100644 --- a/pdd-api/src/main/java/com/qihang/pdd/service/impl/SysUserServiceImpl.java +++ b/pdd-api/src/main/java/com/qihang/pdd/service/impl/SysUserServiceImpl.java @@ -290,4 +290,9 @@ public class SysUserServiceImpl implements ISysUserService return userMapper.deleteUserById(userId); } + @Override + public void checkUserDataScope(Long userId) { + + } + } diff --git a/wei-api/src/main/java/com/qihang/wei/controller/GoodsApiController.java b/wei-api/src/main/java/com/qihang/wei/controller/GoodsApiController.java index a1ece1b5..86efdf24 100644 --- a/wei-api/src/main/java/com/qihang/wei/controller/GoodsApiController.java +++ b/wei-api/src/main/java/com/qihang/wei/controller/GoodsApiController.java @@ -1,6 +1,7 @@ package com.qihang.wei.controller; import com.qihang.common.common.AjaxResult; +import com.qihang.common.common.ResultVoEnum; import com.qihang.common.enums.HttpStatus; import com.qihang.wei.openApi.ApiCommon; import com.qihang.wei.openApi.PullRequest; @@ -30,14 +31,14 @@ public class GoodsApiController { Date currDateTime = new Date(); long startTime = System.currentTimeMillis(); var checkResult = apiCommon.checkBefore(params.getShopId()); - if (checkResult.getCode() != HttpStatus.SUCCESS) { + if (checkResult.getCode() != ResultVoEnum.SUCCESS.getIndex()) { return AjaxResult.error(checkResult.getCode(), checkResult.getMsg(), checkResult.getData()); } String accessToken = checkResult.getData().getAccessToken(); String serverUrl = checkResult.getData().getServerUrl(); String appKey = checkResult.getData().getAppKey(); String appSecret = checkResult.getData().getAppSecret(); - GoodsApiService remoting = RemoteUtil.Remoting("https://api.weixin.qq.com", GoodsApiService.class); + GoodsApiService remoting = RemoteUtil.Remoting(serverUrl, GoodsApiService.class); GoodsApiBo apiBo = new GoodsApiBo(); apiBo.setPage_size(10); GoodsListVo res = remoting.getGoodsList(accessToken, apiBo); diff --git a/wei-api/src/main/java/com/qihang/wei/controller/OrderApiController.java b/wei-api/src/main/java/com/qihang/wei/controller/OrderApiController.java index cdb7c586..be5bb688 100644 --- a/wei-api/src/main/java/com/qihang/wei/controller/OrderApiController.java +++ b/wei-api/src/main/java/com/qihang/wei/controller/OrderApiController.java @@ -1,7 +1,6 @@ package com.qihang.wei.controller; import com.qihang.common.common.AjaxResult; -import com.qihang.common.common.ApiResult; import com.qihang.common.common.ResultVoEnum; import com.qihang.common.enums.EnumShopType; import com.qihang.common.enums.HttpStatus; diff --git a/wei-api/src/main/java/com/qihang/wei/domain/SysPlatform.java b/wei-api/src/main/java/com/qihang/wei/domain/SysPlatform.java new file mode 100644 index 00000000..9640dd7b --- /dev/null +++ b/wei-api/src/main/java/com/qihang/wei/domain/SysPlatform.java @@ -0,0 +1,48 @@ +package com.qihang.wei.domain; + +import java.io.Serializable; +import lombok.Data; + +/** + * + * @TableName sys_platform + */ +@Data +public class SysPlatform implements Serializable { + /** + * + */ + private Integer id; + + /** + * 平台名 + */ + private String name; + + /** + * 平台编码 + */ + private String code; + + /** + * + */ + private String appKey; + + /** + * + */ + private String appSecret; + + /** + * 平台回调uri + */ + private String redirectUri; + + /** + * 接口访问地址 + */ + private String serverUrl; + + private static final long serialVersionUID = 1L; +} \ No newline at end of file diff --git a/wei-api/src/main/java/com/qihang/wei/mapper/SysPlatformMapper.java b/wei-api/src/main/java/com/qihang/wei/mapper/SysPlatformMapper.java new file mode 100644 index 00000000..68a6153f --- /dev/null +++ b/wei-api/src/main/java/com/qihang/wei/mapper/SysPlatformMapper.java @@ -0,0 +1,18 @@ +package com.qihang.wei.mapper; + +import com.qihang.wei.domain.SysPlatform; +import com.baomidou.mybatisplus.core.mapper.BaseMapper; + +/** +* @author qilip +* @description 针对表【sys_platform】的数据库操作Mapper +* @createDate 2024-03-24 18:04:27 +* @Entity com.qihang.wei.domain.SysPlatform +*/ +public interface SysPlatformMapper extends BaseMapper { + +} + + + + diff --git a/wei-api/src/main/java/com/qihang/wei/openApi/ApiCommon.java b/wei-api/src/main/java/com/qihang/wei/openApi/ApiCommon.java index 235be2e2..fc9ff517 100644 --- a/wei-api/src/main/java/com/qihang/wei/openApi/ApiCommon.java +++ b/wei-api/src/main/java/com/qihang/wei/openApi/ApiCommon.java @@ -1,12 +1,15 @@ package com.qihang.wei.openApi; import com.qihang.common.api.ShopApiParams; -import com.qihang.common.common.ApiResult; +import com.qihang.common.common.ResultVo; import com.qihang.common.enums.EnumShopType; import com.qihang.common.enums.HttpStatus; +import com.qihang.wei.openApi.service.ShopInfoApiService; import com.qihang.wei.openApi.service.TokenApiService; +import com.qihang.wei.openApi.vo.ShopApiResultVo; import com.qihang.wei.openApi.vo.Token; +import com.qihang.wei.service.SysPlatformService; import com.qihang.wei.service.SysShopService; import com.qihang.wei.utils.RemoteUtil; import lombok.AllArgsConstructor; @@ -17,6 +20,7 @@ import org.springframework.util.StringUtils; @Component public class ApiCommon { private final SysShopService shopService; + private final SysPlatformService platformService; /** * 更新前的检查 * @@ -24,78 +28,51 @@ public class ApiCommon { * @return * @throws */ - public ApiResult checkBefore(Integer shopId) { + public ResultVo checkBefore(Integer shopId) { var shop = shopService.selectShopById(shopId); if (shop == null) { -// return new ApiResult<>(EnumResultVo.ParamsError.getIndex(), "参数错误,没有找到店铺"); - return ApiResult.build(HttpStatus.PARAMS_ERROR,"参数错误,没有找到店铺"); + return ResultVo.error(HttpStatus.PARAMS_ERROR,"参数错误,没有找到店铺"); } - if (shop.getType() != EnumShopType.WEI.getIndex()) { - return ApiResult.build(HttpStatus.PARAMS_ERROR, "参数错误,店铺不是JD店铺"); + return ResultVo.error(HttpStatus.PARAMS_ERROR, "参数错误,店铺不是JD店铺"); } - if(!StringUtils.hasText(shop.getAppKey())) { - return ApiResult.build(HttpStatus.PARAMS_ERROR, "平台配置错误,没有找到AppKey"); + return ResultVo.error(HttpStatus.PARAMS_ERROR, "平台配置错误,没有找到AppKey"); } if(!StringUtils.hasText(shop.getAppSercet())) { - return ApiResult.build(HttpStatus.PARAMS_ERROR, "第三方平台配置错误,没有找到AppSercet"); + return ResultVo.error(HttpStatus.PARAMS_ERROR, "第三方平台配置错误,没有找到AppSercet"); + } + var platform =platformService.getById(EnumShopType.WEI.getIndex()); + if(!StringUtils.hasText(platform.getServerUrl())) { + return ResultVo.error(HttpStatus.PARAMS_ERROR, "第三方平台配置错误,没有找到ServerUrl"); } -// if(!StringUtils.hasText(platform.getRedirectUri())) { -// return ApiResult.build(HttpStatus.PARAMS_ERROR, "第三方平台配置错误,没有找到RedirectUri"); -// } -// if(!StringUtils.hasText(platform.getServerUrl())) { -// return ApiResult.build(HttpStatus.PARAMS_ERROR, "第三方平台配置错误,没有找到ServerUrl"); -// } - -// if(shop.getSellerId() == null || shop.getSellerId() <= 0) { -// return com.qihang.tao.common.ApiResult.build(HttpStatus.PARAMS_ERROR, "第三方平台配置错误,没有找到SellerUserId"); -// } ShopApiParams params = new ShopApiParams(); params.setAppKey(shop.getAppKey()); params.setAppSecret(shop.getAppSercet()); params.setAccessToken(shop.getAccessToken()); -// params.setTokenRequestUrl(platform.getRedirectUri()); params.setApiRequestUrl(shop.getApiRequestUrl()); -// params.setServerUrl(platform.getServerUrl()); + params.setServerUrl(platform.getServerUrl()); params.setSellerId(shop.getSellerId().toString()); if (!StringUtils.hasText(shop.getAccessToken())) { - String tokenUrl = "https://api.weixin.qq.com/cgi-bin"; // String s = "/token?grant_type=client_credential&appid="+params.getAppKey()+"&secret="+params.getAppSecret(); - TokenApiService remoting = RemoteUtil.Remoting(tokenUrl, TokenApiService.class); + TokenApiService remoting = RemoteUtil.Remoting(params.getServerUrl(), TokenApiService.class); Token token = remoting.getToken("client_credential",params.getAppKey(),params.getAppSecret()); params.setAccessToken(token.getAccess_token()); shopService.updateSessionKey(shopId,token.getAccess_token()); -// return ApiResult.build(HttpStatus.UNAUTHORIZED, "Token已过期,请重新授权", params); + }else { + // 调用 店铺基本信息接口 验证Token + ShopInfoApiService remoting = RemoteUtil.Remoting(params.getServerUrl(), ShopInfoApiService.class); + ShopApiResultVo shopInfo = remoting.getShopInfo(params.getAccessToken()); + if(shopInfo.getErrcode() == 42001){ + // Token过期 + TokenApiService remoting1 = RemoteUtil.Remoting(params.getServerUrl(), TokenApiService.class); + Token token = remoting1.getToken("client_credential",params.getAppKey(),params.getAppSecret()); + params.setAccessToken(token.getAccess_token()); + shopService.updateSessionKey(shopId,token.getAccess_token()); + } } - - /****************先查询卖家对不对***************/ -// TaobaoClient client = new DefaultTaobaoClient(url, appkey, secret); -// UserSellerGetRequest reqSeller = new UserSellerGetRequest(); -// reqSeller.setFields("nick,user_id"); -// UserSellerGetResponse rsp = client.execute(reqSeller, sessionKey); -// if(StringUtils.hasText(rsp.getErrorCode())){ -// if(rsp.getErrorCode().equals("27")){ -// return new ApiResult<>(EnumResultVo.TokenFail.getIndex(), "Token已过期,请重新授权",params); -// } -// else if(rsp.getErrorCode().equals("11")){ -// if(rsp.getSubCode().equals("isv.permission-api-package-limit")) -// return new ApiResult<>(EnumResultVo.ParamsError.getIndex(), "请检查淘宝用户API:taobao.user.seller.get是否具有访问权限",params); -// return new ApiResult<>(EnumResultVo.ParamsError.getIndex(), rsp.getSubCode(),params); -// } -// else if(rsp.getErrorCode().equals("25")){ -// return new ApiResult<>(EnumResultVo.ParamsError.getIndex(), "无效签名!请检查SessionKey、appKey、appSecret是否匹配",params); -// } else -// return new ApiResult<>(EnumResultVo.ParamsError.getIndex(), "参数错误!"+(StringUtils.hasText(rsp.getSubMsg()) ? rsp.getSubMsg(): rsp.getMsg())); -// } -// if(rsp.getUser() == null || rsp.getUser().getUserId() == null){ -// return new ApiResult<>(EnumResultVo.ParamsError.getIndex(), "参数错误!请设置店铺SellerUserId值!",params); -// } -// else if (shop.getSellerUserId().longValue() != rsp.getUser().getUserId().longValue()) { -// return new ApiResult<>(EnumResultVo.TokenFail.getIndex(), "当前用户是:" + rsp.getUser().getNick() + ",请重新授权",params); -// } - return ApiResult.build(HttpStatus.SUCCESS,"",params); + return ResultVo.success(params); } } diff --git a/wei-api/src/main/java/com/qihang/wei/openApi/service/ShopInfoApiService.java b/wei-api/src/main/java/com/qihang/wei/openApi/service/ShopInfoApiService.java new file mode 100644 index 00000000..c7976284 --- /dev/null +++ b/wei-api/src/main/java/com/qihang/wei/openApi/service/ShopInfoApiService.java @@ -0,0 +1,13 @@ +package com.qihang.wei.openApi.service; + +import com.qihang.wei.openApi.vo.ShopApiResultVo; +import com.qihang.wei.openApi.vo.Token; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.service.annotation.GetExchange; +import org.springframework.web.service.annotation.HttpExchange; + +@HttpExchange +public interface ShopInfoApiService { + @GetExchange("/channels/ec/basics/info/get") + ShopApiResultVo getShopInfo(@RequestParam String access_token); +} diff --git a/wei-api/src/main/java/com/qihang/wei/openApi/service/TokenApiService.java b/wei-api/src/main/java/com/qihang/wei/openApi/service/TokenApiService.java index cf35bc4c..cb33812c 100644 --- a/wei-api/src/main/java/com/qihang/wei/openApi/service/TokenApiService.java +++ b/wei-api/src/main/java/com/qihang/wei/openApi/service/TokenApiService.java @@ -9,6 +9,6 @@ import org.springframework.web.service.annotation.HttpExchange; @HttpExchange public interface TokenApiService { - @GetExchange("/token") + @GetExchange("/cgi-bin/token") Token getToken(@RequestParam String grant_type, @RequestParam String appid, @RequestParam String secret); } diff --git a/wei-api/src/main/java/com/qihang/wei/openApi/vo/ShopApiResultVo.java b/wei-api/src/main/java/com/qihang/wei/openApi/vo/ShopApiResultVo.java new file mode 100644 index 00000000..48f3f4b2 --- /dev/null +++ b/wei-api/src/main/java/com/qihang/wei/openApi/vo/ShopApiResultVo.java @@ -0,0 +1,8 @@ +package com.qihang.wei.openApi.vo; + +import lombok.Data; + +@Data +public class ShopApiResultVo extends BaseResVo{ + private ShopInfoVo info; +} diff --git a/wei-api/src/main/java/com/qihang/wei/openApi/vo/ShopInfoVo.java b/wei-api/src/main/java/com/qihang/wei/openApi/vo/ShopInfoVo.java new file mode 100644 index 00000000..f1b0ac14 --- /dev/null +++ b/wei-api/src/main/java/com/qihang/wei/openApi/vo/ShopInfoVo.java @@ -0,0 +1,12 @@ +package com.qihang.wei.openApi.vo; + +import lombok.Data; + +@Data +public class ShopInfoVo { + private String nickname; + private String headimg_url; + private String subject_type; + private String status; + private String username; +} diff --git a/wei-api/src/main/java/com/qihang/wei/service/SysPlatformService.java b/wei-api/src/main/java/com/qihang/wei/service/SysPlatformService.java new file mode 100644 index 00000000..bc329174 --- /dev/null +++ b/wei-api/src/main/java/com/qihang/wei/service/SysPlatformService.java @@ -0,0 +1,13 @@ +package com.qihang.wei.service; + +import com.qihang.wei.domain.SysPlatform; +import com.baomidou.mybatisplus.extension.service.IService; + +/** +* @author qilip +* @description 针对表【sys_platform】的数据库操作Service +* @createDate 2024-03-24 18:04:27 +*/ +public interface SysPlatformService extends IService { + +} diff --git a/wei-api/src/main/java/com/qihang/wei/service/impl/SysPlatformServiceImpl.java b/wei-api/src/main/java/com/qihang/wei/service/impl/SysPlatformServiceImpl.java new file mode 100644 index 00000000..9d69cf38 --- /dev/null +++ b/wei-api/src/main/java/com/qihang/wei/service/impl/SysPlatformServiceImpl.java @@ -0,0 +1,22 @@ +package com.qihang.wei.service.impl; + +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.qihang.wei.domain.SysPlatform; +import com.qihang.wei.service.SysPlatformService; +import com.qihang.wei.mapper.SysPlatformMapper; +import org.springframework.stereotype.Service; + +/** +* @author qilip +* @description 针对表【sys_platform】的数据库操作Service实现 +* @createDate 2024-03-24 18:04:27 +*/ +@Service +public class SysPlatformServiceImpl extends ServiceImpl + implements SysPlatformService{ + +} + + + + diff --git a/wei-api/src/main/resources/mapper/SysPlatformMapper.xml b/wei-api/src/main/resources/mapper/SysPlatformMapper.xml new file mode 100644 index 00000000..556d2470 --- /dev/null +++ b/wei-api/src/main/resources/mapper/SysPlatformMapper.xml @@ -0,0 +1,22 @@ + + + + + + + + + + + + + + + + id,name,code, + app_key,app_secret,redirect_uri, + server_url + +