Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
J
jd-activity
Project
Project
Details
Activity
Releases
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
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
曾水平
jd-activity
Commits
5a19d829
Commit
5a19d829
authored
May 25, 2021
by
曾水平
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
优化
parent
4e1b7234
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
90 additions
and
65 deletions
+90
-65
Open2DuibaController.java
...com/duiba/jdactivity/controller/Open2DuibaController.java
+52
-50
DuibaAppEnum.java
...cn/com/duiba/jdactivity/developer/duiba/DuibaAppEnum.java
+6
-0
JdShopEnum.java
...om/duiba/jdactivity/developer/jd/constant/JdShopEnum.java
+23
-7
JdApiUtil.java
...cn/com/duiba/jdactivity/developer/jd/utils/JdApiUtil.java
+1
-1
autologin.html
src/main/resources/templates/autologin.html
+8
-7
No files found.
src/main/java/cn/com/duiba/jdactivity/controller/Open2DuibaController.java
View file @
5a19d829
...
@@ -49,12 +49,12 @@ import java.util.stream.Collectors;
...
@@ -49,12 +49,12 @@ import java.util.stream.Collectors;
public
class
Open2DuibaController
{
public
class
Open2DuibaController
{
public
static
final
Logger
LOGGER
=
LoggerFactory
.
getLogger
(
Open2DuibaController
.
class
);
public
static
final
Logger
LOGGER
=
LoggerFactory
.
getLogger
(
Open2DuibaController
.
class
);
public
static
final
String
ENCRYPT_KEY
=
"JuGi3FCECD1dA2BPL1lCWC=="
;
public
static
final
String
ENCRYPT_KEY
=
"JuGi3FCECD1dA2BPL1lCWC=="
;
//默认超时或提前5分钟
private
static
final
long
DEFAULT_EXPIRE_TIME
=
5
*
60
*
1000L
;
@Resource
@Resource
private
JdApiUtil
jdApiUtil
;
private
JdApiUtil
jdApiUtil
;
@Resource
@Resource
private
AccessTokenUtils
accessTokenUtils
;
private
AccessTokenUtils
accessTokenUtils
;
//默认超时或提前5分钟
private
static
final
long
DEFAULT_EXPIRE_TIME
=
5
*
60
*
1000L
;
/**
/**
* 根据环境获取不同的免登录地址
* 根据环境获取不同的免登录地址
...
@@ -81,6 +81,46 @@ public class Open2DuibaController {
...
@@ -81,6 +81,46 @@ public class Open2DuibaController {
return
host
+
path
;
return
host
+
path
;
}
}
/**
* 签名校验
*/
private
static
void
signVerify
(
String
method
)
throws
BizException
{
//后期若多个项目调用可改为注解方式
HttpServletRequest
request
=
RequestTool
.
getHttpServletRequest
();
final
Map
<
String
,
String
>
parameterMap
=
RequestTool
.
getRequestParamMap
(
request
);
LOGGER
.
info
(
method
+
"参数:"
+
JSON
.
toJSONString
(
parameterMap
));
//前后5分钟内有效
String
timestamp
=
request
.
getParameter
(
"timestamp"
);
String
appKey
=
request
.
getParameter
(
"appKey"
);
String
sign
=
request
.
getParameter
(
"sign"
);
DuibaAppEnum
duibaAppEnum
=
DuibaAppEnum
.
getDuibaApp
(
appKey
);
if
(
duibaAppEnum
==
null
)
{
throw
new
BizException
(
"appKey不存在"
);
}
long
clientTimestamp
=
timestamp
==
null
?
0L
:
Long
.
parseLong
(
timestamp
);
long
now
=
System
.
currentTimeMillis
();
if
(
Math
.
abs
(
now
-
clientTimestamp
)
>
DEFAULT_EXPIRE_TIME
)
{
throw
new
BizException
(
String
.
format
(
"请同步服务器与客户端时间为%s分钟之内"
,
DEFAULT_EXPIRE_TIME
));
}
//验签sign
Map
<
String
,
String
>
signMap
=
new
HashMap
<>(
parameterMap
);
signMap
.
remove
(
"sign"
);
signMap
.
put
(
"appSecret"
,
duibaAppEnum
.
getAppSecret
());
String
correctSign
=
SignTool
.
sign
(
signMap
);
boolean
signVerify
=
Objects
.
equals
(
correctSign
,
sign
);
boolean
verify
=
SignTool
.
signVerify
(
duibaAppEnum
.
getAppSecret
(),
request
);
LOGGER
.
info
(
"signVerify={},verify={},correctSign={}"
,
signVerify
,
verify
,
correctSign
);
// 二选一,只要有一个正确就通过
if
(!
signVerify
&&
!
verify
)
{
throw
new
BizException
(
"签名校验不正确"
);
}
}
/**
/**
* 微信、京东端 用户登陆后跳转到星速台
* 微信、京东端 用户登陆后跳转到星速台
*
*
...
@@ -90,21 +130,22 @@ public class Open2DuibaController {
...
@@ -90,21 +130,22 @@ public class Open2DuibaController {
public
Result
<
String
>
autologin
(
@RequestBody
AutologinParam
autologinParam
)
{
public
Result
<
String
>
autologin
(
@RequestBody
AutologinParam
autologinParam
)
{
try
{
try
{
LOGGER
.
info
(
"autologin,autologinParam={}"
,
JSON
.
toJSONString
(
autologinParam
));
LOGGER
.
info
(
"autologin,autologinParam={}"
,
JSON
.
toJSONString
(
autologinParam
));
JdShopEnum
jdShopEnum
=
JdShopEnum
.
BOSIDENG
;
Long
shopId
=
Optional
.
ofNullable
(
autologinParam
.
getShopId
()).
filter
(
aLong
->
aLong
!=
0L
).
orElse
(
jdShopEnum
.
getShopId
());
Long
venderId
=
Optional
.
ofNullable
(
autologinParam
.
getVenderId
()).
filter
(
aLong
->
aLong
!=
0L
).
orElse
(
jdShopEnum
.
getVenderId
());
String
token
=
autologinParam
.
getToken
();
String
token
=
autologinParam
.
getToken
();
String
source
=
autologinParam
.
getSource
();
String
source
=
JdTokenSourceEnum
.
JD
.
getSource
();
String
redirectUrl
=
autologinParam
.
getRedirectUrl
();
String
redirectUrl
=
autologinParam
.
getRedirectUrl
();
String
env
=
autologinParam
.
getEnv
();
String
env
=
autologinParam
.
getEnv
();
DuibaAppEnum
duibaApp
=
Optional
.
ofNullable
(
DuibaAppEnum
.
getDuibaApp
(
autologinParam
.
getAppKey
())).
orElse
(
DuibaAppEnum
.
TEST_4_27
);
// 京东店铺
JdShopEnum
jdShopEnum
=
Optional
.
ofNullable
(
JdShopEnum
.
getJdShop
(
autologinParam
.
getVenderId
(),
autologinParam
.
getShopId
()))
.
orElse
(
JdShopEnum
.
BOSIDENG
);
if
(
StringUtils
.
isBlank
(
source
))
{
// 兑吧应用
source
=
JdTokenSourceEnum
.
JD
.
getSource
();
DuibaAppEnum
duibaApp
=
Optional
}
.
ofNullable
(
DuibaAppEnum
.
getDuibaApp
(
autologinParam
.
getAppKey
()))
.
orElse
(
DuibaAppEnum
.
BOSIDENG_PROD
);
TbShopAccessTokenDto
accessToken
=
accessTokenUtils
.
getAccessTokenWithCache
(
venderId
,
shopId
);
TbShopAccessTokenDto
accessToken
=
accessTokenUtils
.
getAccessTokenWithCache
(
jdShopEnum
.
getVenderId
(),
jdShopEnum
.
getShopId
()
);
LOGGER
.
info
(
"获取accessToken,结果={}"
,
JSON
.
toJSONString
(
accessToken
));
LOGGER
.
info
(
"获取accessToken,结果={}"
,
JSON
.
toJSONString
(
accessToken
));
JdAppEnum
appByAppKey
=
JdAppEnum
.
getAppByAppKey
(
accessToken
.
getAppKey
());
JdAppEnum
appByAppKey
=
JdAppEnum
.
getAppByAppKey
(
accessToken
.
getAppKey
());
...
@@ -222,45 +263,6 @@ public class Open2DuibaController {
...
@@ -222,45 +263,6 @@ public class Open2DuibaController {
}
}
}
}
/**
* 签名校验
*/
private
void
signVerify
(
String
method
)
throws
BizException
{
//后期若多个项目调用可改为注解方式
HttpServletRequest
request
=
RequestTool
.
getHttpServletRequest
();
final
Map
<
String
,
String
>
parameterMap
=
RequestTool
.
getRequestParamMap
(
request
);
LOGGER
.
info
(
method
+
"参数:"
+
JSON
.
toJSONString
(
parameterMap
));
//前后5分钟内有效
String
timestamp
=
request
.
getParameter
(
"timestamp"
);
String
appKey
=
request
.
getParameter
(
"appKey"
);
String
sign
=
request
.
getParameter
(
"sign"
);
DuibaAppEnum
duibaAppEnum
=
DuibaAppEnum
.
getDuibaApp
(
appKey
);
if
(
duibaAppEnum
==
null
)
{
throw
new
BizException
(
"appKey不存在"
);
}
long
clientTimestamp
=
timestamp
==
null
?
0L
:
Long
.
parseLong
(
timestamp
);
long
now
=
System
.
currentTimeMillis
();
if
(
Math
.
abs
(
now
-
clientTimestamp
)
>
DEFAULT_EXPIRE_TIME
)
{
throw
new
BizException
(
String
.
format
(
"请同步服务器与客户端时间为%s分钟之内"
,
DEFAULT_EXPIRE_TIME
));
}
//验签sign
Map
<
String
,
String
>
signMap
=
new
HashMap
<>(
parameterMap
);
signMap
.
remove
(
"sign"
);
signMap
.
put
(
"appSecret"
,
duibaAppEnum
.
getAppSecret
());
String
correctSign
=
SignTool
.
sign
(
signMap
);
boolean
signVerify
=
Objects
.
equals
(
correctSign
,
sign
);
boolean
verify
=
SignTool
.
signVerify
(
duibaAppEnum
.
getAppSecret
(),
request
);
LOGGER
.
info
(
"signVerify={},verify={},correctSign={}"
,
signVerify
,
verify
,
correctSign
);
if
(!
signVerify
)
{
throw
new
BizException
(
"签名校验不正确"
);
}
}
/**
/**
* 是否是会员
* 是否是会员
*/
*/
...
...
src/main/java/cn/com/duiba/jdactivity/developer/duiba/DuibaAppEnum.java
View file @
5a19d829
package
cn
.
com
.
duiba
.
jdactivity
.
developer
.
duiba
;
package
cn
.
com
.
duiba
.
jdactivity
.
developer
.
duiba
;
import
org.apache.commons.lang3.StringUtils
;
import
java.util.Objects
;
import
java.util.Objects
;
/**
/**
...
@@ -9,6 +11,7 @@ import java.util.Objects;
...
@@ -9,6 +11,7 @@ import java.util.Objects;
public
enum
DuibaAppEnum
{
public
enum
DuibaAppEnum
{
WX
(
"微信公众号测试"
,
"3bRVpGghtsQXXeZpVH4VGi92Nr7V"
,
"28Ujh91mWeKSCZ4ndDyLWf527TN1"
),
WX
(
"微信公众号测试"
,
"3bRVpGghtsQXXeZpVH4VGi92Nr7V"
,
"28Ujh91mWeKSCZ4ndDyLWf527TN1"
),
TEST_4_27
(
"4-27测试"
,
"22KCCnB22yZihPnuB8gpqZhtdAka"
,
"ct8j6grNJ5cCqQcN1c8sTdSEdcK"
),
TEST_4_27
(
"4-27测试"
,
"22KCCnB22yZihPnuB8gpqZhtdAka"
,
"ct8j6grNJ5cCqQcN1c8sTdSEdcK"
),
BOSIDENG_PROD
(
"波司登线上"
,
"4EBS3taRKgKpKKSVg4xv4UnfEESh"
,
"2hMzuvExEE7XzfThv2fbnUKxRsXA"
),
;
;
...
@@ -35,6 +38,9 @@ public enum DuibaAppEnum {
...
@@ -35,6 +38,9 @@ public enum DuibaAppEnum {
}
}
public
static
DuibaAppEnum
getDuibaApp
(
String
appKey
)
{
public
static
DuibaAppEnum
getDuibaApp
(
String
appKey
)
{
if
(
StringUtils
.
isBlank
(
appKey
))
{
return
null
;
}
for
(
DuibaAppEnum
value
:
values
())
{
for
(
DuibaAppEnum
value
:
values
())
{
if
(
Objects
.
equals
(
value
.
getAppKey
(),
appKey
))
{
if
(
Objects
.
equals
(
value
.
getAppKey
(),
appKey
))
{
return
value
;
return
value
;
...
...
src/main/java/cn/com/duiba/jdactivity/developer/jd/constant/JdShopEnum.java
View file @
5a19d829
package
cn
.
com
.
duiba
.
jdactivity
.
developer
.
jd
.
constant
;
package
cn
.
com
.
duiba
.
jdactivity
.
developer
.
jd
.
constant
;
import
java.util.Objects
;
public
enum
JdShopEnum
{
public
enum
JdShopEnum
{
DUIBA
(
"杭州兑吧"
,
10
139787L
,
1027649
7L
),
DUIBA
(
"杭州兑吧"
,
10
276497L
,
1013978
7L
),
BOSIDENG
(
"波司登官方旗舰店"
,
4
4892L
,
48034
L
);
BOSIDENG
(
"波司登官方旗舰店"
,
4
8034L
,
44892
L
);
private
final
String
shopName
;
private
final
String
shopName
;
/**
* 店铺Id
*/
private
final
Long
shopId
;
/**
/**
* 商家Id
* 商家Id
*/
*/
private
final
Long
venderId
;
private
final
Long
venderId
;
JdShopEnum
(
String
shopName
,
Long
shopId
,
Long
venderId
)
{
/**
* 店铺Id
*/
private
final
Long
shopId
;
JdShopEnum
(
String
shopName
,
Long
venderId
,
Long
shopId
)
{
this
.
shopName
=
shopName
;
this
.
shopName
=
shopName
;
this
.
shopId
=
shopId
;
this
.
shopId
=
shopId
;
this
.
venderId
=
venderId
;
this
.
venderId
=
venderId
;
...
@@ -31,4 +35,16 @@ public enum JdShopEnum {
...
@@ -31,4 +35,16 @@ public enum JdShopEnum {
public
Long
getVenderId
()
{
public
Long
getVenderId
()
{
return
venderId
;
return
venderId
;
}
}
public
static
JdShopEnum
getJdShop
(
Long
venderId
,
Long
shopId
)
{
if
(
venderId
==
null
||
shopId
==
null
||
venderId
==
0L
||
shopId
==
0L
)
{
return
null
;
}
for
(
JdShopEnum
value
:
values
())
{
if
(
Objects
.
equals
(
value
.
getVenderId
(),
venderId
)
&&
Objects
.
equals
(
value
.
getShopId
(),
shopId
))
{
return
value
;
}
}
return
null
;
}
}
}
src/main/java/cn/com/duiba/jdactivity/developer/jd/utils/JdApiUtil.java
View file @
5a19d829
...
@@ -426,7 +426,7 @@ public class JdApiUtil {
...
@@ -426,7 +426,7 @@ public class JdApiUtil {
// 分享类型 1 分享 2 不分享(如设置京券 type=0,2 不分享
// 分享类型 1 分享 2 不分享(如设置京券 type=0,2 不分享
request
.
setShareType
(
2
);
request
.
setShareType
(
2
);
// 活动返回链接
// 活动返回链接
request
.
setActivityLink
(
"www.jd.com"
);
//
request.setActivityLink("www.jd.com");
// 会员类别
// 会员类别
// request.setUserClass(20000);
// request.setUserClass(20000);
// request.setPaidMembers("[]");
// request.setPaidMembers("[]");
...
...
src/main/resources/templates/autologin.html
View file @
5a19d829
...
@@ -3,7 +3,7 @@
...
@@ -3,7 +3,7 @@
<head>
<head>
<meta
charset=
"UTF-8"
>
<meta
charset=
"UTF-8"
>
<title>
免登录
</title>
<title>
正在加载..
</title>
<meta
name=
"viewport"
<meta
name=
"viewport"
content=
"width=device-width,initial-scale=1, minimum-scale=1, maximum-scale=1, user-scalable=no"
/>
content=
"width=device-width,initial-scale=1, minimum-scale=1, maximum-scale=1, user-scalable=no"
/>
<meta
name=
"apple-mobile-web-app-capable"
content=
"yes"
/>
<meta
name=
"apple-mobile-web-app-capable"
content=
"yes"
/>
...
@@ -13,18 +13,18 @@
...
@@ -13,18 +13,18 @@
<meta
name=
"360-fullscreen"
content=
"true"
/>
<meta
name=
"360-fullscreen"
content=
"true"
/>
<!-- <script src="./jssdk.min.js"></script> -->
<!-- <script src="./jssdk.min.js"></script> -->
<script
src=
"//yun.duiba.com.cn/aurora/assets/4c37d75a75d8e7534d9e3b056911ba06ac5bf8f8.js"
></script>
<script
src=
"//yun.duiba.com.cn/aurora/assets/4c37d75a75d8e7534d9e3b056911ba06ac5bf8f8.js"
></script>
<script
src=
"//yun.duiba.com.cn/js-libs/vConsole/3.3.4/vconsole.min.js"
></script>
<!-- <script src="//yun.duiba.com.cn/js-libs/vConsole/3.3.4/vconsole.min.js"></script> -->
<script
src=
"https://s3.pstatp.com/cdn/expire-1-M/jquery/3.3.1/jquery.min.js"
></script>
<!-- jquery.min.js -->
<script
src=
"//yun.duiba.com.cn/aurora/assets/68c35424c0c72de8d0d9ac316c85fcb67fc23f2d.js"
></script>
<script
src=
"//h5static.m.jd.com/act/jm-jdshare/2.0.0/jm-jdshare.js"
></script>
<script
src=
"//h5static.m.jd.com/act/jm-jdshare/2.0.0/jm-jdshare.js"
></script>
<script>
<script>
new
VConsole
();
//
new VConsole();
</script>
</script>
<style>
<style>
.box
{
.box
{
width
:
100%
;
width
:
100%
;
height
:
100vh
;
height
:
100vh
;
}
}
.box
>
div
{
.box
>
div
{
...
@@ -41,8 +41,8 @@
...
@@ -41,8 +41,8 @@
<body>
<body>
<div
class=
"box"
>
<div
class=
"box"
>
<
div
onclick=
"openLoginPanel()"
>
唤起登录面板
</div
>
<
!-- <div onclick="openLoginPanel()">唤起登录面板</div> --
>
<
div
onclick=
"jumpToPage()"
>
跳转
</div
>
<
!-- <div onclick="jumpToPage()">跳转</div> --
>
</div>
</div>
<script
language=
"javascript"
>
<script
language=
"javascript"
>
(
function
()
{
(
function
()
{
...
@@ -111,6 +111,7 @@
...
@@ -111,6 +111,7 @@
console
.
log
(
"autoLogin返回参数:"
,
data
)
console
.
log
(
"autoLogin返回参数:"
,
data
)
pageUrl
=
data
.
data
;
pageUrl
=
data
.
data
;
console
.
log
(
pageUrl
)
console
.
log
(
pageUrl
)
window
.
location
.
href
=
pageUrl
;
},
},
complete
:
function
()
{
complete
:
function
()
{
},
},
...
...
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