Просмотр исходного кода

整合接入了token 和测试获取addresslist列表

zxy лет назад: 2
Родитель
Сommit
eb27a93786

+ 21 - 0
src/main/java/com/api/config/DoudianConfig.java

@@ -0,0 +1,21 @@
1
+package com.api.config;
2
+
3
+import com.doudian.open.api.address_list.AddressListRequest;
4
+import com.doudian.open.core.GlobalConfig;
5
+import org.springframework.beans.factory.annotation.Value;
6
+import org.springframework.context.annotation.Bean;
7
+import org.springframework.context.annotation.Configuration;
8
+import org.springframework.stereotype.Repository;
9
+
10
+import javax.annotation.PostConstruct;
11
+
12
+/**
13
+ * 抖店config
14
+ */
15
+@Configuration
16
+public class DoudianConfig {
17
+    @Bean
18
+    public AddressListRequest addressListRequest() {
19
+        return new AddressListRequest();
20
+    }
21
+}

+ 1 - 0
src/main/java/com/api/config/FilterConfig.java

@@ -9,6 +9,7 @@
9 9
 package com.api.config;
10 10
 
11 11
 import com.common.xss.XssFilter;
12
+import org.springframework.beans.factory.annotation.Value;
12 13
 import org.springframework.boot.web.servlet.FilterRegistrationBean;
13 14
 import org.springframework.context.annotation.Bean;
14 15
 import org.springframework.context.annotation.Configuration;

+ 20 - 0
src/main/java/com/api/config/InitDoudian.java

@@ -0,0 +1,20 @@
1
+package com.api.config;
2
+
3
+import com.doudian.open.core.GlobalConfig;
4
+import org.springframework.beans.factory.annotation.Value;
5
+import org.springframework.stereotype.Repository;
6
+
7
+import javax.annotation.PostConstruct;
8
+
9
+@Repository
10
+public class InitDoudian {
11
+    @Value("${doudian.app-key}")
12
+    private String appKey;
13
+    @Value("${doudian.app-secret}")
14
+    private String appSecret;
15
+    @PostConstruct
16
+    public void init() {
17
+        GlobalConfig.initAppKey(appKey);
18
+        GlobalConfig.initAppSecret(appSecret);
19
+    }
20
+}

+ 11 - 1
src/main/java/com/api/controller/ApiTestController.java

@@ -9,6 +9,7 @@
9 9
 package com.api.controller;
10 10
 
11 11
 import com.api.dao.TokenDao;
12
+import com.api.service.DoudianTokenService;
12 13
 import com.common.utils.R;
13 14
 import com.api.annotation.Login;
14 15
 import com.api.annotation.LoginUser;
@@ -42,6 +43,8 @@ public class ApiTestController extends AbsctactController {
42 43
     BeanFactory beanFactory;
43 44
     @Autowired
44 45
     TokenDao tokenDao;
46
+    @Autowired
47
+    DoudianTokenService doudianTokenService;
45 48
     @Login
46 49
     @GetMapping("userInfo")
47 50
     @ApiOperation(value="获取用户信息", response=UserEntity.class)
@@ -65,5 +68,12 @@ public class ApiTestController extends AbsctactController {
65 68
 //        return R.ok().put("msg", "无需token也能访问。。。");
66 69
         return R.ok().put( "无需token也能访问。。。");
67 70
     }
68
-
71
+    @GetMapping("douToken")
72
+    @ApiOperation("忽略Token验证测试")
73
+    public R douToken(HttpServletRequest request, HttpSession httpSession){
74
+//        doudianTokenService.getShopAccessToken(19855808L);
75
+        doudianTokenService.getAddressList(19855808L);
76
+//        return R.ok().put("msg", "无需token也能访问。。。");
77
+        return R.ok().put( "无需token也能访问。。。");
78
+    }
69 79
 }

+ 9 - 0
src/main/java/com/api/service/DoudianTokenService.java

@@ -0,0 +1,9 @@
1
+package com.api.service;
2
+
3
+import com.doudian.open.api.address_list.AddressListResponse;
4
+import com.doudian.open.core.AccessToken;
5
+
6
+public interface DoudianTokenService {
7
+    AccessToken getShopAccessToken(Long shopId);
8
+    AddressListResponse getAddressList(Long shopId);
9
+}

+ 40 - 0
src/main/java/com/api/service/impl/DoudianTokenServiceImpl.java

@@ -0,0 +1,40 @@
1
+package com.api.service.impl;
2
+
3
+import com.api.service.DoudianTokenService;
4
+import com.doudian.open.api.address_list.AddressListRequest;
5
+import com.doudian.open.api.address_list.AddressListResponse;
6
+import com.doudian.open.api.address_list.param.AddressListParam;
7
+import com.doudian.open.core.AccessToken;
8
+import com.doudian.open.core.AccessTokenBuilder;
9
+import org.springframework.beans.factory.annotation.Autowired;
10
+import org.springframework.stereotype.Service;
11
+
12
+import javax.annotation.PostConstruct;
13
+
14
+@Service
15
+public class DoudianTokenServiceImpl implements DoudianTokenService {
16
+    @Autowired
17
+    AddressListRequest addressListRequest;
18
+    private AccessToken accessToken;
19
+    // zxy测试预填入Token
20
+    @PostConstruct
21
+    public void initToken() {
22
+        accessToken = AccessTokenBuilder.refresh("3ce5a5db-bd29-471b-b7c1-1b277a760dbe");
23
+    }
24
+    @Override
25
+    public AccessToken getShopAccessToken(Long shopId) {
26
+        accessToken= AccessTokenBuilder.build(shopId);
27
+        return null;
28
+    }
29
+    @Override
30
+    public AddressListResponse getAddressList(Long shopId) {
31
+        AddressListParam param = addressListRequest.getParam();
32
+        param.setPageNo(1L);
33
+        param.setPageSize(10L);
34
+        param.setShopId(shopId);
35
+        param.setOrderBy("desc");
36
+        param.setOrderField("create_time");
37
+        AddressListResponse execute = addressListRequest.execute(accessToken);
38
+        return null;
39
+    }
40
+}

+ 3 - 3
src/main/resources/application-dev.yml

@@ -5,9 +5,9 @@ spring:
5 5
     type: com.alibaba.druid.pool.DruidDataSource
6 6
     druid:
7 7
       driver-class-name: com.mysql.cj.jdbc.Driver
8
-      url: jdbc:mysql://47.110.156.18:3306/sczn_eshop_test?zeroDateTimeBehavior=convertToNull&useUnicode=true&autoReconnect=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai
9
-      username: sczn
10
-      password: sczn159357
8
+      url: jdbc:mysql://192.168.50.132:3306/sczn_eshop_test?zeroDateTimeBehavior=convertToNull&useUnicode=true&autoReconnect=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai
9
+      username: root
10
+      password: 123456
11 11
       initial-size: 10
12 12
       max-active: 100
13 13
       min-idle: 10

+ 3 - 2
src/main/resources/application.yml

@@ -34,8 +34,9 @@ spring:
34 34
 renren:
35 35
   redis:
36 36
     open: false  # 是否开启redis缓存  true开启   false关闭
37
-
38
-
37
+doudian:
38
+  app-key: 7090080248619877901
39
+  app-secret : a4d9d3e6-aa69-4f0c-bffa-be4039e74262
39 40
 #mybatis
40 41
 mybatis-plus:
41 42
   mapper-locations: classpath*:/mapper/**/*.xml