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
67c7dedd
Commit
67c7dedd
authored
Jan 26, 2024
by
吕明尚
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
增加抖音门店查询接口
parent
044c001f
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
98 additions
and
6 deletions
+98
-6
TiktokController.java
...in/java/share/web/controller/system/TiktokController.java
+7
-2
TiktokCouponDto.java
...src/main/java/share/system/domain/vo/TiktokCouponDto.java
+2
-0
TiktokService.java
...tem/src/main/java/share/system/service/TiktokService.java
+5
-0
TiktokServiceImpl.java
...ain/java/share/system/service/impl/TiktokServiceImpl.java
+84
-4
No files found.
share-front/src/main/java/share/web/controller/system/TiktokController.java
View file @
67c7dedd
...
...
@@ -41,8 +41,13 @@ public class TiktokController {
}
@GetMapping
(
"/certificate/get)"
)
public
String
certificateGet
()
{
return
""
;
public
String
certificateGet
(
TiktokCouponDto
tiktokCouponDto
)
{
return
tiktokService
.
certificateGet
(
tiktokCouponDto
);
}
@GetMapping
(
"/poi/query"
)
public
Object
poiQuery
(
TiktokCouponDto
tiktokCouponDto
)
{
return
tiktokService
.
poiQuery
(
tiktokCouponDto
);
}
}
share-system/src/main/java/share/system/domain/vo/TiktokCouponDto.java
View file @
67c7dedd
...
...
@@ -12,6 +12,8 @@ public class TiktokCouponDto {
private
String
code
;
//门店id
private
String
poiId
;
//商家账户 ID
private
String
accountId
;
//验券准备返回的标识
private
String
verifyToken
;
//验券准备接口返回的加密抖音券码
...
...
share-system/src/main/java/share/system/service/TiktokService.java
View file @
67c7dedd
package
share
.
system
.
service
;
import
cn.hutool.json.JSONArray
;
import
share.system.domain.vo.TiktokCouponDto
;
import
java.util.List
;
...
...
@@ -12,4 +13,8 @@ public interface TiktokService {
String
verify
(
TiktokCouponDto
tiktokCouponDto
);
String
cancel
(
TiktokCouponDto
tiktokCouponDto
);
String
certificateGet
(
TiktokCouponDto
tiktokCouponDto
);
Object
poiQuery
(
TiktokCouponDto
tiktokCouponDto
);
}
share-system/src/main/java/share/system/service/impl/TiktokServiceImpl.java
View file @
67c7dedd
...
...
@@ -5,7 +5,9 @@ import cn.hutool.core.date.DateUtil;
import
cn.hutool.http.HttpGlobalConfig
;
import
cn.hutool.http.HttpRequest
;
import
cn.hutool.http.HttpUtil
;
import
cn.hutool.json.JSONArray
;
import
cn.hutool.json.JSONObject
;
import
com.github.pagehelper.util.StringUtil
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.beans.factory.annotation.Autowired
;
...
...
@@ -19,8 +21,9 @@ 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
;
@Service
public
class
TiktokServiceImpl
implements
TiktokService
{
...
...
@@ -72,11 +75,15 @@ public class TiktokServiceImpl implements TiktokService {
//判断短链接是否以https://v.douyin.com/开头,/结尾
if
(
tiktokCouponDto
.
getEncryptedData
().
startsWith
(
"https://v.douyin.com/"
)
&&
tiktokCouponDto
.
getEncryptedData
().
endsWith
(
"/"
))
{
String
encryptedData
=
HttpRequest
.
get
(
tiktokCouponDto
.
getEncryptedData
()).
timeout
(
HttpGlobalConfig
.
getTimeout
()).
execute
().
body
();
String
objectId
=
result
.
substring
(
encryptedData
.
indexOf
(
"object_id="
)
+
"object_id="
.
length
(),
encryptedData
.
indexOf
(
"&"
));
Pattern
pattern
=
Pattern
.
compile
(
"object_id=([^&]*)"
);
Matcher
matcher
=
pattern
.
matcher
(
encryptedData
);
if
(
matcher
.
find
())
{
String
objectId
=
matcher
.
group
(
1
);
result
=
HttpRequest
.
get
(
url
)
.
contentType
(
"application/json"
)
.
header
(
"access-token"
,
accessToken
)
.
form
(
"encrypted_data"
,
objectId
).
form
(
"poi_id"
,
tiktokCouponDto
.
getPoiId
()).
execute
().
body
();
}
}
else
{
result
=
HttpRequest
.
get
(
url
)
...
...
@@ -94,10 +101,27 @@ public class TiktokServiceImpl implements TiktokService {
}
public
static
void
main
(
String
[]
args
)
{
String
url
=
"<a href=\"https://www.iesdouyin.com/share/commerce/coupon/I0duaGdVYnp0RitYekxkNm11VHl3WUVCM2wvWXNmNEZDcXZ3aGZDYm9ka3R2VjdualNOT1VGVzMxUkxmdWowTVp2VWVBams1OFAyK3YrMm4yc0lhQm90a0hPb1ZNRFk5V3VxTkhIV3hZTHQyelByMFJ5R2YzSy9FRjZXNDgvMTBXVno1NW5MaFFOYzRQbnFtRExpZGF5YzI4aTdBK3d6dnk3eFBUTVd2VkRRZkM/?schema_type=13&object_id=I0duaGdVYnp0RitYekxkNm11VHl3WUVCM2wvWXNmNEZDcXZ3aGZDYm9ka3R2VjdualNOT1VGVzMxUkxmdWowTVp2VWVBams1OFAyK3YrMm4yc0lhQm90a0hPb1ZNRFk5V3VxTkhIV3hZTHQyelByMFJ5R2YzSy9FRjZXNDgvMTBXVno1NW5MaFFOYzRQbnFtRExpZGF5YzI4aTdBK3d6dnk3eFBUTVd2VkRRZkM&utm_campaign=client_scan_share&app=aweme&utm_medium=ios&tt_from=scan_share&iid=&utm_source=scan_share\">Found</a>."
;
String
url
=
"<a href=\"https://www.iesdouyin.com/share/commerce/"
+
"coupon/I0duaGdVYnp0RitYekxkNm11VHl3WUVCM2wvWXNmNEZDcXZ3aGZDYm9ka3R2VjdualNOT1VGVzMxUkxmdWowTVp2VWVBams1OFAyK3YrMm4yc0lhQm90a0hPb1ZNRFk5V3VxTkhIV3hZTHQyelByMFJ5R2YzSy9FRjZXNDgvMTBXVno1NW5MaFFOYzRQbnFtRExpZGF5YzI4aTdBK3d6dnk3eFBUTVd2VkRRZkM/"
+
"?schema_type=13&"
+
"object_id=I0duaGdVYnp0RitYekxkNm11VHl3WUVCM2wvWXNmNEZDcXZ3aGZDYm9ka3R2VjdualNOT1VGVzMxUkxmdWowTVp2VWVBams1OFAyK3YrMm4yc0lhQm90a0hPb1ZNRFk5V3VxTkhIV3hZTHQyelByMFJ5R2YzSy9FRjZXNDgvMTBXVno1NW5MaFFOYzRQbnFtRExpZGF5YzI4aTdBK3d6dnk3eFBUTVd2VkRRZkM&"
+
"utm_campaign=client_scan_share&"
+
"app=aweme&"
+
"utm_medium=ios&"
+
"tt_from=scan_share&"
+
"iid=&"
+
"utm_source=scan_share\">Found</a>."
;
//截取中间的object_id=到&之间的字符串
String
objectId
=
url
.
substring
(
url
.
indexOf
(
"object_id="
)
+
"object_id="
.
length
(),
url
.
indexOf
(
"&"
));
Pattern
pattern
=
Pattern
.
compile
(
"object_id=([^&]*)"
);
Matcher
matcher
=
pattern
.
matcher
(
url
);
if
(
matcher
.
find
())
{
String
objectId
=
matcher
.
group
(
1
);
System
.
out
.
println
(
objectId
);
}
else
{
System
.
out
.
println
(
"No match found"
);
}
}
@Override
public
String
verify
(
TiktokCouponDto
tiktokCouponDto
)
{
String
accessToken
=
obtain
();
...
...
@@ -145,6 +169,62 @@ public class TiktokServiceImpl implements TiktokService {
return
data
.
getStr
(
"description"
);
}
@Override
public
String
certificateGet
(
TiktokCouponDto
tiktokCouponDto
)
{
String
accessToken
=
obtain
();
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
)
.
contentType
(
"application/json"
)
.
header
(
"access-token"
,
accessToken
)
.
form
(
"encrypted_code"
,
jsonObject
.
toString
()).
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"
);
}
return
data
.
getJSONObject
(
"certificate"
).
getStr
(
"status"
);
}
@Override
public
Object
poiQuery
(
TiktokCouponDto
tiktokCouponDto
)
{
String
accessToken
=
obtain
();
String
url
=
"https://open.douyin.com/goodlife/v1/shop/poi/query/"
;
String
result
=
null
;
if
(
StringUtil
.
isNotEmpty
(
tiktokCouponDto
.
getAccountId
()))
{
result
=
HttpRequest
.
post
(
url
)
.
contentType
(
"application/json"
)
.
header
(
"access-token"
,
accessToken
)
.
form
(
"account_id"
,
tiktokCouponDto
.
getAccountId
())
.
form
(
"page"
,
1
)
.
form
(
"size"
,
50
)
.
execute
().
body
();
}
else
{
result
=
HttpRequest
.
post
(
url
)
.
contentType
(
"application/json"
)
.
header
(
"access-token"
,
accessToken
)
.
form
(
"poi_id"
,
tiktokCouponDto
.
getAccountId
())
.
form
(
"page"
,
1
)
.
form
(
"size"
,
50
)
.
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
pois
=
data
.
getJSONArray
(
"pois"
);
Object
o
=
pois
.
get
(
0
);
JSONObject
object
=
new
JSONObject
(
o
);
//门店信息
JSONObject
poi
=
object
.
getJSONObject
(
"poi"
);
//生活服务商家账户信息
JSONObject
rootAccount
=
object
.
getJSONObject
(
"root_account"
);
return
pois
;
}
public
String
obtain
()
{
String
o
;
o
=
redisUtil
.
get
(
ReceiptRdeisEnum
.
TIKTOK_CLIENT_TOKEN
.
getValue
());
...
...
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