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
044c001f
Commit
044c001f
authored
Jan 26, 2024
by
吕明尚
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
修改抖音验卷准备逻辑
parent
a7988a71
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
104 additions
and
16 deletions
+104
-16
TiktokController.java
...in/java/share/web/controller/system/TiktokController.java
+21
-4
TiktokCouponDto.java
...src/main/java/share/system/domain/vo/TiktokCouponDto.java
+27
-0
TiktokService.java
...tem/src/main/java/share/system/service/TiktokService.java
+6
-2
TiktokServiceImpl.java
...ain/java/share/system/service/impl/TiktokServiceImpl.java
+50
-10
No files found.
share-front/src/main/java/share/web/controller/system/TiktokController.java
View file @
044c001f
...
@@ -4,6 +4,7 @@ import org.springframework.beans.factory.annotation.Autowired;
...
@@ -4,6 +4,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import
org.springframework.web.bind.annotation.GetMapping
;
import
org.springframework.web.bind.annotation.GetMapping
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RestController
;
import
org.springframework.web.bind.annotation.RestController
;
import
share.system.domain.vo.TiktokCouponDto
;
import
share.system.service.TiktokService
;
import
share.system.service.TiktokService
;
import
java.util.List
;
import
java.util.List
;
...
@@ -14,18 +15,34 @@ public class TiktokController {
...
@@ -14,18 +15,34 @@ public class TiktokController {
@Autowired
@Autowired
private
TiktokService
tiktokService
;
private
TiktokService
tiktokService
;
//权限限验证接口,返回client_token,用于调用其他接口,如果不需要,可以不用这个接口
@GetMapping
(
"/oauth/clientToken"
)
@GetMapping
(
"/oauth/clientToken"
)
public
void
clientToken
()
{
public
void
clientToken
()
{
tiktokService
.
clientToken
();
tiktokService
.
clientToken
();
}
}
//验卷准备接口,返回code,用于调用其他接口
@GetMapping
(
"/certificate/prepare"
)
@GetMapping
(
"/certificate/prepare"
)
public
String
prepare
(
String
code
,
String
poiId
)
{
public
String
prepare
(
TiktokCouponDto
tiktokCouponDto
)
{
return
tiktokService
.
prepare
(
code
,
poiId
);
return
tiktokService
.
prepare
(
tiktokCouponDto
);
}
}
//验卷接口,返回验卷结果
@GetMapping
(
"/certificate/verify"
)
@GetMapping
(
"/certificate/verify"
)
public
String
verify
(
String
verifyToken
,
String
poiId
,
List
<
String
>
encryptedCodes
)
{
public
String
verify
(
TiktokCouponDto
tiktokCouponDto
)
{
return
tiktokService
.
verify
(
verifyToken
,
poiId
,
encryptedCodes
);
return
tiktokService
.
verify
(
tiktokCouponDto
);
}
//撤销核销接口,返回撤销结果
@GetMapping
(
"/certificate/cancel"
)
public
String
cancel
(
TiktokCouponDto
tiktokCouponDto
)
{
return
tiktokService
.
cancel
(
tiktokCouponDto
);
}
}
@GetMapping
(
"/certificate/get)"
)
public
String
certificateGet
()
{
return
""
;
}
}
}
share-system/src/main/java/share/system/domain/vo/TiktokCouponDto.java
0 → 100644
View file @
044c001f
package
share
.
system
.
domain
.
vo
;
import
lombok.Data
;
import
java.util.List
;
@Data
public
class
TiktokCouponDto
{
//短链接
private
String
encryptedData
;
//劵码
private
String
code
;
//门店id
private
String
poiId
;
//验券准备返回的标识
private
String
verifyToken
;
//验券准备接口返回的加密抖音券码
private
List
<
String
>
encryptedCodes
;
//验卷接口返回 券码一次核销的唯一标识
private
String
verifyId
;
//券码的标识(验券时返回)
private
String
certificateId
;
//验券准备接口返回的加密券码
private
String
encryptedCode
;
}
share-system/src/main/java/share/system/service/TiktokService.java
View file @
044c001f
package
share
.
system
.
service
;
package
share
.
system
.
service
;
import
share.system.domain.vo.TiktokCouponDto
;
import
java.util.List
;
import
java.util.List
;
public
interface
TiktokService
{
public
interface
TiktokService
{
void
clientToken
();
void
clientToken
();
String
prepare
(
String
code
,
String
poiId
);
String
prepare
(
TiktokCouponDto
tiktokCouponDto
);
String
verify
(
TiktokCouponDto
tiktokCouponDto
);
String
verify
(
String
verifyToken
,
String
poiId
,
List
<
String
>
encryptedCodes
);
String
cancel
(
TiktokCouponDto
tiktokCouponDto
);
}
}
share-system/src/main/java/share/system/service/impl/TiktokServiceImpl.java
View file @
044c001f
...
@@ -2,6 +2,7 @@ package share.system.service.impl;
...
@@ -2,6 +2,7 @@ package share.system.service.impl;
import
cn.hutool.core.date.DatePattern
;
import
cn.hutool.core.date.DatePattern
;
import
cn.hutool.core.date.DateUtil
;
import
cn.hutool.core.date.DateUtil
;
import
cn.hutool.http.HttpGlobalConfig
;
import
cn.hutool.http.HttpRequest
;
import
cn.hutool.http.HttpRequest
;
import
cn.hutool.http.HttpUtil
;
import
cn.hutool.http.HttpUtil
;
import
cn.hutool.json.JSONObject
;
import
cn.hutool.json.JSONObject
;
...
@@ -13,6 +14,7 @@ import share.common.core.redis.RedisUtil;
...
@@ -13,6 +14,7 @@ import share.common.core.redis.RedisUtil;
import
share.common.enums.ErrorCodeEnum
;
import
share.common.enums.ErrorCodeEnum
;
import
share.common.enums.ReceiptRdeisEnum
;
import
share.common.enums.ReceiptRdeisEnum
;
import
share.common.enums.VerifyResultsEnum
;
import
share.common.enums.VerifyResultsEnum
;
import
share.system.domain.vo.TiktokCouponDto
;
import
share.system.service.TiktokService
;
import
share.system.service.TiktokService
;
import
java.util.Date
;
import
java.util.Date
;
...
@@ -63,13 +65,25 @@ public class TiktokServiceImpl implements TiktokService {
...
@@ -63,13 +65,25 @@ public class TiktokServiceImpl implements TiktokService {
}
}
@Override
@Override
public
String
prepare
(
String
code
,
String
poiId
)
{
public
String
prepare
(
TiktokCouponDto
tiktokCouponDto
)
{
String
accessToken
=
obtain
();
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
=
HttpRequest
.
get
(
url
)
String
result
=
""
;
//判断短链接是否以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
(
"&"
));
result
=
HttpRequest
.
get
(
url
)
.
contentType
(
"application/json"
)
.
contentType
(
"application/json"
)
.
header
(
"access-token"
,
accessToken
)
.
header
(
"access-token"
,
accessToken
)
.
form
(
"code"
,
code
).
form
(
"poi_id"
,
poiId
).
execute
().
body
();
.
form
(
"encrypted_data"
,
objectId
).
form
(
"poi_id"
,
tiktokCouponDto
.
getPoiId
()).
execute
().
body
();
}
else
{
result
=
HttpRequest
.
get
(
url
)
.
contentType
(
"application/json"
)
.
header
(
"access-token"
,
accessToken
)
.
form
(
"code"
,
tiktokCouponDto
.
getCode
()).
form
(
"poi_id"
,
tiktokCouponDto
.
getPoiId
()).
execute
().
body
();
}
JSONObject
entries
=
new
JSONObject
(
result
);
JSONObject
entries
=
new
JSONObject
(
result
);
JSONObject
data
=
entries
.
getJSONObject
(
"data"
);
JSONObject
data
=
entries
.
getJSONObject
(
"data"
);
if
(!
data
.
getStr
(
"error_code"
).
equals
(
ErrorCodeEnum
.
SUCCESS
.
getCode
()))
{
if
(!
data
.
getStr
(
"error_code"
).
equals
(
ErrorCodeEnum
.
SUCCESS
.
getCode
()))
{
...
@@ -79,14 +93,19 @@ public class TiktokServiceImpl implements TiktokService {
...
@@ -79,14 +93,19 @@ public class TiktokServiceImpl implements TiktokService {
return
data
.
getStr
(
"verify_token"
);
return
data
.
getStr
(
"verify_token"
);
}
}
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>."
;
//截取中间的object_id=到&之间的字符串
String
objectId
=
url
.
substring
(
url
.
indexOf
(
"object_id="
)
+
"object_id="
.
length
(),
url
.
indexOf
(
"&"
));
}
@Override
@Override
public
String
verify
(
String
verifyToken
,
String
poiId
,
List
<
String
>
encryptedCodes
)
{
public
String
verify
(
TiktokCouponDto
tiktokCouponDto
)
{
String
accessToken
=
obtain
();
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
<
String
,
Object
>
map
=
new
HashMap
<>();
map
.
put
(
"verify_token"
,
verifyToken
);
map
.
put
(
"verify_token"
,
tiktokCouponDto
.
getVerifyToken
()
);
map
.
put
(
"poi_id"
,
poiId
);
map
.
put
(
"poi_id"
,
tiktokCouponDto
.
getPoiId
()
);
map
.
put
(
"encrypted_codes"
,
encryptedCodes
);
map
.
put
(
"encrypted_codes"
,
tiktokCouponDto
.
getEncryptedCodes
()
);
JSONObject
jsonObject
=
new
JSONObject
(
map
);
JSONObject
jsonObject
=
new
JSONObject
(
map
);
String
result
=
HttpRequest
.
post
(
url
)
String
result
=
HttpRequest
.
post
(
url
)
.
contentType
(
"application/json"
)
.
contentType
(
"application/json"
)
...
@@ -100,11 +119,32 @@ public class TiktokServiceImpl implements TiktokService {
...
@@ -100,11 +119,32 @@ public class TiktokServiceImpl implements TiktokService {
}
else
if
(
data
.
getStr
(
"error_code"
).
equals
(
"1208"
)
||
data
.
getJSONObject
(
"verify_results"
).
getStr
(
"result"
).
equals
(
VerifyResultsEnum
.
COOKED
.
getCode
()))
{
}
else
if
(
data
.
getStr
(
"error_code"
).
equals
(
"1208"
)
||
data
.
getJSONObject
(
"verify_results"
).
getStr
(
"result"
).
equals
(
VerifyResultsEnum
.
COOKED
.
getCode
()))
{
return
"验卷成功"
;
return
"验卷成功"
;
}
else
if
(!
data
.
getStr
(
"error_code"
).
equals
(
ErrorCodeEnum
.
SUCCESS
.
getCode
()))
{
}
else
if
(!
data
.
getStr
(
"error_code"
).
equals
(
ErrorCodeEnum
.
SUCCESS
.
getCode
()))
{
compensate
(
verifyToken
,
poiId
,
encryptedCodes
);
compensate
(
tiktokCouponDto
);
}
}
return
"验卷失败"
;
return
"验卷失败"
;
}
}
@Override
public
String
cancel
(
TiktokCouponDto
tiktokCouponDto
)
{
String
accessToken
=
obtain
();
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
)
.
contentType
(
"application/json"
)
.
header
(
"access-token"
,
accessToken
)
.
body
(
jsonObject
.
toString
()).
execute
().
body
();
JSONObject
entries
=
new
JSONObject
(
result
);
JSONObject
data
=
entries
.
getJSONObject
(
"data"
);
if
(!
data
.
getStr
(
"error_code"
).
equals
(
ErrorCodeEnum
.
SUCCESS
.
getCode
()))
{
logger
.
error
(
"抖音撤销核销失败:{}"
,
data
.
getStr
(
"description"
));
throw
new
RuntimeException
(
data
.
getStr
(
"description"
));
}
return
data
.
getStr
(
"description"
);
}
public
String
obtain
()
{
public
String
obtain
()
{
String
o
;
String
o
;
o
=
redisUtil
.
get
(
ReceiptRdeisEnum
.
TIKTOK_CLIENT_TOKEN
.
getValue
());
o
=
redisUtil
.
get
(
ReceiptRdeisEnum
.
TIKTOK_CLIENT_TOKEN
.
getValue
());
...
@@ -117,11 +157,11 @@ public class TiktokServiceImpl implements TiktokService {
...
@@ -117,11 +157,11 @@ public class TiktokServiceImpl implements TiktokService {
return
sessionKey
.
getStr
(
"accessToken"
);
return
sessionKey
.
getStr
(
"accessToken"
);
}
}
public
void
compensate
(
String
verifyToken
,
String
poiId
,
List
<
String
>
encryptedCodes
)
{
public
void
compensate
(
TiktokCouponDto
tiktokCouponDto
)
{
//间隔5秒
//间隔5秒
try
{
try
{
Thread
.
sleep
(
5000
);
Thread
.
sleep
(
5000
);
verify
(
verifyToken
,
poiId
,
encryptedCodes
);
verify
(
tiktokCouponDto
);
}
catch
(
InterruptedException
e
)
{
}
catch
(
InterruptedException
e
)
{
throw
new
RuntimeException
(
e
);
throw
new
RuntimeException
(
e
);
}
}
...
...
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