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
c8e3be05
Commit
c8e3be05
authored
Jan 25, 2024
by
吕明尚
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
抖音验卷接口
parent
e5ca5348
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
77 additions
and
9 deletions
+77
-9
TiktokController.java
...in/java/share/web/controller/system/TiktokController.java
+8
-2
TiktokService.java
...tem/src/main/java/share/system/service/TiktokService.java
+5
-1
TiktokServiceImpl.java
...ain/java/share/system/service/impl/TiktokServiceImpl.java
+60
-6
SignUtil.java
share-system/src/main/java/share/system/util/SignUtil.java
+4
-0
No files found.
share-front/src/main/java/share/web/controller/system/TiktokController.java
View file @
c8e3be05
...
@@ -6,6 +6,8 @@ import org.springframework.web.bind.annotation.RequestMapping;
...
@@ -6,6 +6,8 @@ import org.springframework.web.bind.annotation.RequestMapping;
import
org.springframework.web.bind.annotation.RestController
;
import
org.springframework.web.bind.annotation.RestController
;
import
share.system.service.TiktokService
;
import
share.system.service.TiktokService
;
import
java.util.List
;
@RestController
@RestController
@RequestMapping
(
"/chessCards"
)
@RequestMapping
(
"/chessCards"
)
public
class
TiktokController
{
public
class
TiktokController
{
...
@@ -18,8 +20,12 @@ public class TiktokController {
...
@@ -18,8 +20,12 @@ public class TiktokController {
}
}
@GetMapping
(
"/certificate/prepare"
)
@GetMapping
(
"/certificate/prepare"
)
public
void
prepare
(
String
code
,
String
poiId
)
{
public
String
prepare
(
String
code
,
String
poiId
)
{
tiktokService
.
prepare
(
code
,
poiId
);
return
tiktokService
.
prepare
(
code
,
poiId
);
}
}
@GetMapping
(
"/certificate/verify"
)
public
String
verify
(
String
verifyToken
,
String
poiId
,
List
<
String
>
encryptedCodes
)
{
return
tiktokService
.
verify
(
verifyToken
,
poiId
,
encryptedCodes
);
}
}
}
share-system/src/main/java/share/system/service/TiktokService.java
View file @
c8e3be05
package
share
.
system
.
service
;
package
share
.
system
.
service
;
import
java.util.List
;
public
interface
TiktokService
{
public
interface
TiktokService
{
void
clientToken
();
void
clientToken
();
void
prepare
(
String
code
,
String
poiId
);
String
prepare
(
String
code
,
String
poiId
);
String
verify
(
String
verifyToken
,
String
poiId
,
List
<
String
>
encryptedCodes
);
}
}
share-system/src/main/java/share/system/service/impl/TiktokServiceImpl.java
View file @
c8e3be05
...
@@ -18,6 +18,7 @@ import share.system.service.TiktokService;
...
@@ -18,6 +18,7 @@ import share.system.service.TiktokService;
import
java.util.Date
;
import
java.util.Date
;
import
java.util.HashMap
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Map
;
@Service
@Service
...
@@ -41,8 +42,7 @@ public class TiktokServiceImpl implements TiktokService {
...
@@ -41,8 +42,7 @@ public class TiktokServiceImpl implements TiktokService {
tokenMap
.
put
(
"grant_type"
,
"client_credentials"
);
tokenMap
.
put
(
"grant_type"
,
"client_credentials"
);
String
post
=
HttpUtil
.
post
(
url
,
tokenMap
);
String
post
=
HttpUtil
.
post
(
url
,
tokenMap
);
JSONObject
sessionKey
=
new
JSONObject
(
post
);
JSONObject
sessionKey
=
new
JSONObject
(
post
);
String
data
=
sessionKey
.
getStr
(
"data"
);
JSONObject
dataJson
=
sessionKey
.
getJSONObject
(
"data"
);
JSONObject
dataJson
=
new
JSONObject
(
data
);
String
errorCode
=
dataJson
.
getStr
(
"error_code"
);
String
errorCode
=
dataJson
.
getStr
(
"error_code"
);
if
(!
errorCode
.
equals
(
ErrorCodeEnum
.
SUCCESS
.
getCode
()))
{
if
(!
errorCode
.
equals
(
ErrorCodeEnum
.
SUCCESS
.
getCode
()))
{
logger
.
error
(
"抖音授权失败:{}"
,
dataJson
.
getStr
(
"description"
));
logger
.
error
(
"抖音授权失败:{}"
,
dataJson
.
getStr
(
"description"
));
...
@@ -64,15 +64,69 @@ public class TiktokServiceImpl implements TiktokService {
...
@@ -64,15 +64,69 @@ public class TiktokServiceImpl implements TiktokService {
}
}
@Override
@Override
public
void
prepare
(
String
code
,
String
poiId
)
{
public
String
prepare
(
String
code
,
String
poiId
)
{
String
o
=
redisUtil
.
get
(
ReceiptRdeisEnum
.
TIKTOK_CLIENT_TOKEN
.
getValue
());
String
accessToken
=
obtain
();
JSONObject
sessionKey
=
new
JSONObject
(
o
);
String
accessToken
=
sessionKey
.
getStr
(
"accessToken"
);
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
=
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
(
"code"
,
code
).
form
(
"poi_id"
,
poiId
).
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
(
"verify_token"
);
}
@Override
public
String
verify
(
String
verifyToken
,
String
poiId
,
List
<
String
>
encryptedCodes
)
{
String
accessToken
=
obtain
();
String
url
=
"https://open.douyin.com/goodlife/v1/fulfilment/certificate/verify/"
;
Map
<
String
,
Object
>
map
=
new
HashMap
<>();
map
.
put
(
"verify_token"
,
verifyToken
);
map
.
put
(
"poi_id"
,
poiId
);
map
.
put
(
"encrypted_codes"
,
encryptedCodes
);
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"
);
JSONObject
extra
=
entries
.
getJSONObject
(
"extra"
);
if
(
data
.
getStr
(
"error_code"
).
equals
(
ErrorCodeEnum
.
SUCCESS
.
getCode
())
&&
data
.
getJSONObject
(
"verify_results"
).
getStr
(
"result"
).
equals
(
ErrorCodeEnum
.
SUCCESS
.
getCode
()))
{
return
"验卷成功"
;
}
else
if
(
data
.
getStr
(
"error_code"
).
equals
(
"1208"
)
||
data
.
getJSONObject
(
"verify_results"
).
getStr
(
"result"
).
equals
(
"2"
))
{
return
"验卷成功"
;
}
else
if
(!
data
.
getStr
(
"error_code"
).
equals
(
ErrorCodeEnum
.
SUCCESS
.
getCode
()))
{
return
"验卷失败"
;
}
return
"验卷失败"
;
}
}
public
String
obtain
()
{
String
o
;
o
=
redisUtil
.
get
(
ReceiptRdeisEnum
.
TIKTOK_CLIENT_TOKEN
.
getValue
());
//过期时间小于当前时间 重新获取token
if
(
new
JSONObject
(
o
).
getDate
(
"expiresTime"
).
getTime
()
<
System
.
currentTimeMillis
())
{
clientToken
();
o
=
redisUtil
.
get
(
ReceiptRdeisEnum
.
TIKTOK_CLIENT_TOKEN
.
getValue
());
}
JSONObject
sessionKey
=
new
JSONObject
(
o
);
return
sessionKey
.
getStr
(
"accessToken"
);
}
public
void
compensate
(
String
verifyToken
,
String
poiId
,
List
<
String
>
encryptedCodes
)
{
//间隔5秒
try
{
Thread
.
sleep
(
5000
);
verify
(
verifyToken
,
poiId
,
encryptedCodes
);
}
catch
(
InterruptedException
e
)
{
throw
new
RuntimeException
(
e
);
}
}
}
}
share-system/src/main/java/share/system/util/SignUtil.java
View file @
c8e3be05
package
share
.
system
.
util
;
package
share
.
system
.
util
;
import
org.springframework.beans.factory.annotation.Value
;
import
javax.crypto.Cipher
;
import
javax.crypto.Cipher
;
import
javax.crypto.spec.IvParameterSpec
;
import
javax.crypto.spec.IvParameterSpec
;
import
javax.crypto.spec.SecretKeySpec
;
import
javax.crypto.spec.SecretKeySpec
;
...
@@ -9,7 +11,9 @@ public class SignUtil {
...
@@ -9,7 +11,9 @@ public class SignUtil {
/*
/*
* appid/client_key对应的client_secret TODO 这里换成服务商的appsecret
* appid/client_key对应的client_secret TODO 这里换成服务商的appsecret
*/
*/
// @Value("${client_secret}")
private
static
final
String
secret
=
"12345678901234566543210987654321"
;
private
static
final
String
secret
=
"12345678901234566543210987654321"
;
// @Value("${client_key}")
private
static
final
String
key
;
private
static
final
String
key
;
private
static
final
String
iv
;
private
static
final
String
iv
;
...
...
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