...
|
...
|
@@ -6,12 +6,15 @@ import com.baomidou.mybatisplus.core.metadata.IPage; |
6
|
6
|
import com.fasterxml.jackson.databind.JsonNode;
|
7
|
7
|
import lombok.RequiredArgsConstructor;
|
8
|
8
|
import lombok.extern.slf4j.Slf4j;
|
|
9
|
+import org.springframework.http.ResponseEntity;
|
9
|
10
|
import org.springframework.security.authentication.BadCredentialsException;
|
10
|
11
|
import org.springframework.security.core.userdetails.UsernameNotFoundException;
|
11
|
12
|
import org.springframework.security.crypto.password.PasswordEncoder;
|
12
|
13
|
import org.springframework.stereotype.Service;
|
13
|
14
|
import org.springframework.transaction.annotation.Transactional;
|
|
15
|
+import org.springframework.web.client.RestTemplate;
|
14
|
16
|
import org.thingsboard.server.common.data.StringUtils;
|
|
17
|
+import org.thingsboard.server.common.data.yunteng.config.third.WechatProperties;
|
15
|
18
|
import org.thingsboard.server.common.data.yunteng.core.cache.CacheUtils;
|
16
|
19
|
import org.thingsboard.server.common.data.yunteng.core.exception.YtDataValidationException;
|
17
|
20
|
import org.thingsboard.server.common.data.yunteng.core.message.ErrorMessage;
|
...
|
...
|
@@ -23,6 +26,7 @@ import org.thingsboard.server.common.data.yunteng.dto.request.CodeTTL; |
23
|
26
|
import org.thingsboard.server.common.data.yunteng.enums.MessageTypeEnum;
|
24
|
27
|
import org.thingsboard.server.common.data.yunteng.enums.MsgTemplatePurposeEnum;
|
25
|
28
|
import org.thingsboard.server.common.data.yunteng.enums.ThirdPlatformEnum;
|
|
29
|
+import org.thingsboard.server.common.data.yunteng.utils.JacksonUtil;
|
26
|
30
|
import org.thingsboard.server.common.data.yunteng.utils.tools.YtPageData;
|
27
|
31
|
import org.thingsboard.server.dao.yunteng.entities.User;
|
28
|
32
|
import org.thingsboard.server.dao.yunteng.entities.YtThirdUserEntity;
|
...
|
...
|
@@ -47,6 +51,9 @@ public class YtThirdPlatformServiceImpl extends AbstractBaseService<YtThirdPlatf |
47
|
51
|
private final CacheUtils cacheUtils;
|
48
|
52
|
private final PasswordEncoder passwordEncoder;
|
49
|
53
|
|
|
54
|
+ private final RestTemplate restTemplate = new RestTemplate();
|
|
55
|
+ private final WechatProperties wechatProperties;
|
|
56
|
+
|
50
|
57
|
@Override
|
51
|
58
|
public YtPageData<YtThirdUserDTO> pageDatas(IPage<YtThirdUserEntity> pageInfrom, ThirdPlatformEnum platformName, String name) {
|
52
|
59
|
Wrapper pageFilter = new QueryWrapper<YtThirdUserEntity>()
|
...
|
...
|
@@ -171,6 +178,19 @@ public class YtThirdPlatformServiceImpl extends AbstractBaseService<YtThirdPlatf |
171
|
178
|
return baseMapper.delete(filter) > 0;
|
172
|
179
|
}
|
173
|
180
|
|
|
181
|
+ private static final String loginApi="/sns/jscode2session?appid={appid}&secret={appid}&js_code={appid}&grant_type=authorization_code";
|
|
182
|
+ @Override
|
|
183
|
+ public String thirdLogin(String loginCode) {
|
|
184
|
+ String response = restTemplate.getForObject(wechatProperties.getUrl()+loginApi,String.class, wechatProperties.getAppId(),wechatProperties.getAppSecret(),loginCode);
|
|
185
|
+ JsonNode result = JacksonUtil.toJsonNode(response);
|
|
186
|
+
|
|
187
|
+ if(result.has("errcode")){
|
|
188
|
+ throw new YtDataValidationException(String.format(ErrorMessage.THIRD_PLATFORM_EXCEPTION.getMessage(),ThirdPlatformEnum.WECHAT,result.get("errmsg").asText()));
|
|
189
|
+ }
|
|
190
|
+ String thirdUserId = result.get("openid").asText();
|
|
191
|
+ return thirdUserId;
|
|
192
|
+ }
|
|
193
|
+
|
174
|
194
|
@Override
|
175
|
195
|
public UserDTO login(String thirdUserId) {
|
176
|
196
|
User user = baseMapper.login(thirdUserId);
|
...
|
...
|
@@ -186,4 +206,7 @@ public class YtThirdPlatformServiceImpl extends AbstractBaseService<YtThirdPlatf |
186
|
206
|
public JsonNode message(String receiver, JsonNode message) {
|
187
|
207
|
return null;
|
188
|
208
|
}
|
|
209
|
+
|
|
210
|
+
|
|
211
|
+
|
189
|
212
|
} |
...
|
...
|
|