From b31cfa173e7aa0e892dd7f119430723fbc31420e Mon Sep 17 00:00:00 2001 From: tianzong <5262097@qq.com> Date: Mon, 1 Feb 2021 09:48:05 +0800 Subject: [PATCH 1/5] =?UTF-8?q?=E6=B3=A8=E9=87=8A=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/moming/douapisdk/Constants.java | 58 +++++----- .../moming/douapisdk/DefaultDouYinClient.java | 105 +++++++++++++----- .../com/moming/douapisdk/DouYinRequest.java | 9 +- .../util/RequestParametersHolder.java | 4 + 4 files changed, 121 insertions(+), 55 deletions(-) diff --git a/src/main/java/com/moming/douapisdk/Constants.java b/src/main/java/com/moming/douapisdk/Constants.java index 4dca901..67ddf27 100644 --- a/src/main/java/com/moming/douapisdk/Constants.java +++ b/src/main/java/com/moming/douapisdk/Constants.java @@ -4,50 +4,58 @@ package com.moming.douapisdk; * @author tianzong * @date 2020/7/21 */ -public class Constants { +public interface Constants { /** 协议入参共享参数 **/ - public static final String APP_KEY = "app_key"; - public static final String METHOD = "method"; - public static final String TIMESTAMP = "timestamp"; - public static final String VERSION = "v"; - public static final String SIGN = "sign"; - public static final String ACCESS_TOKEN = "access_token"; - public static final String PARAM_JSON = "param_json"; + String APP_KEY = "app_key"; + String METHOD = "method"; + String TIMESTAMP = "timestamp"; + String VERSION = "v"; + String SIGN = "sign"; + String ACCESS_TOKEN = "access_token"; + String PARAM_JSON = "param_json"; - public static final String AUTHORIZATION_CODE = "authorization_code"; + /** + * 授权类型:工具型授权 + */ + String AUTHORIZATION_CODE = "authorization_code"; + + /** + * 授权类型:自用型授权 + */ + String AUTHORIZATION_SELF = "authorization_self"; - public static final String REFRESH_GRANT_TYPE = "refresh_token"; + String REFRESH_GRANT_TYPE = "refresh_token"; /** * 授权访问地址 */ - public static final String AUTHORIZATION_PATH = "/oauth2/access_token"; + String AUTHORIZATION_PATH = "/oauth2/access_token"; /** * 刷新token的地址 */ - public static final String REFRESH_TOKEN_PATH = "/oauth2/refresh_token"; + String REFRESH_TOKEN_PATH = "/oauth2/refresh_token"; /** 协议出参共享参数 */ - public static final String ERROR_CODE = "err_no"; - public static final String ERROR_MSG = "message"; + String ERROR_CODE = "err_no"; + String ERROR_MSG = "message"; /** 默认时间格式 **/ - public static final String DATE_TIME_FORMAT = "yyyy-MM-dd HH:mm:ss"; + String DATE_TIME_FORMAT = "yyyy-MM-dd HH:mm:ss"; /** Date默认时区 **/ - public static final String DATE_TIMEZONE = "GMT+8"; + String DATE_TIMEZONE = "GMT+8"; /** UTF-8字符集 **/ - public static final String CHARSET_UTF8 = "UTF-8"; + String CHARSET_UTF8 = "UTF-8"; /** HTTP请求相关 **/ - public static final String METHOD_POST = "POST"; - public static final String METHOD_GET = "GET"; - public static final String CTYPE_FORM_DATA = "application/x-www-form-urlencoded"; - public static final String CTYPE_FILE_UPLOAD = "multipart/form-data"; - public static final String CTYPE_TEXT_XML = "text/xml"; - public static final String CTYPE_APPLICATION_XML = "application/xml"; - public static final String CTYPE_TEXT_PLAIN = "text/plain"; - public static final String CTYPE_APP_JSON = "application/json"; + String METHOD_POST = "POST"; + String METHOD_GET = "GET"; + String C_TYPE_FORM_DATA = "application/x-www-form-urlencoded"; + String C_TYPE_FILE_UPLOAD = "multipart/form-data"; + String C_TYPE_TEXT_XML = "text/xml"; + String C_TYPE_APPLICATION_XML = "application/xml"; + String C_TYPE_TEXT_PLAIN = "text/plain"; + String C_TYPE_APP_JSON = "application/json"; } diff --git a/src/main/java/com/moming/douapisdk/DefaultDouYinClient.java b/src/main/java/com/moming/douapisdk/DefaultDouYinClient.java index 1cebe08..d2337c4 100644 --- a/src/main/java/com/moming/douapisdk/DefaultDouYinClient.java +++ b/src/main/java/com/moming/douapisdk/DefaultDouYinClient.java @@ -10,7 +10,6 @@ import com.moming.douapisdk.internal.util.RequestParametersHolder; import com.moming.douapisdk.response.OauthResponse; import lombok.Data; import lombok.extern.log4j.Log4j2; -import org.yaml.snakeyaml.scanner.Constant; import java.io.IOException; import java.util.Date; @@ -19,6 +18,8 @@ import java.util.Map; import java.util.Objects; /** + * 抖音客户端 + * * @author tianzong * @date 2020/7/21 */ @@ -76,24 +77,32 @@ public class DefaultDouYinClient implements DouYinClient { */ @Override public T execute(DouYinRequest request, String accessToken) throws ApiException { - return _execute(request, accessToken); + return executeInternal(request, accessToken); } /** - * oauth2.0授权 + * 工具型应用授权 + * code换token + * + * + * @link https://op.jinritemai.com/docs/guide-docs/9/22 * @param code code授权码 - * @return + * @return 获取token */ public OauthResponse code2Access(String code) throws ApiException { DouYinHashMap appParams = new DouYinHashMap(); appParams.put("app_id", this.appKey); appParams.put("app_secret", this.appSecret); - appParams.put("code", code); - appParams.put("grant_type", Constants.AUTHORIZATION_CODE); + if (code != null) { + appParams.put("code", code); + } + appParams.put("grant_type", code == null + ? Constants.AUTHORIZATION_SELF + : Constants.AUTHORIZATION_CODE); OauthResponse tsr; String url = null; try { - url = resolveApiUrl(Constants.AUTHORIZATION_PATH, appParams); + url = buildApiUrl(Constants.AUTHORIZATION_PATH, appParams); log.info(" 换取token的url : {} ", url); String body = HttpClientHelper.httpGet(url); tsr = JSONObject.parseObject(body, OauthResponse.class); @@ -109,12 +118,22 @@ public class DefaultDouYinClient implements DouYinClient { } + /** + * 自用型应用授权 + * + * @link https://op.jinritemai.com/docs/guide-docs/9/21 + * @return 获取token + */ + public OauthResponse code2Access() { + return code2Access(null); + } + /** * 刷新AccessToken * - * @param refreshToken - * @return - * @throws ApiException + * @param refreshToken 刷新token + * @return 新的oauth信息 + * @throws ApiException api结果 */ public OauthResponse refreshAccessToken(String refreshToken) throws ApiException { Objects.requireNonNull(refreshToken); @@ -126,7 +145,7 @@ public class DefaultDouYinClient implements DouYinClient { OauthResponse tsr; String url = null; try { - url = resolveApiUrl(Constants.REFRESH_TOKEN_PATH, appParams); + url = buildApiUrl(Constants.REFRESH_TOKEN_PATH, appParams); log.info(" 刷新AccessToken的url : {} ", url); String body = HttpClientHelper.httpGet(url); tsr = JSONObject.parseObject(body, OauthResponse.class); @@ -141,17 +160,27 @@ public class DefaultDouYinClient implements DouYinClient { return tsr; } - private T _execute(DouYinRequest request, String accessToken) throws ApiException { - long start = System.currentTimeMillis(); - - // 构建响应解释器 + /** + * 执行调用 + * + * @param request 请求类型 + * @param accessToken token + * @param 具体请求接口 + * @return 返回数据 + * @throws ApiException api调用异常 + */ + private T executeInternal(DouYinRequest request, String accessToken) + throws ApiException { // 调用api - RequestParametersHolder requestHolder = invokeApi(request, accessToken, start); + RequestParametersHolder requestHolder = invokeApiInternal(request, accessToken); T tsr = null; + // 解析结果 try { + + // 构建响应解释器 tsr = parseBody(requestHolder, request); if (tsr.hasError()) { @@ -159,10 +188,13 @@ public class DefaultDouYinClient implements DouYinClient { } } catch (Exception e) { - log.error("调用api接口发生错误,错误ErrorNo---{}, 错误Message---{}, 请求的Url--{}", - tsr.getErrNo(), - tsr.getMessage(), - tsr.getRequestUrl()); + + if (tsr != null) { + log.error("调用api接口发生错误,错误ErrorNo---{}, 错误Message---{}, 请求的Url--{}", + tsr.getErrNo(), + tsr.getMessage(), + tsr.getRequestUrl()); + } throw new ApiException(e); } @@ -170,7 +202,17 @@ public class DefaultDouYinClient implements DouYinClient { return tsr; } - private T parseBody(RequestParametersHolder requestHolder, DouYinRequest request) throws IllegalAccessException, InstantiationException { + /** + * 解析接口返回数据 + * @param requestHolder 请求参数 + * @param request 请求数据 + * @param 返回对象 + * @return 结果 + * @throws IllegalAccessException 异常 + * @throws InstantiationException 异常 + */ + private T parseBody(RequestParametersHolder requestHolder, DouYinRequest request) + throws IllegalAccessException, InstantiationException { T tsr = JSONObject.parseObject(requestHolder.getResponseBody(), request.getResponseClass()); @@ -185,15 +227,18 @@ public class DefaultDouYinClient implements DouYinClient { return tsr; } - private RequestParametersHolder invokeApi(DouYinRequest request, String session, long start) throws ApiException { + private RequestParametersHolder invokeApiInternal( + DouYinRequest request, String session) + throws ApiException { RequestDTO requestDTO = new RequestDTO(); requestDTO.setTextParams(request.getTextParams()); requestDTO.setApiMethodName(request.getApiMethodName()); requestDTO.setApiUrl(request.getApiUrl()); - return invokeApi(requestDTO, session, start); + return invokeApiInternal(requestDTO, session); } - protected RequestParametersHolder invokeApi(RequestDTO request, String accessToken, long start) throws ApiException{ + protected RequestParametersHolder invokeApiInternal(RequestDTO request, String accessToken) + throws ApiException{ RequestParametersHolder requestHolder = new RequestParametersHolder(); if (request.getTextParams() == null) { @@ -226,7 +271,7 @@ public class DefaultDouYinClient implements DouYinClient { protocolParams.put(Constants.ACCESS_TOKEN, accessToken); try { // 调用httpClient处理 - String url = resolveApiUrl(request.getApiUrl(), requestHolder.getProtocolParams()); + String url = buildApiUrl(request.getApiUrl(), requestHolder.getProtocolParams()); log.info(" 请求API接口; url : {} ", url); requestHolder.setRequestUrl(url); String body = HttpClientHelper.httpGet(url); @@ -240,7 +285,15 @@ public class DefaultDouYinClient implements DouYinClient { return requestHolder; } - private String resolveApiUrl(String apiUrl, Map params) throws IOException { + /** + * 组合请求api + * + * @param apiUrl api地址 + * @param params 参数 + * @return url + * @throws IOException io异常 + */ + private String buildApiUrl(String apiUrl, Map params) throws IOException { return this.serverUrl + apiUrl + "?" diff --git a/src/main/java/com/moming/douapisdk/DouYinRequest.java b/src/main/java/com/moming/douapisdk/DouYinRequest.java index dfdf662..ce6e129 100644 --- a/src/main/java/com/moming/douapisdk/DouYinRequest.java +++ b/src/main/java/com/moming/douapisdk/DouYinRequest.java @@ -4,6 +4,7 @@ import java.util.Map; /** * Api请求接口 + * * @author tianzong * @date 2020/7/23 */ @@ -13,13 +14,13 @@ public interface DouYinRequest { * 获取api的url地址 * @return url地址 */ - public String getApiUrl(); + String getApiUrl(); /** * 获取API的名称 * @return API名称 */ - public String getApiMethodName(); + String getApiMethodName(); /** * 获取所有的key-value形式的文本请求参数集合,其中: @@ -29,11 +30,11 @@ public interface DouYinRequest { * * @return 文本请求参数集合 */ - public Map getTextParams(); + Map getTextParams(); /** * 获取具体响应实现类的定义。 * @return 获取具体响应实现类的定义。 */ - public Class getResponseClass(); + Class getResponseClass(); } diff --git a/src/main/java/com/moming/douapisdk/internal/util/RequestParametersHolder.java b/src/main/java/com/moming/douapisdk/internal/util/RequestParametersHolder.java index 289b903..e0303f3 100644 --- a/src/main/java/com/moming/douapisdk/internal/util/RequestParametersHolder.java +++ b/src/main/java/com/moming/douapisdk/internal/util/RequestParametersHolder.java @@ -6,6 +6,10 @@ import lombok.Data; import java.util.TreeMap; /** + * 请求参数 存储结构体 + * + * 存放请求url,请求参数,返回值 + * * @author tianzong * @date 2020/7/21 */ -- Gitee From 9f9103a296a6976b27b41dd9a1b3ae20f778b539 Mon Sep 17 00:00:00 2001 From: tianzong <5262097@qq.com> Date: Mon, 1 Feb 2021 10:07:30 +0800 Subject: [PATCH 2/5] =?UTF-8?q?=E5=95=86=E5=93=81=E5=92=8C=E8=AE=A2?= =?UTF-8?q?=E5=8D=95=E7=B1=BB=E5=9E=8B=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../douapisdk/domain/DouYinProduct.java | 70 +++++++++++++++++-- .../moming/douapisdk/domain/OrderChild.java | 4 +- 2 files changed, 66 insertions(+), 8 deletions(-) diff --git a/src/main/java/com/moming/douapisdk/domain/DouYinProduct.java b/src/main/java/com/moming/douapisdk/domain/DouYinProduct.java index 418e868..8e20239 100644 --- a/src/main/java/com/moming/douapisdk/domain/DouYinProduct.java +++ b/src/main/java/com/moming/douapisdk/domain/DouYinProduct.java @@ -6,6 +6,8 @@ import lombok.Data; import org.springframework.boot.jackson.JsonComponent; /** + * 抖音商品 + * * @author lujingpo */ @Data @@ -21,38 +23,94 @@ public class DouYinProduct { */ @JSONField(name = "open_user_id") private long openUserId; + + /** + * 商品名称 + */ private String name; + + /** + * 详情html + */ private String description; + + /** + * 头图,主图第一张 + */ private String img; /** - * 市场价格 + * 划线价,单位分 */ @JSONField(name = "market_price") private int marketPrice; + + /** + * 售价,单位分 + */ @JSONField(name = "discount_price") private int discountPrice; - @JSONField(name = "settlement_price") - private int settlementPrice; + + /** + * 商品上下架状态:0上架 1下架 2已删除 + */ private int status; + + /** + * 规格id + */ @JSONField(name = "spec_id") - private int specId; + private Long specId; + + /** + * 商品审核状态:1未提审 2审核中 3审核通过 4审核驳回 5封禁 + */ @JSONField(name = "check_status") private int checkStatus; + + /** + * 手机号 + */ private String mobile; + + /** + * 一级类目 + */ @JSONField(name = "first_cid") private int firstCid; + + /** + * 二级类目 + */ @JSONField(name = "second_cid") private int secondCid; + + /** + * 三级类目 + */ @JSONField(name = "third_cid") private int thirdCid; + + /** + * 支持的支付方式:0货到付款 1在线支付 2两者都支持 + */ @JSONField(name = "pay_type") private int payType; + + /** + * 商家推荐语 + */ @JSONField(name = "recommend_remark") private String recommendRemark; - @JSONField(name = "is_create") - private int isCreate; + + /** + * 创建时间 + */ @JSONField(name = "create_time") private String createTime; + + /** + * 更新时间 + */ @JSONField(name = "update_time") private String updateTime; diff --git a/src/main/java/com/moming/douapisdk/domain/OrderChild.java b/src/main/java/com/moming/douapisdk/domain/OrderChild.java index 636c070..b79f7b9 100644 --- a/src/main/java/com/moming/douapisdk/domain/OrderChild.java +++ b/src/main/java/com/moming/douapisdk/domain/OrderChild.java @@ -36,7 +36,7 @@ public class OrderChild { private int comboAmount; @JSONField(name = "combo_id") - private int comboId; + private long comboId; @JSONField(name = "combo_num") private int comboNum; @@ -78,7 +78,7 @@ public class OrderChild { private int outProductId; @JSONField(name = "out_sku_id") - private int outSkuId; + private long outSkuId; @JSONField(name = "pay_type") private int payType; -- Gitee From 4a431f36401e3f1efb2460a06e6a84be5028998c Mon Sep 17 00:00:00 2001 From: tianzong <5262097@qq.com> Date: Mon, 1 Feb 2021 11:33:13 +0800 Subject: [PATCH 3/5] =?UTF-8?q?=E8=8E=B7=E5=8F=96=E5=94=AE=E5=90=8E?= =?UTF-8?q?=E8=AE=A2=E5=8D=95=E5=88=97=E8=A1=A8=E6=8E=A5=E5=8F=A3=E7=BC=96?= =?UTF-8?q?=E5=86=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .idea/inspectionProfiles/Project_Default.xml | 4 + .../moming/douapisdk/domain/AfterSale.java | 389 ++++++++++++++++++ .../douapisdk/request/OrderDetailRequest.java | 5 +- .../request/TradeRefundListSearchRequest.java | 190 +++++++++ .../TradeRefundListSearchResponse.java | 29 ++ 5 files changed, 614 insertions(+), 3 deletions(-) create mode 100644 src/main/java/com/moming/douapisdk/domain/AfterSale.java create mode 100644 src/main/java/com/moming/douapisdk/request/TradeRefundListSearchRequest.java create mode 100644 src/main/java/com/moming/douapisdk/response/TradeRefundListSearchResponse.java diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml index 6560a98..71b8943 100644 --- a/.idea/inspectionProfiles/Project_Default.xml +++ b/.idea/inspectionProfiles/Project_Default.xml @@ -32,5 +32,9 @@