Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
gxpt_ht
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
pseer
gxpt_ht
Commits
afb83b77
Commit
afb83b77
authored
Jan 29, 2024
by
吕明尚
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
增加查询商品详情接口
parent
60d53fda
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
95 additions
and
18 deletions
+95
-18
ReceiptRdeisEnum.java
...on/src/main/java/share/common/enums/ReceiptRdeisEnum.java
+2
-2
TiktokUrlEnum.java
...ommon/src/main/java/share/common/enums/TiktokUrlEnum.java
+40
-0
OnlineQueryDto.java
.../src/main/java/share/system/domain/vo/OnlineQueryDto.java
+1
-1
TiktokServiceImpl.java
...ain/java/share/system/service/impl/TiktokServiceImpl.java
+52
-15
No files found.
share-common/src/main/java/share/common/enums/ReceiptRdeisEnum.java
View file @
afb83b77
...
...
@@ -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
;
...
...
share-common/src/main/java/share/common/enums/TiktokUrlEnum.java
0 → 100644
View file @
afb83b77
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
;
}
}
share-system/src/main/java/share/system/domain/vo/OnlineQueryDto.java
View file @
afb83b77
...
...
@@ -18,7 +18,7 @@ public class OnlineQueryDto {
private
Integer
goodsCreatorType
;
//是否查询商品全量关联门店
//设置为true时,分页数量最大上限为20
private
b
oolean
queryAllPoi
;
private
B
oolean
queryAllPoi
;
//新商品查询参数,仅支持ka自研开发者使用,当前参数生效时goods_creator_type参数不再生效
//1 - 可查询归属于ka自研的所有商品,包括非ka自研创建的商品
private
Integer
goodsQueryType
;
...
...
share-system/src/main/java/share/system/service/impl/TiktokServiceImpl.java
View file @
afb83b77
...
...
@@ -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
()
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment