Browse Source

三方登录

root 5 years ago
parent
commit
2f664dedb7

BIN
1.dmp


+ 53 - 7
facade/src/app/routes/passport/login/login.component.ts

@@ -16,6 +16,7 @@ import { environment } from '@env/environment';
16 16
 import { StartupService } from '@core';
17 17
 import { eventNames } from 'cluster';
18 18
 import { HttpHandler } from '@angular/common/http';
19
+import { load } from '@angular/core/src/render3';
19 20
 
20 21
 @Component({
21 22
   selector: 'passport-login',
@@ -124,7 +125,6 @@ export class UserLoginComponent implements OnDestroy {
124 125
         provider: environment.provider,
125 126
       };
126 127
 
127
-      console.log(this.settingsService.app);
128 128
 
129 129
     const url = environment.BASE_URL + 'oauth/token?_allow_anonymous=true';
130 130
     let options = null;
@@ -167,15 +167,26 @@ export class UserLoginComponent implements OnDestroy {
167 167
   // #region social
168 168
 
169 169
   open(item: object, openType: SocialOpenType = 'href') {
170
+
171
+
170 172
     let url = ``;
171 173
     let callback = ``;
172 174
     const type = item['code'];
175
+    const location = window.location;
176
+
173 177
     //if (environment.production) {
174 178
     //  callback = 'https://ng-alain.github.io/ng-alain/#/callback/' + type;
175 179
     //} else {
176
-     callback = 'http://localhost:4200/#/callback/' + type;
180
+     callback = location.protocol + '//' + location.host;
181
+
182
+      callback += '/callback/' + item['code'];
183
+
184
+    let uri: string = item['uri'];
185
+    if (uri.endsWith('/'))
186
+      uri = uri.substr(0, uri.length  - 1 );
187
+    uri += '/oauth/authorize';
177 188
     //}
178
-    url = `${item['uri']}?client_id=${item['clientId']}&response_type=code&redirect_uri=${decodeURIComponent(
189
+    url = `${uri}?client_id=${item['clientId']}&response_type=code&redirect_uri=${decodeURIComponent(
179 190
           callback,
180 191
         )}`;
181 192
     // switch (type) {
@@ -206,10 +217,12 @@ export class UserLoginComponent implements OnDestroy {
206 217
           type: 'window',
207 218
         })
208 219
         .subscribe(res => {
209
-          if (res) {
210
-            this.settingsService.setUser(res);
211
-            this.router.navigateByUrl('/');
212
-          }
220
+          const code = localStorage.getItem('_code');
221
+          //this.loadUser(item, code);
222
+          // if (res) {
223
+          //   this.settingsService.setUser(res);
224
+          //   this.router.navigateByUrl('/');
225
+          // }
213 226
         });
214 227
     } else {
215 228
       this.socialService.login(url, '/', {
@@ -218,6 +231,39 @@ export class UserLoginComponent implements OnDestroy {
218 231
     }
219 232
   }
220 233
 
234
+  loadUser(item: object, code: string) {
235
+    // 获得token
236
+    const data = {
237
+      grant_type: 'authorization_code',
238
+      client_id: item['clientId'],
239
+      client_secret: item['clientSecret'],
240
+      code: code,
241
+      redirect_uri: '',
242
+    };
243
+
244
+
245
+  const url = environment.BASE_URL + 'oauth/token?_allow_anonymous=true';
246
+  let options = null;
247
+  let params: any = null;
248
+  let body = null;
249
+  if ( environment.auth_set_header ) {
250
+     options = {headers:   {Authorization: 'Basic ' + btoa ( data.client_id + ':' + data.client_secret ),
251
+       'Content-type': 'application/x-www-form-urlencoded'}};
252
+    params = data;
253
+  } else {
254
+    body = data;
255
+  }
256
+console.log(item);
257
+
258
+  this.http
259
+    .post('http://127.0.0.1:8092/oauth/token' , body , data, options)
260
+    .subscribe((res: any) => {
261
+      console.log(res);
262
+    } ,  (res) => {
263
+       console.log(res);
264
+    });
265
+  }
266
+
221 267
   // #endregion
222 268
 
223 269
   ngOnDestroy(): void {

+ 41 - 3
src/main/java/com/kingkong/bljs/controller/MainController.java

@@ -1,7 +1,11 @@
1 1
 package com.kingkong.bljs.controller;
2 2
 
3 3
 import com.kingkong.bljs.dao.ClientMapper;
4
+import com.kingkong.bljs.dao.ThreeloginMapper;
4 5
 import com.kingkong.bljs.entity.Client;
6
+import com.kingkong.bljs.entity.Threelogin;
7
+import com.kingkong.bljs.service.ModuleService;
8
+import com.kingkong.bljs.service.ThreeLoginService;
5 9
 import org.springframework.beans.factory.annotation.Autowired;
6 10
 import org.springframework.security.oauth2.provider.AuthorizationRequest;
7 11
 import org.springframework.stereotype.Controller;
@@ -19,12 +23,19 @@ import java.util.Map;
19 23
 public class MainController {
20 24
 
21 25
     @Autowired
22
-    private ClientMapper clientMapper;
26
+    private ThreeloginMapper threeloginMapper;
27
+
28
+
29
+
30
+
31
+    @Autowired
32
+    private ModuleService moduleService;
33
+
34
+
23 35
 
24 36
     @GetMapping("/login")
25 37
     public ModelAndView login(@RequestParam(name="error",required=false)String error,
26
-                              @RequestParam(name="logout",required=false)String logout,
27
-                              Map<String, Object> model, HttpSession session) {
38
+                              @RequestParam(name="logout",required=false)String logout) {
28 39
 
29 40
         ModelAndView page = new ModelAndView();
30 41
         page.setViewName("login");
@@ -40,4 +51,31 @@ public class MainController {
40 51
         view.addObject("clientId", authorizationRequest.getClientId());
41 52
         return view;
42 53
     }
54
+
55
+
56
+    /**
57
+     * 社会化登录回调地址
58
+     * @param clientId
59
+     * @param code
60
+     * @return
61
+     */
62
+    @ResponseBody
63
+    @GetMapping("/callback/{clientCode}")
64
+    public String societyCallback(@PathVariable("clientCode") String clientCode,@RequestParam("code") String code) throws Exception{
65
+        Threelogin threelogin = threeloginMapper.selectByPrimaryKey(clientCode);
66
+        ThreeLoginService threeLoginService = new ThreeLoginService();
67
+        threeLoginService.setThreelogin(threelogin);
68
+        String token = threeLoginService.getToken(code);
69
+
70
+
71
+        //保存登录信息
72
+        moduleService.batchOperation(threelogin.getProfile(),threeLoginService);
73
+
74
+
75
+        //threeLoginService.setThreelogin(threelogin);
76
+
77
+
78
+        //String str = "<script>localStorage.setItem('_code','" + token + "');window.close();</script>";
79
+        return code;
80
+    }
43 81
 }

+ 26 - 12
src/main/java/com/kingkong/bljs/dao/ThreeloginMapper.java

@@ -14,7 +14,7 @@ public interface ThreeloginMapper {
14 14
      * This method was generated by MyBatis Generator.
15 15
      * This method corresponds to the database table K_USER.K_THREE_LOGIN
16 16
      *
17
-     * @mbg.generated Fri May 24 17:01:32 CST 2019
17
+     * @mbg.generated Tue May 28 17:11:24 CST 2019
18 18
      */
19 19
     @Delete({
20 20
         "delete from K_USER.K_THREE_LOGIN",
@@ -26,17 +26,23 @@ public interface ThreeloginMapper {
26 26
      * This method was generated by MyBatis Generator.
27 27
      * This method corresponds to the database table K_USER.K_THREE_LOGIN
28 28
      *
29
-     * @mbg.generated Fri May 24 17:01:32 CST 2019
29
+     * @mbg.generated Tue May 28 17:11:24 CST 2019
30 30
      */
31 31
     @Insert({
32 32
         "insert into K_USER.K_THREE_LOGIN (CODE, CLIENT_ID, ",
33 33
         "CLIENT_SECRET, NAME, ",
34 34
         "CREATED_AT, UPDATED_AT, ",
35
-        "DELETED_AT, APP_ID)",
35
+        "DELETED_AT, APP_ID, URI, ",
36
+        "TYPE, PROFILE, USERNAME, ",
37
+        "PASSWORD, TOKEN, ",
38
+        "REFRESH_DATE, CALLBACK_URI)",
36 39
         "values (#{code,jdbcType=VARCHAR}, #{clientId,jdbcType=VARCHAR}, ",
37 40
         "#{clientSecret,jdbcType=VARCHAR}, #{name,jdbcType=VARCHAR}, ",
38 41
         "#{createdAt,jdbcType=DATE}, #{updatedAt,jdbcType=DATE}, ",
39
-        "#{deletedAt,jdbcType=DATE}, #{appId,jdbcType=DECIMAL})"
42
+        "#{deletedAt,jdbcType=DATE}, #{appId,jdbcType=DECIMAL}, #{uri,jdbcType=VARCHAR}, ",
43
+        "#{type,jdbcType=DECIMAL}, #{profile,jdbcType=VARCHAR}, #{username,jdbcType=VARCHAR}, ",
44
+        "#{password,jdbcType=VARCHAR}, #{token,jdbcType=VARCHAR}, ",
45
+        "#{refreshDate,jdbcType=DATE}, #{callbackUri,jdbcType=VARCHAR})"
40 46
     })
41 47
     int insert(Threelogin record);
42 48
 
@@ -44,7 +50,7 @@ public interface ThreeloginMapper {
44 50
      * This method was generated by MyBatis Generator.
45 51
      * This method corresponds to the database table K_USER.K_THREE_LOGIN
46 52
      *
47
-     * @mbg.generated Fri May 24 17:01:32 CST 2019
53
+     * @mbg.generated Tue May 28 17:11:24 CST 2019
48 54
      */
49 55
     int insertSelective(Threelogin record);
50 56
 
@@ -52,11 +58,12 @@ public interface ThreeloginMapper {
52 58
      * This method was generated by MyBatis Generator.
53 59
      * This method corresponds to the database table K_USER.K_THREE_LOGIN
54 60
      *
55
-     * @mbg.generated Fri May 24 17:01:32 CST 2019
61
+     * @mbg.generated Tue May 28 17:11:24 CST 2019
56 62
      */
57 63
     @Select({
58 64
         "select",
59
-        "CODE, CLIENT_ID, CLIENT_SECRET, NAME, CREATED_AT, UPDATED_AT, DELETED_AT, APP_ID",
65
+        "CODE, CLIENT_ID, CLIENT_SECRET, NAME, CREATED_AT, UPDATED_AT, DELETED_AT, APP_ID, ",
66
+        "URI, TYPE, PROFILE, USERNAME, PASSWORD, TOKEN, REFRESH_DATE, CALLBACK_URI",
60 67
         "from K_USER.K_THREE_LOGIN",
61 68
         "where CODE = #{code,jdbcType=VARCHAR}"
62 69
     })
@@ -67,7 +74,7 @@ public interface ThreeloginMapper {
67 74
      * This method was generated by MyBatis Generator.
68 75
      * This method corresponds to the database table K_USER.K_THREE_LOGIN
69 76
      *
70
-     * @mbg.generated Fri May 24 17:01:32 CST 2019
77
+     * @mbg.generated Tue May 28 17:11:24 CST 2019
71 78
      */
72 79
     int updateByPrimaryKeySelective(Threelogin record);
73 80
 
@@ -75,7 +82,7 @@ public interface ThreeloginMapper {
75 82
      * This method was generated by MyBatis Generator.
76 83
      * This method corresponds to the database table K_USER.K_THREE_LOGIN
77 84
      *
78
-     * @mbg.generated Fri May 24 17:01:32 CST 2019
85
+     * @mbg.generated Tue May 28 17:11:24 CST 2019
79 86
      */
80 87
     @Update({
81 88
         "update K_USER.K_THREE_LOGIN",
@@ -85,12 +92,19 @@ public interface ThreeloginMapper {
85 92
           "CREATED_AT = #{createdAt,jdbcType=DATE},",
86 93
           "UPDATED_AT = #{updatedAt,jdbcType=DATE},",
87 94
           "DELETED_AT = #{deletedAt,jdbcType=DATE},",
88
-          "APP_ID = #{appId,jdbcType=DECIMAL}",
95
+          "APP_ID = #{appId,jdbcType=DECIMAL},",
96
+          "URI = #{uri,jdbcType=VARCHAR},",
97
+          "TYPE = #{type,jdbcType=DECIMAL},",
98
+          "PROFILE = #{profile,jdbcType=VARCHAR},",
99
+          "USERNAME = #{username,jdbcType=VARCHAR},",
100
+          "PASSWORD = #{password,jdbcType=VARCHAR},",
101
+          "TOKEN = #{token,jdbcType=VARCHAR},",
102
+          "REFRESH_DATE = #{refreshDate,jdbcType=DATE},",
103
+          "CALLBACK_URI = #{callbackUri,jdbcType=VARCHAR}",
89 104
         "where CODE = #{code,jdbcType=VARCHAR}"
90 105
     })
91 106
     int updateByPrimaryKey(Threelogin record);
92 107
 
93
-
94
-    @Select({"select * from k_three_login where app_id=#{appid}"})
108
+    @Select({"select * from k_three_login where app_id=#{appid} and type=0"})
95 109
     List<Threelogin> selectByAppId(String appid);
96 110
 }

+ 189 - 21
src/main/java/com/kingkong/bljs/entity/Threelogin.java

@@ -8,7 +8,7 @@ public class Threelogin {
8 8
      * This field was generated by MyBatis Generator.
9 9
      * This field corresponds to the database column K_USER.K_THREE_LOGIN.CODE
10 10
      *
11
-     * @mbg.generated Fri May 24 17:01:32 CST 2019
11
+     * @mbg.generated Tue May 28 17:11:24 CST 2019
12 12
      */
13 13
     private String code;
14 14
 
@@ -17,7 +17,7 @@ public class Threelogin {
17 17
      * This field was generated by MyBatis Generator.
18 18
      * This field corresponds to the database column K_USER.K_THREE_LOGIN.CLIENT_ID
19 19
      *
20
-     * @mbg.generated Fri May 24 17:01:32 CST 2019
20
+     * @mbg.generated Tue May 28 17:11:24 CST 2019
21 21
      */
22 22
     private String clientId;
23 23
 
@@ -26,7 +26,7 @@ public class Threelogin {
26 26
      * This field was generated by MyBatis Generator.
27 27
      * This field corresponds to the database column K_USER.K_THREE_LOGIN.CLIENT_SECRET
28 28
      *
29
-     * @mbg.generated Fri May 24 17:01:32 CST 2019
29
+     * @mbg.generated Tue May 28 17:11:24 CST 2019
30 30
      */
31 31
     private String clientSecret;
32 32
 
@@ -35,7 +35,7 @@ public class Threelogin {
35 35
      * This field was generated by MyBatis Generator.
36 36
      * This field corresponds to the database column K_USER.K_THREE_LOGIN.NAME
37 37
      *
38
-     * @mbg.generated Fri May 24 17:01:32 CST 2019
38
+     * @mbg.generated Tue May 28 17:11:24 CST 2019
39 39
      */
40 40
     private String name;
41 41
 
@@ -44,7 +44,7 @@ public class Threelogin {
44 44
      * This field was generated by MyBatis Generator.
45 45
      * This field corresponds to the database column K_USER.K_THREE_LOGIN.CREATED_AT
46 46
      *
47
-     * @mbg.generated Fri May 24 17:01:32 CST 2019
47
+     * @mbg.generated Tue May 28 17:11:24 CST 2019
48 48
      */
49 49
     private Date createdAt;
50 50
 
@@ -53,7 +53,7 @@ public class Threelogin {
53 53
      * This field was generated by MyBatis Generator.
54 54
      * This field corresponds to the database column K_USER.K_THREE_LOGIN.UPDATED_AT
55 55
      *
56
-     * @mbg.generated Fri May 24 17:01:32 CST 2019
56
+     * @mbg.generated Tue May 28 17:11:24 CST 2019
57 57
      */
58 58
     private Date updatedAt;
59 59
 
@@ -62,7 +62,7 @@ public class Threelogin {
62 62
      * This field was generated by MyBatis Generator.
63 63
      * This field corresponds to the database column K_USER.K_THREE_LOGIN.DELETED_AT
64 64
      *
65
-     * @mbg.generated Fri May 24 17:01:32 CST 2019
65
+     * @mbg.generated Tue May 28 17:11:24 CST 2019
66 66
      */
67 67
     private Date deletedAt;
68 68
 
@@ -71,20 +71,89 @@ public class Threelogin {
71 71
      * This field was generated by MyBatis Generator.
72 72
      * This field corresponds to the database column K_USER.K_THREE_LOGIN.APP_ID
73 73
      *
74
-     * @mbg.generated Fri May 24 17:01:32 CST 2019
74
+     * @mbg.generated Tue May 28 17:11:24 CST 2019
75 75
      */
76 76
     private Integer appId;
77 77
 
78
-
78
+    /**
79
+     *
80
+     * This field was generated by MyBatis Generator.
81
+     * This field corresponds to the database column K_USER.K_THREE_LOGIN.URI
82
+     *
83
+     * @mbg.generated Tue May 28 17:11:24 CST 2019
84
+     */
79 85
     private String uri;
80 86
 
87
+    /**
88
+     *
89
+     * This field was generated by MyBatis Generator.
90
+     * This field corresponds to the database column K_USER.K_THREE_LOGIN.TYPE
91
+     *
92
+     * @mbg.generated Tue May 28 17:11:24 CST 2019
93
+     */
94
+    private Short type;
95
+
96
+    /**
97
+     *
98
+     * This field was generated by MyBatis Generator.
99
+     * This field corresponds to the database column K_USER.K_THREE_LOGIN.PROFILE
100
+     *
101
+     * @mbg.generated Tue May 28 17:11:24 CST 2019
102
+     */
103
+    private String profile;
104
+
105
+    /**
106
+     *
107
+     * This field was generated by MyBatis Generator.
108
+     * This field corresponds to the database column K_USER.K_THREE_LOGIN.USERNAME
109
+     *
110
+     * @mbg.generated Tue May 28 17:11:24 CST 2019
111
+     */
112
+    private String username;
113
+
114
+    /**
115
+     *
116
+     * This field was generated by MyBatis Generator.
117
+     * This field corresponds to the database column K_USER.K_THREE_LOGIN.PASSWORD
118
+     *
119
+     * @mbg.generated Tue May 28 17:11:24 CST 2019
120
+     */
121
+    private String password;
122
+
123
+    /**
124
+     *
125
+     * This field was generated by MyBatis Generator.
126
+     * This field corresponds to the database column K_USER.K_THREE_LOGIN.TOKEN
127
+     *
128
+     * @mbg.generated Tue May 28 17:11:24 CST 2019
129
+     */
130
+    private String token;
131
+
132
+    /**
133
+     *
134
+     * This field was generated by MyBatis Generator.
135
+     * This field corresponds to the database column K_USER.K_THREE_LOGIN.REFRESH_DATE
136
+     *
137
+     * @mbg.generated Tue May 28 17:11:24 CST 2019
138
+     */
139
+    private Date refreshDate;
140
+
141
+    /**
142
+     *
143
+     * This field was generated by MyBatis Generator.
144
+     * This field corresponds to the database column K_USER.K_THREE_LOGIN.CALLBACK_URI
145
+     *
146
+     * @mbg.generated Tue May 28 17:11:24 CST 2019
147
+     */
148
+    private String callbackUri;
149
+
81 150
     /**
82 151
      * This method was generated by MyBatis Generator.
83 152
      * This method corresponds to the database table K_USER.K_THREE_LOGIN
84 153
      *
85
-     * @mbg.generated Fri May 24 17:01:32 CST 2019
154
+     * @mbg.generated Tue May 28 17:11:24 CST 2019
86 155
      */
87
-    public Threelogin(String code, String clientId, String clientSecret, String name, Date createdAt, Date updatedAt, Date deletedAt, Integer appId,String uri) {
156
+    public Threelogin(String code, String clientId, String clientSecret, String name, Date createdAt, Date updatedAt, Date deletedAt, Integer appId, String uri, Short type, String profile, String username, String password, String token, Date refreshDate, String callbackUri) {
88 157
         this.code = code;
89 158
         this.clientId = clientId;
90 159
         this.clientSecret = clientSecret;
@@ -94,6 +163,13 @@ public class Threelogin {
94 163
         this.deletedAt = deletedAt;
95 164
         this.appId = appId;
96 165
         this.uri = uri;
166
+        this.type = type;
167
+        this.profile = profile;
168
+        this.username = username;
169
+        this.password = password;
170
+        this.token = token;
171
+        this.refreshDate = refreshDate;
172
+        this.callbackUri = callbackUri;
97 173
     }
98 174
 
99 175
     /**
@@ -102,7 +178,7 @@ public class Threelogin {
102 178
      *
103 179
      * @return the value of K_USER.K_THREE_LOGIN.CODE
104 180
      *
105
-     * @mbg.generated Fri May 24 17:01:32 CST 2019
181
+     * @mbg.generated Tue May 28 17:11:24 CST 2019
106 182
      */
107 183
     public String getCode() {
108 184
         return code;
@@ -114,7 +190,7 @@ public class Threelogin {
114 190
      *
115 191
      * @return the value of K_USER.K_THREE_LOGIN.CLIENT_ID
116 192
      *
117
-     * @mbg.generated Fri May 24 17:01:32 CST 2019
193
+     * @mbg.generated Tue May 28 17:11:24 CST 2019
118 194
      */
119 195
     public String getClientId() {
120 196
         return clientId;
@@ -126,7 +202,7 @@ public class Threelogin {
126 202
      *
127 203
      * @return the value of K_USER.K_THREE_LOGIN.CLIENT_SECRET
128 204
      *
129
-     * @mbg.generated Fri May 24 17:01:32 CST 2019
205
+     * @mbg.generated Tue May 28 17:11:24 CST 2019
130 206
      */
131 207
     public String getClientSecret() {
132 208
         return clientSecret;
@@ -138,7 +214,7 @@ public class Threelogin {
138 214
      *
139 215
      * @return the value of K_USER.K_THREE_LOGIN.NAME
140 216
      *
141
-     * @mbg.generated Fri May 24 17:01:32 CST 2019
217
+     * @mbg.generated Tue May 28 17:11:24 CST 2019
142 218
      */
143 219
     public String getName() {
144 220
         return name;
@@ -150,7 +226,7 @@ public class Threelogin {
150 226
      *
151 227
      * @return the value of K_USER.K_THREE_LOGIN.CREATED_AT
152 228
      *
153
-     * @mbg.generated Fri May 24 17:01:32 CST 2019
229
+     * @mbg.generated Tue May 28 17:11:24 CST 2019
154 230
      */
155 231
     public Date getCreatedAt() {
156 232
         return createdAt;
@@ -162,7 +238,7 @@ public class Threelogin {
162 238
      *
163 239
      * @return the value of K_USER.K_THREE_LOGIN.UPDATED_AT
164 240
      *
165
-     * @mbg.generated Fri May 24 17:01:32 CST 2019
241
+     * @mbg.generated Tue May 28 17:11:24 CST 2019
166 242
      */
167 243
     public Date getUpdatedAt() {
168 244
         return updatedAt;
@@ -174,7 +250,7 @@ public class Threelogin {
174 250
      *
175 251
      * @return the value of K_USER.K_THREE_LOGIN.DELETED_AT
176 252
      *
177
-     * @mbg.generated Fri May 24 17:01:32 CST 2019
253
+     * @mbg.generated Tue May 28 17:11:24 CST 2019
178 254
      */
179 255
     public Date getDeletedAt() {
180 256
         return deletedAt;
@@ -186,13 +262,105 @@ public class Threelogin {
186 262
      *
187 263
      * @return the value of K_USER.K_THREE_LOGIN.APP_ID
188 264
      *
189
-     * @mbg.generated Fri May 24 17:01:32 CST 2019
265
+     * @mbg.generated Tue May 28 17:11:24 CST 2019
190 266
      */
191 267
     public Integer getAppId() {
192 268
         return appId;
193 269
     }
194 270
 
195
-    public String getUri(){
196
-        return this.uri;
271
+    /**
272
+     * This method was generated by MyBatis Generator.
273
+     * This method returns the value of the database column K_USER.K_THREE_LOGIN.URI
274
+     *
275
+     * @return the value of K_USER.K_THREE_LOGIN.URI
276
+     *
277
+     * @mbg.generated Tue May 28 17:11:24 CST 2019
278
+     */
279
+    public String getUri() {
280
+        return uri;
281
+    }
282
+
283
+    /**
284
+     * This method was generated by MyBatis Generator.
285
+     * This method returns the value of the database column K_USER.K_THREE_LOGIN.TYPE
286
+     *
287
+     * @return the value of K_USER.K_THREE_LOGIN.TYPE
288
+     *
289
+     * @mbg.generated Tue May 28 17:11:24 CST 2019
290
+     */
291
+    public Short getType() {
292
+        return type;
293
+    }
294
+
295
+    /**
296
+     * This method was generated by MyBatis Generator.
297
+     * This method returns the value of the database column K_USER.K_THREE_LOGIN.PROFILE
298
+     *
299
+     * @return the value of K_USER.K_THREE_LOGIN.PROFILE
300
+     *
301
+     * @mbg.generated Tue May 28 17:11:24 CST 2019
302
+     */
303
+    public String getProfile() {
304
+        return profile;
305
+    }
306
+
307
+    /**
308
+     * This method was generated by MyBatis Generator.
309
+     * This method returns the value of the database column K_USER.K_THREE_LOGIN.USERNAME
310
+     *
311
+     * @return the value of K_USER.K_THREE_LOGIN.USERNAME
312
+     *
313
+     * @mbg.generated Tue May 28 17:11:24 CST 2019
314
+     */
315
+    public String getUsername() {
316
+        return username;
317
+    }
318
+
319
+    /**
320
+     * This method was generated by MyBatis Generator.
321
+     * This method returns the value of the database column K_USER.K_THREE_LOGIN.PASSWORD
322
+     *
323
+     * @return the value of K_USER.K_THREE_LOGIN.PASSWORD
324
+     *
325
+     * @mbg.generated Tue May 28 17:11:24 CST 2019
326
+     */
327
+    public String getPassword() {
328
+        return password;
329
+    }
330
+
331
+    /**
332
+     * This method was generated by MyBatis Generator.
333
+     * This method returns the value of the database column K_USER.K_THREE_LOGIN.TOKEN
334
+     *
335
+     * @return the value of K_USER.K_THREE_LOGIN.TOKEN
336
+     *
337
+     * @mbg.generated Tue May 28 17:11:24 CST 2019
338
+     */
339
+    public String getToken() {
340
+        return token;
341
+    }
342
+
343
+    /**
344
+     * This method was generated by MyBatis Generator.
345
+     * This method returns the value of the database column K_USER.K_THREE_LOGIN.REFRESH_DATE
346
+     *
347
+     * @return the value of K_USER.K_THREE_LOGIN.REFRESH_DATE
348
+     *
349
+     * @mbg.generated Tue May 28 17:11:24 CST 2019
350
+     */
351
+    public Date getRefreshDate() {
352
+        return refreshDate;
353
+    }
354
+
355
+    /**
356
+     * This method was generated by MyBatis Generator.
357
+     * This method returns the value of the database column K_USER.K_THREE_LOGIN.CALLBACK_URI
358
+     *
359
+     * @return the value of K_USER.K_THREE_LOGIN.CALLBACK_URI
360
+     *
361
+     * @mbg.generated Tue May 28 17:11:24 CST 2019
362
+     */
363
+    public String getCallbackUri() {
364
+        return callbackUri;
197 365
     }
198 366
 }

+ 2 - 0
src/main/java/com/kingkong/bljs/service/ModuleService.java

@@ -267,6 +267,8 @@ public class ModuleService {
267 267
 
268 268
 
269 269
         CustomUser loginUser = userService.loginUser();
270
+        if(loginUser.getUsername().equals("anonymousUser"))
271
+            return result;
270 272
         Map user = userService.getUser(loginUser.getUsername(),loginUser.getAppid());
271 273
 
272 274
         for(Object key : user.keySet()) {

+ 101 - 0
src/main/java/com/kingkong/bljs/service/ThreeLoginService.java

@@ -0,0 +1,101 @@
1
+package com.kingkong.bljs.service;
2
+
3
+import com.alibaba.fastjson.JSONObject;
4
+import com.kingkong.bljs.entity.Threelogin;
5
+import com.kingkong.bljs.util.HttpClient;
6
+import com.kingkong.bljs.util.StringUtil;
7
+import org.springframework.beans.factory.annotation.Autowired;
8
+import org.springframework.http.HttpHeaders;
9
+import org.springframework.stereotype.Service;
10
+import org.springframework.util.LinkedMultiValueMap;
11
+import org.springframework.util.MultiValueMap;
12
+
13
+import javax.servlet.http.HttpServletRequest;
14
+import java.util.HashMap;
15
+
16
+
17
+@Service
18
+public class ThreeLoginService {
19
+
20
+    private Threelogin threelogin;
21
+    private String token;
22
+    private String baseUrl = "";
23
+
24
+
25
+    private void setToken(String token){
26
+        this.token = token;
27
+    }
28
+
29
+
30
+    public  void setThreelogin(Threelogin threelogin){
31
+        this.threelogin = threelogin;
32
+        String url = threelogin.getUri();
33
+        if(!url.endsWith("/"))
34
+            url += "/";
35
+        baseUrl = url;
36
+    }
37
+
38
+
39
+    public Threelogin getThreelogin(){
40
+        return this.getThreelogin();
41
+    }
42
+
43
+    public String getToken() {
44
+        return this.token;
45
+    }
46
+
47
+    public  String getToken(String code) throws Exception{
48
+        MultiValueMap<String, String> params = new LinkedMultiValueMap<>();
49
+        params.add("grant_type","authorization_code");
50
+        params.add("code",code);
51
+
52
+        params.add("client_id",threelogin.getClientId());
53
+        params.add("client_secret",threelogin.getClientSecret());
54
+        params.add("redirect_uri", threelogin.getCallbackUri());
55
+
56
+        JSONObject json = (JSONObject) post("oauth/token",params);
57
+
58
+
59
+        String token = json.getString("access_token");
60
+
61
+        this.token = token;
62
+        return token;
63
+    }
64
+
65
+    private HttpHeaders getHeader() throws Exception {
66
+        HttpHeaders httpHeaders = new HttpHeaders();
67
+        String basic = StringUtil.base64Encode(threelogin.getClientId() + ":" + threelogin.getClientSecret());
68
+        if(null == token  || token.equals("")) //token 为空,未登录过
69
+            httpHeaders.add("Authorization","Basic " + basic );
70
+        else
71
+            httpHeaders.add("Authorization","Bearer " + token);
72
+        return httpHeaders;
73
+    }
74
+
75
+
76
+    public String refreshToken(String user) {
77
+        return null;
78
+    }
79
+
80
+    public Object post(String api,MultiValueMap<String, String> params) throws Exception{
81
+        HttpHeaders httpHeaders = this.getHeader();
82
+
83
+        String url = baseUrl + api;
84
+
85
+
86
+        String res = HttpClient.sendPostRequest(url,params,httpHeaders);
87
+
88
+        return JSONObject.parse(res);
89
+    }
90
+
91
+    public Object get(String api,MultiValueMap<String, String> params) throws Exception{
92
+        HttpHeaders httpHeaders = this.getHeader();
93
+
94
+        String url = baseUrl + api;
95
+
96
+        String res = HttpClient.sendGetRequest(url,params,httpHeaders);
97
+
98
+        return JSONObject.parse(res);
99
+    }
100
+
101
+}

+ 54 - 0
src/main/java/com/kingkong/bljs/util/HttpClient.java

@@ -0,0 +1,54 @@
1
+package com.kingkong.bljs.util;
2
+
3
+import org.springframework.http.*;
4
+//import org.springframework.http.HttpEntity;
5
+//import org.springframework.http.MediaType;
6
+//import org.springframework.http.ResponseEntity;
7
+import org.springframework.util.MultiValueMap;
8
+import org.springframework.web.client.RestTemplate;
9
+
10
+public class HttpClient {
11
+    /**
12
+     * 向目的URL发送post请求
13
+     * @param url       目的url
14
+     * @param params    发送的参数
15
+     * @return  AdToutiaoJsonTokenData
16
+     */
17
+    public static String sendPostRequest(String url, MultiValueMap<String, String> params,HttpHeaders headers){
18
+        RestTemplate client = new RestTemplate();
19
+        //新建Http头,add方法可以添加参数
20
+//        HttpHeaders headers = new HttpHeaders();
21
+
22
+        //设置请求发送方式
23
+        HttpMethod method = HttpMethod.POST;
24
+        // 以表单的方式提交
25
+        headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED);
26
+        //将请求头部和参数合成一个请求
27
+        HttpEntity<MultiValueMap<String, String>> requestEntity = new HttpEntity<>(params, headers);
28
+        //执行HTTP请求,将返回的结构使用String 类格式化(可设置为对应返回值格式的类)
29
+        ResponseEntity<String> response = client.exchange(url, method, requestEntity,String .class);
30
+
31
+        return response.getBody();
32
+    }
33
+
34
+    /**
35
+     * 向目的URL发送get请求
36
+     * @param url       目的url
37
+     * @param params    发送的参数
38
+     * @param headers   发送的http头,可在外部设置好参数后传入
39
+     * @return  String
40
+     */
41
+    public static String sendGetRequest(String url, MultiValueMap<String, String> params,HttpHeaders headers){
42
+        RestTemplate client = new RestTemplate();
43
+
44
+        HttpMethod method = HttpMethod.GET;
45
+        // 以表单的方式提交
46
+        headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED);
47
+        //将请求头部和参数合成一个请求
48
+        HttpEntity<MultiValueMap<String, String>> requestEntity = new HttpEntity<>(params, headers);
49
+        //执行HTTP请求,将返回的结构使用String 类格式化
50
+        ResponseEntity<String> response = client.exchange(url, method, requestEntity, String.class);
51
+
52
+        return response.getBody();
53
+    }
54
+}

+ 1 - 1
src/main/resources/generatorConfig.xml

@@ -87,7 +87,7 @@
87 87
 
88 88
 
89 89
 
90
-        <table tableName="k_app" schema="k_user" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false"
90
+        <table tableName="k_three_login" schema="k_user" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false"
91 91
                enableSelectByExample="false" selectByExampleQueryId="false">
92 92
 
93 93
             <!-- optional   , only for mybatis3 runtime

+ 86 - 5
src/main/resources/mapper/ThreeloginMapper.xml

@@ -5,7 +5,7 @@
5 5
     <!--
6 6
       WARNING - @mbg.generated
7 7
       This element is automatically generated by MyBatis Generator, do not modify.
8
-      This element was generated on Fri May 24 17:01:32 CST 2019.
8
+      This element was generated on Tue May 28 17:11:24 CST 2019.
9 9
     -->
10 10
     <constructor>
11 11
       <idArg column="CODE" javaType="java.lang.String" jdbcType="VARCHAR" />
@@ -16,21 +16,30 @@
16 16
       <arg column="UPDATED_AT" javaType="java.util.Date" jdbcType="DATE" />
17 17
       <arg column="DELETED_AT" javaType="java.util.Date" jdbcType="DATE" />
18 18
       <arg column="APP_ID" javaType="java.lang.Integer" jdbcType="DECIMAL" />
19
+      <arg column="URI" javaType="java.lang.String" jdbcType="VARCHAR" />
20
+      <arg column="TYPE" javaType="java.lang.Short" jdbcType="DECIMAL" />
21
+      <arg column="PROFILE" javaType="java.lang.String" jdbcType="VARCHAR" />
22
+      <arg column="USERNAME" javaType="java.lang.String" jdbcType="VARCHAR" />
23
+      <arg column="PASSWORD" javaType="java.lang.String" jdbcType="VARCHAR" />
24
+      <arg column="TOKEN" javaType="java.lang.String" jdbcType="VARCHAR" />
25
+      <arg column="REFRESH_DATE" javaType="java.util.Date" jdbcType="DATE" />
26
+      <arg column="CALLBACK_URI" javaType="java.lang.String" jdbcType="VARCHAR" />
19 27
     </constructor>
20 28
   </resultMap>
21 29
   <sql id="Base_Column_List">
22 30
     <!--
23 31
       WARNING - @mbg.generated
24 32
       This element is automatically generated by MyBatis Generator, do not modify.
25
-      This element was generated on Fri May 24 17:01:32 CST 2019.
33
+      This element was generated on Tue May 28 17:11:24 CST 2019.
26 34
     -->
27
-    CODE, CLIENT_ID, CLIENT_SECRET, NAME, CREATED_AT, UPDATED_AT, DELETED_AT, APP_ID
35
+    CODE, CLIENT_ID, CLIENT_SECRET, NAME, CREATED_AT, UPDATED_AT, DELETED_AT, APP_ID, 
36
+    URI, TYPE, PROFILE, USERNAME, PASSWORD, TOKEN, REFRESH_DATE, CALLBACK_URI
28 37
   </sql>
29 38
   <insert id="insertSelective" parameterType="com.kingkong.bljs.entity.Threelogin">
30 39
     <!--
31 40
       WARNING - @mbg.generated
32 41
       This element is automatically generated by MyBatis Generator, do not modify.
33
-      This element was generated on Fri May 24 17:01:32 CST 2019.
42
+      This element was generated on Tue May 28 17:11:24 CST 2019.
34 43
     -->
35 44
     insert into K_USER.K_THREE_LOGIN
36 45
     <trim prefix="(" suffix=")" suffixOverrides=",">
@@ -58,6 +67,30 @@
58 67
       <if test="appId != null">
59 68
         APP_ID,
60 69
       </if>
70
+      <if test="uri != null">
71
+        URI,
72
+      </if>
73
+      <if test="type != null">
74
+        TYPE,
75
+      </if>
76
+      <if test="profile != null">
77
+        PROFILE,
78
+      </if>
79
+      <if test="username != null">
80
+        USERNAME,
81
+      </if>
82
+      <if test="password != null">
83
+        PASSWORD,
84
+      </if>
85
+      <if test="token != null">
86
+        TOKEN,
87
+      </if>
88
+      <if test="refreshDate != null">
89
+        REFRESH_DATE,
90
+      </if>
91
+      <if test="callbackUri != null">
92
+        CALLBACK_URI,
93
+      </if>
61 94
     </trim>
62 95
     <trim prefix="values (" suffix=")" suffixOverrides=",">
63 96
       <if test="code != null">
@@ -84,13 +117,37 @@
84 117
       <if test="appId != null">
85 118
         #{appId,jdbcType=DECIMAL},
86 119
       </if>
120
+      <if test="uri != null">
121
+        #{uri,jdbcType=VARCHAR},
122
+      </if>
123
+      <if test="type != null">
124
+        #{type,jdbcType=DECIMAL},
125
+      </if>
126
+      <if test="profile != null">
127
+        #{profile,jdbcType=VARCHAR},
128
+      </if>
129
+      <if test="username != null">
130
+        #{username,jdbcType=VARCHAR},
131
+      </if>
132
+      <if test="password != null">
133
+        #{password,jdbcType=VARCHAR},
134
+      </if>
135
+      <if test="token != null">
136
+        #{token,jdbcType=VARCHAR},
137
+      </if>
138
+      <if test="refreshDate != null">
139
+        #{refreshDate,jdbcType=DATE},
140
+      </if>
141
+      <if test="callbackUri != null">
142
+        #{callbackUri,jdbcType=VARCHAR},
143
+      </if>
87 144
     </trim>
88 145
   </insert>
89 146
   <update id="updateByPrimaryKeySelective" parameterType="com.kingkong.bljs.entity.Threelogin">
90 147
     <!--
91 148
       WARNING - @mbg.generated
92 149
       This element is automatically generated by MyBatis Generator, do not modify.
93
-      This element was generated on Fri May 24 17:01:32 CST 2019.
150
+      This element was generated on Tue May 28 17:11:24 CST 2019.
94 151
     -->
95 152
     update K_USER.K_THREE_LOGIN
96 153
     <set>
@@ -115,6 +172,30 @@
115 172
       <if test="appId != null">
116 173
         APP_ID = #{appId,jdbcType=DECIMAL},
117 174
       </if>
175
+      <if test="uri != null">
176
+        URI = #{uri,jdbcType=VARCHAR},
177
+      </if>
178
+      <if test="type != null">
179
+        TYPE = #{type,jdbcType=DECIMAL},
180
+      </if>
181
+      <if test="profile != null">
182
+        PROFILE = #{profile,jdbcType=VARCHAR},
183
+      </if>
184
+      <if test="username != null">
185
+        USERNAME = #{username,jdbcType=VARCHAR},
186
+      </if>
187
+      <if test="password != null">
188
+        PASSWORD = #{password,jdbcType=VARCHAR},
189
+      </if>
190
+      <if test="token != null">
191
+        TOKEN = #{token,jdbcType=VARCHAR},
192
+      </if>
193
+      <if test="refreshDate != null">
194
+        REFRESH_DATE = #{refreshDate,jdbcType=DATE},
195
+      </if>
196
+      <if test="callbackUri != null">
197
+        CALLBACK_URI = #{callbackUri,jdbcType=VARCHAR},
198
+      </if>
118 199
     </set>
119 200
     where CODE = #{code,jdbcType=VARCHAR}
120 201
   </update>