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
b705bc48
Commit
b705bc48
authored
May 18, 2021
by
曾水平
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
多环境配置
parent
ef6c1beb
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
69 additions
and
54 deletions
+69
-54
AppController.java
...ava/cn/com/duiba/jdactivity/controller/AppController.java
+21
-34
IndexController.java
...a/cn/com/duiba/jdactivity/controller/IndexController.java
+15
-0
AccessTokenUtils.java
...duiba/jdactivity/developer/jd/utils/AccessTokenUtils.java
+6
-0
application-dev.properties
src/main/resources/application-dev.properties
+11
-0
application-prod.properties
src/main/resources/application-prod.properties
+12
-0
application.properties
src/main/resources/application.properties
+2
-17
index.html
src/main/resources/static/index.html
+1
-1
ControllerTest.java
src/test/java/cn/com/duiba/jdactivity/ControllerTest.java
+1
-2
No files found.
src/main/java/cn/com/duiba/jdactivity/controller/
Sho
pController.java
→
src/main/java/cn/com/duiba/jdactivity/controller/
Ap
pController.java
View file @
b705bc48
...
...
@@ -7,13 +7,14 @@ import cn.com.duiba.jdactivity.developer.jd.domain.JosParameters;
import
cn.com.duiba.jdactivity.developer.jd.utils.AccessTokenUtils
;
import
cn.com.duiba.jdactivity.developer.jd.utils.ApiUtil
;
import
cn.com.duiba.jdactivity.developer.jd.utils.LoginUtils
;
import
cn.com.duiba.jdactivity.dto.TbShopAccessTokenDto
;
import
com.jd.open.api.sdk.domain.seller.ShopSafService.response.query.ShopJosResult
;
import
org.apache.commons.lang3.StringUtils
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.stereotype.Controller
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RequestParam
;
import
org.springframework.web.bind.annotation.RestController
;
import
javax.annotation.Resource
;
...
...
@@ -23,10 +24,10 @@ import javax.annotation.Resource;
* @author zsp (zengshuiping@duiba.com.cn)
* @date 2021/5/13 13:58
*/
@
Rest
Controller
@RequestMapping
(
"/
sho
p"
)
public
class
Sho
pController
{
public
static
final
Logger
LOGGER
=
LoggerFactory
.
getLogger
(
Sho
pController
.
class
);
@Controller
@RequestMapping
(
"/
ap
p"
)
public
class
Ap
pController
{
public
static
final
Logger
LOGGER
=
LoggerFactory
.
getLogger
(
Ap
pController
.
class
);
@Resource
private
AccessTokenUtils
accessTokenUtils
;
...
...
@@ -34,25 +35,32 @@ public class ShopController {
@Resource
private
ApiUtil
apiUtil
;
/**
* 应用插件启动唤起页
*/
@RequestMapping
(
"/login"
)
public
String
login
(
String
code
,
String
state
)
{
@RequestParam
(
required
=
false
)
String
state
)
{
LOGGER
.
info
(
"login,code={},state={}"
,
code
,
state
);
if
(
StringUtils
.
isAnyBlank
(
code
,
state
))
{
if
(
StringUtils
.
isAnyBlank
(
code
))
{
return
"参数缺失"
;
}
JosParameters
josParameters
=
LoginUtils
.
getStateParam
(
state
);
// 获取appKey
String
appKey
=
AppEnum
.
DUIBA
.
getAppKey
();
if
(
StringUtils
.
isBlank
(
state
))
{
JosParameters
josParameters
=
LoginUtils
.
getStateParam
(
state
);
appKey
=
josParameters
.
getApp_key
();
}
AppEnum
appEnum
=
AppEnum
.
getAppByAppKey
(
josParameters
.
getApp_key
()
);
AppEnum
appEnum
=
AppEnum
.
getAppByAppKey
(
appKey
);
if
(
appEnum
==
null
)
{
return
"appKey参数不合法"
;
}
AccessTokenResponse
accessTokenByCode
=
accessTokenUtils
.
getAccessTokenByCode
(
appEnum
,
code
);
if
(!
accessTokenByCode
.
isOk
())
{
Result
<
ShopJosResult
>
shopJosResultResult
=
apiUtil
.
venderShopQuery
(
appEnum
,
accessTokenByCode
.
getAccess_token
());
if
(
shopJosResultResult
.
getSuccess
())
{
ShopJosResult
data
=
shopJosResultResult
.
getData
();
...
...
@@ -63,34 +71,13 @@ public class ShopController {
// 保存入库
}
return
null
;
return
"/shop/index"
;
}
@RequestMapping
(
"/getShopInfoVO"
)
public
String
getShopInfoVO
(
@RequestParam
(
required
=
false
,
defaultValue
=
"B0F491866BC8C8BA5954B4DFCCF283CC"
)
String
appKey
,
String
code
,
@RequestParam
(
required
=
false
)
String
state
)
{
if
(
StringUtils
.
isBlank
(
code
))
{
return
"code参数缺失"
;
}
AppEnum
appEnum
=
AppEnum
.
getAppByAppKey
(
appKey
);
if
(
appEnum
==
null
)
{
return
"appKey参数不合法"
;
}
if
(
StringUtils
.
isNoneBlank
(
state
))
{
JosParameters
josParameters
=
LoginUtils
.
getStateParam
(
state
);
}
AccessTokenResponse
accessTokenByCode
=
accessTokenUtils
.
getAccessTokenByCode
(
appEnum
,
code
);
if
(!
accessTokenByCode
.
isOk
())
{
// 保存入库
}
public
String
getShopInfoVO
(
Long
venderId
,
Long
shopId
)
{
TbShopAccessTokenDto
accessToken
=
accessTokenUtils
.
getAccessToken
(
venderId
,
shopId
);
return
null
;
}
...
...
src/main/java/cn/com/duiba/jdactivity/controller/IndexController.java
0 → 100644
View file @
b705bc48
package
cn
.
com
.
duiba
.
jdactivity
.
controller
;
import
org.springframework.stereotype.Controller
;
import
org.springframework.web.bind.annotation.RequestMapping
;
/**
* @author zsp (zengshuiping@duiba.com.cn)
* @date 2021/5/18 12:51
*/
@Controller
@RequestMapping
(
"/"
)
public
class
IndexController
{
}
src/main/java/cn/com/duiba/jdactivity/developer/jd/utils/AccessTokenUtils.java
View file @
b705bc48
...
...
@@ -13,6 +13,8 @@ import com.alibaba.fastjson.JSONValidator;
import
com.jd.open.api.sdk.domain.seller.ShopSafService.response.query.ShopJosResult
;
import
org.apache.commons.collections4.CollectionUtils
;
import
org.apache.commons.lang3.StringUtils
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.stereotype.Component
;
import
javax.annotation.Resource
;
...
...
@@ -28,6 +30,8 @@ import java.util.TreeMap;
*/
@Component
public
class
AccessTokenUtils
{
public
static
final
Logger
LOGGER
=
LoggerFactory
.
getLogger
(
AccessTokenUtils
.
class
);
private
static
final
String
TO_LOGIN_SUFFIX
=
"/to_login"
;
private
static
final
String
ACCESS_TOKEN_SUFFIX
=
"/access_token"
;
private
static
final
String
NULL
=
"null"
;
...
...
@@ -59,6 +63,8 @@ public class AccessTokenUtils {
String
url
=
UrlUtils
.
assembleUrl
(
urlConstants
.
getOauthUrl
()
+
ACCESS_TOKEN_SUFFIX
,
param
);
String
s
=
httpClientUtil
.
sendGet
(
url
);
LOGGER
.
info
(
"getAccessTokenByCode,code={},s={}"
,
code
,
s
);
if
(
StringUtils
.
isNotBlank
(
s
)
&&
!
StringUtils
.
equalsIgnoreCase
(
NULL
,
s
)
&&
JSONValidator
.
from
(
s
).
validate
())
{
...
...
src/main/resources/application-dev.properties
0 → 100644
View file @
b705bc48
#MySQL配置 注意这是内网地址
spring.datasource.url
=
jdbc:mysql://127.0.0.1:3306/mydb?serverTimezone=UTC&useSSL=false&allowPublicKeyRetrieval=true&useUnicode=true&characterEncoding=utf-8
spring.datasource.username
=
root
spring.datasource.password
=
123456
spring.datasource.driver-class-name
=
com.mysql.cj.jdbc.Driver
#redis 注意这是内网地址
spring.redis.host
=
localhost
spring.redis.timeout
=
1000
spring.redis.jedis.pool.max-wait
=
100
spring.redis.jedis.pool.min-idle
=
1
src/main/resources/application-prod.properties
0 → 100644
View file @
b705bc48
#MySQL配置 注意这是内网地址
spring.datasource.url
=
jdbc:mysql://mysql-cn-north-1-5321aee1b70d421c.rds.jdcloud.com:3306?serverTimezone=UTC&useSSL=false&allowPublicKeyRetrieval=true
spring.datasource.username
=
jd_activity
spring.datasource.password
=
kP6oWdeYU78tHee70bcs
spring.datasource.driver-class-name
=
com.mysql.cj.jdbc.Driver
#redis 注意这是内网地址
spring.redis.host
=
redis-x4n822igaxnu-proxy-nlb.jvessel-open-hb.jdcloud.com
spring.redis.password
=
kP6oWdeYU78tHee
spring.redis.timeout
=
1000
spring.redis.jedis.pool.max-wait
=
100
spring.redis.jedis.pool.min-idle
=
1
src/main/resources/application.properties
View file @
b705bc48
spring.application.name
=
jd-activity
spring.profiles.active
=
dev
spring.profiles.active
=
prod
#先排除一些autoconfigure
spring.autoconfigure.exclude
=
# tomcat
...
...
@@ -7,25 +7,10 @@ server.port=8080
server.tomcat.accesslog.enabled
=
false
server.tomcat.uri-encoding
=
UTF-8
server.tomcat.threads.max
=
300
#MySQL配置 注意这是内网地址
#spring.datasource.url=jdbc:mysql://mysql-cn-north-1-5321aee1b70d421c.rds.jdcloud.com:3306?serverTimezone=UTC&useSSL=false&allowPublicKeyRetrieval=true
#spring.datasource.username=jd_activity
#spring.datasource.password=kP6oWdeYU78tHee70bcs
#jdbc:mysql://${MYSQL_HOST:localhost}:3306/db_example
spring.datasource.url
=
jdbc:mysql://127.0.0.1:3306/mydb?serverTimezone=UTC&useSSL=false&allowPublicKeyRetrieval=true&useUnicode=true&characterEncoding=utf-8
spring.datasource.username
=
root
spring.datasource.password
=
123456
spring.datasource.driver-class-name
=
com.mysql.cj.jdbc.Driver
# logging
logging.file.path
=
${user.home}/logs/${spring.application.name}
# MyBatis 配置
mybatis.config-location
=
classpath:mybatis/mybatis-config.xml
mybatis.mapper-locations
=
classpath:mybatis/*/*.xml
#redis 注意这是内网地址
#spring.redis.host=redis-x4n822igaxnu-proxy-nlb.jvessel-open-hb.jdcloud.com
#spring.redis.password=kP6oWdeYU78tHee
spring.redis.host
=
localhost
spring.redis.timeout
=
1000
spring.redis.jedis.pool.max-wait
=
100
spring.redis.jedis.pool.min-idle
=
1
src/main/resources/static/index.html
View file @
b705bc48
...
...
@@ -91,7 +91,7 @@
function
getToken
()
{
console
.
log
(
"获取token"
,
window
.
location
.
href
)
JSSDK
.
Isv
.
requestIsvToken
({
url
:
window
.
location
.
href
url
:
'https://duiba-isv.isvjcloud.com'
},
callBackToken
);
}
...
...
src/test/java/cn/com/duiba/jdactivity/ControllerTest.java
View file @
b705bc48
package
cn
.
com
.
duiba
.
jdactivity
;
import
org.junit.jupiter.api.Test
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc
;
import
org.springframework.http.MediaType
;
...
...
@@ -22,7 +21,7 @@ public class ControllerTest extends BaseTest {
@Autowired
private
MockMvc
mvc
;
@Test
//
@Test
public
void
getHello
()
throws
Exception
{
mvc
.
perform
(
MockMvcRequestBuilders
.
get
(
"/"
)
.
accept
(
MediaType
.
APPLICATION_JSON
))
...
...
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