Commit afb83b77 by 吕明尚

增加查询商品详情接口

parent 60d53fda
......@@ -7,8 +7,8 @@ public enum ReceiptRdeisEnum {
MT_SESSION_OBJECT_KEY(3, "MT_SESSION_OBJECT_KEY"),
ORDER_NO_KEY(4, "ORDER_NO_KEY."),
ACCESS_TOKEN_KEY(5, "ACCESS_TOKEN_KEY."),
TIKTOK_CLIENT_TOKEN(6, "TIKTOK_CLIENT_TOKEN."),
ORDER_NO(6, "ORDER_NO.");
ORDER_NO(6, "ORDER_NO."),
TIKTOK_CLIENT_TOKEN(7, "TIKTOK_CLIENT_TOKEN.");
private Integer code;
......
package share.common.enums;
public enum TiktokUrlEnum {
//用户授权
OAUTH_CLIENT_TOKEN("https://open.douyin.com/oauth/client_token/", "生成 client_token"),
CERTIFICATE_PREPARE("https://open.douyin.com/goodlife/v1/fulfilment/certificate/prepare/", "验卷准备接口"),
CERTIFICATE_VERIFY("https://open.douyin.com/goodlife/v1/fulfilment/certificate/verify/", "验卷接口"),
CERTIFICATE_CANCEL("https://open.douyin.com/goodlife/v1/fulfilment/certificate/cancel/", "撤销核销接口"),
CERTIFICATE_GET("https://open.douyin.com/goodlife/v1/fulfilment/certificate/get/", "券状态查询"),
POI_QUERY("https://open.douyin.com/goodlife/v1/shop/poi/query/", "查询门店信息"),
ONLINE_QUERY("https://open.douyin.com/goodlife/v1/akte/goods/product/online/query/", "查询商品线上数据列表"),
;
private String url;
private String name;
TiktokUrlEnum() {
}
TiktokUrlEnum(String url, String name) {
this.url = url;
this.name = name;
}
public String getUrl() {
return url;
}
public void setUrl(String url) {
this.url = url;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
......@@ -18,7 +18,7 @@ public class OnlineQueryDto {
private Integer goodsCreatorType;
//是否查询商品全量关联门店
//设置为true时,分页数量最大上限为20
private boolean queryAllPoi;
private Boolean queryAllPoi;
//新商品查询参数,仅支持ka自研开发者使用,当前参数生效时goods_creator_type参数不再生效
//1 - 可查询归属于ka自研的所有商品,包括非ka自研创建的商品
private Integer goodsQueryType;
......
......@@ -15,6 +15,7 @@ import org.springframework.stereotype.Service;
import share.common.core.redis.RedisUtil;
import share.common.enums.ErrorCodeEnum;
import share.common.enums.ReceiptRdeisEnum;
import share.common.enums.TiktokUrlEnum;
import share.common.enums.VerifyResultsEnum;
import share.system.domain.vo.OnlineQueryDto;
import share.system.domain.vo.TiktokCouponDto;
......@@ -22,6 +23,7 @@ import share.system.service.TiktokService;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
......@@ -40,12 +42,12 @@ public class TiktokServiceImpl implements TiktokService {
@Override
public void clientToken() {
String url = "https://open.douyin.com/oauth/client_token/";
// String url = "https://open.douyin.com/oauth/client_token/";
HashMap<String, Object> tokenMap = new HashMap<>();
tokenMap.put("client_key", CLIENT_KEY);
tokenMap.put("client_secret", CLIENT_SECRET);
tokenMap.put("grant_type", "client_credentials");
String post = HttpRequest.post(url)
String post = HttpRequest.post(TiktokUrlEnum.OAUTH_CLIENT_TOKEN.getUrl())
.contentType("application/json")
.body(new JSONObject(tokenMap).toString()).execute().body();
JSONObject sessionKey = new JSONObject(post);
......@@ -73,7 +75,7 @@ public class TiktokServiceImpl implements TiktokService {
@Override
public String prepare(TiktokCouponDto tiktokCouponDto) {
String accessToken = obtain();
String url = "https://open.douyin.com/goodlife/v1/fulfilment/certificate/prepare/";
// String url = "https://open.douyin.com/goodlife/v1/fulfilment/certificate/prepare/";
String result = "";
//判断短链接是否以https://v.douyin.com/开头,/结尾
if (tiktokCouponDto.getEncryptedData().startsWith("https://v.douyin.com/") && tiktokCouponDto.getEncryptedData().endsWith("/")) {
......@@ -82,14 +84,14 @@ public class TiktokServiceImpl implements TiktokService {
Matcher matcher = pattern.matcher(encryptedData);
if (matcher.find()) {
String objectId = matcher.group(1);
result = HttpRequest.get(url)
result = HttpRequest.get(TiktokUrlEnum.CERTIFICATE_PREPARE.getUrl())
.contentType("application/json")
.header("access-token", accessToken)
.form("encrypted_data", objectId).form("poi_id", tiktokCouponDto.getPoiId()).execute().body();
}
} else {
result = HttpRequest.get(url)
result = HttpRequest.get(TiktokUrlEnum.CERTIFICATE_PREPARE.getUrl())
.contentType("application/json")
.header("access-token", accessToken)
.form("code", tiktokCouponDto.getCode()).form("poi_id", tiktokCouponDto.getPoiId()).execute().body();
......@@ -106,13 +108,13 @@ public class TiktokServiceImpl implements TiktokService {
@Override
public String verify(TiktokCouponDto tiktokCouponDto) {
String accessToken = obtain();
String url = "https://open.douyin.com/goodlife/v1/fulfilment/certificate/verify/";
// String url = "https://open.douyin.com/goodlife/v1/fulfilment/certificate/verify/";
Map<String, Object> map = new HashMap<>();
map.put("verify_token", tiktokCouponDto.getVerifyToken());
map.put("poi_id", tiktokCouponDto.getPoiId());
map.put("encrypted_codes", tiktokCouponDto.getEncryptedCodes());
JSONObject jsonObject = new JSONObject(map);
String result = HttpRequest.post(url)
String result = HttpRequest.post(TiktokUrlEnum.CERTIFICATE_VERIFY.getUrl())
.contentType("application/json")
.header("access-token", accessToken)
.body(jsonObject.toString()).execute().body();
......@@ -132,12 +134,12 @@ public class TiktokServiceImpl implements TiktokService {
@Override
public String cancel(TiktokCouponDto tiktokCouponDto) {
String accessToken = obtain();
String url = "https://open.douyin.com/goodlife/v1/fulfilment/certificate/cancel/";
// String url = "https://open.douyin.com/goodlife/v1/fulfilment/certificate/cancel/";
Map<String, Object> map = new HashMap<>();
map.put("verify_id", tiktokCouponDto.getVerifyId());
map.put("certificate_id", tiktokCouponDto.getCertificateId());
JSONObject jsonObject = new JSONObject(map);
String result = HttpRequest.post(url)
String result = HttpRequest.post(TiktokUrlEnum.CERTIFICATE_CANCEL.getUrl())
.contentType("application/json")
.header("access-token", accessToken)
.body(jsonObject.toString()).execute().body();
......@@ -153,11 +155,11 @@ public class TiktokServiceImpl implements TiktokService {
@Override
public String certificateGet(TiktokCouponDto tiktokCouponDto) {
String accessToken = obtain();
String url = "https://open.douyin.com/goodlife/v1/fulfilment/certificate/get/";
// String url = "https://open.douyin.com/goodlife/v1/fulfilment/certificate/get/";
Map<String, Object> map = new HashMap<>();
map.put("encrypted_code", tiktokCouponDto.getEncryptedCode());
JSONObject jsonObject = new JSONObject(map);
String result = HttpRequest.post(url)
String result = HttpRequest.post(TiktokUrlEnum.CERTIFICATE_GET.getUrl())
.contentType("application/json")
.header("access-token", accessToken)
.form("encrypted_code", jsonObject.toString()).execute().body();
......@@ -172,10 +174,10 @@ public class TiktokServiceImpl implements TiktokService {
@Override
public Object poiQuery(TiktokCouponDto tiktokCouponDto) {
String accessToken = obtain();
String url = "https://open.douyin.com/goodlife/v1/shop/poi/query/";
// String url = "https://open.douyin.com/goodlife/v1/shop/poi/query/";
String result = null;
if (StringUtil.isNotEmpty(tiktokCouponDto.getAccountId())) {
result = HttpRequest.post(url)
result = HttpRequest.post(TiktokUrlEnum.POI_QUERY.getUrl())
.contentType("application/json")
.header("access-token", accessToken)
.form("account_id", tiktokCouponDto.getAccountId())
......@@ -183,7 +185,7 @@ public class TiktokServiceImpl implements TiktokService {
.form("size", 50)
.execute().body();
} else {
result = HttpRequest.post(url)
result = HttpRequest.post(TiktokUrlEnum.POI_QUERY.getUrl())
.contentType("application/json")
.header("access-token", accessToken)
.form("poi_id", tiktokCouponDto.getAccountId())
......@@ -208,7 +210,42 @@ public class TiktokServiceImpl implements TiktokService {
@Override
public Object onlineQuery(OnlineQueryDto onlineQueryDto) {
return null;
String accessToken = obtain();
String result = HttpRequest.post(TiktokUrlEnum.ONLINE_QUERY.getUrl())
.contentType("application/json")
.header("access-token", accessToken)
.form("cursor", onlineQueryDto.getCursor())
.form("count", onlineQueryDto.getCount())
.form("status", onlineQueryDto.getStatus())
.form("account_id", onlineQueryDto.getAccountId())
.form("goods_creator_type", onlineQueryDto.getGoodsCreatorType())
.form("query_all_poi", onlineQueryDto.getQueryAllPoi())
.form("goods_query_type", onlineQueryDto.getGoodsQueryType())
.execute().body();
JSONObject entries = new JSONObject(result);
JSONObject data = entries.getJSONObject("data");
if (!data.getStr("error_code").equals(ErrorCodeEnum.SUCCESS.getCode())) {
return data.getStr("description");
}
JSONArray products = data.getJSONArray("products");
//JSONArray转List
List<JSONObject> list = products.toList(JSONObject.class);
list.stream().forEach(e -> {
JSONObject product = e.getJSONObject("product");
JSONObject sku = e.getJSONObject("sku");
JSONObject commissionInfo = e.getJSONObject("commission_info");
JSONObject onlineStatus = e.getJSONObject("online_status");
//商品id
String productId = product.getStr("product_id");
//商品名称
String productName = product.getStr("product_name");
//商品类型 1-团购 11-代金券 15-次卡
Integer productType = product.getInt("product_type");
//售卖开始时间
Integer soldStartTime = product.getInt("sold_start_time");
Integer soldEndTime = product.getInt("sold_end_time");
});
return data.getJSONArray("records");
}
public String obtain() {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment