|
|
@@ -20,6 +20,8 @@ import com.uas.platform.core.util.serializer.FlexJsonUtils;
|
|
|
import com.uas.sso.entity.UserAccount;
|
|
|
import com.uas.sso.entity.UserView;
|
|
|
import com.uas.sso.util.AccountUtils;
|
|
|
+import org.slf4j.Logger;
|
|
|
+import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.data.redis.core.RedisTemplate;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
@@ -46,6 +48,8 @@ public class WeChatServiceImpl implements WeChatService{
|
|
|
@Autowired
|
|
|
private RedisTemplate redisTemplate;
|
|
|
|
|
|
+ private Logger logger = LoggerFactory.getLogger(WeChatServiceImpl.class);
|
|
|
+
|
|
|
/**
|
|
|
* 保存到 redis 里的过期时间(second)
|
|
|
*/
|
|
|
@@ -53,6 +57,7 @@ public class WeChatServiceImpl implements WeChatService{
|
|
|
|
|
|
@Override
|
|
|
public ModelMap getWxUserInfo(String code, String state, String openId) {
|
|
|
+ logger.info("得到用户信息 code: {}, state: {}, openId: {}", code, state, openId);
|
|
|
ModelMap result = new ModelMap();
|
|
|
if (!StringUtils.isEmpty(code)) {
|
|
|
AuthUserInfo userInfo = null;
|
|
|
@@ -140,8 +145,15 @@ public class WeChatServiceImpl implements WeChatService{
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 微信绑定用户
|
|
|
+ *
|
|
|
+ * @param user
|
|
|
+ * @return
|
|
|
+ */
|
|
|
@Override
|
|
|
public ModelMap bindUser(User user) {
|
|
|
+ logger.info("微信绑定用户 userUU: {}", user.getUserUU());
|
|
|
ModelMap result = new ModelMap();
|
|
|
// 账户中心校验手机号和密码是否正确
|
|
|
if (StringUtils.isEmpty(user) || StringUtils.isEmpty(user.getUserTel()) || StringUtils.isEmpty(user.getUserPwd()) || StringUtils.isEmpty(user.getOpenId())) {
|
|
|
@@ -192,6 +204,7 @@ public class WeChatServiceImpl implements WeChatService{
|
|
|
* @param code
|
|
|
*/
|
|
|
private AuthUserInfo getAccessTokenByCode(String code) throws Exception {
|
|
|
+ logger.info("通过code获取用户openId, code: {}", code);
|
|
|
AuthTokenParams authTokenParams = new AuthTokenParams(WeChatUtil.APPID, WeChatUtil.APPSECRET, code, "authorization_code");
|
|
|
String json = HttpReqUtil.doGet(WeChatUtil.GET_OAUTH_TOKEN_URL, authTokenParams.getParams());
|
|
|
AuthAccessToken authAccessToken = FlexJsonUtils.fromJson(json, AuthAccessToken.class);
|
|
|
@@ -212,6 +225,7 @@ public class WeChatServiceImpl implements WeChatService{
|
|
|
* @return
|
|
|
*/
|
|
|
private AuthUserInfo getUserInfo(String accessToken, String openId) throws Exception {
|
|
|
+ logger.info("获取用户信息 accessToken: {}, openId: {}", accessToken, openId);
|
|
|
// 返回国家地区语言版本,zh_CN 简体,zh_TW 繁体,en 英语
|
|
|
AuthUserParams authUserParams = new AuthUserParams(accessToken, openId, "zh_CN");
|
|
|
String json = HttpReqUtil.doGet(WeChatUtil.SNS_USERINFO_URL, authUserParams.getParams());
|
|
|
@@ -229,12 +243,14 @@ public class WeChatServiceImpl implements WeChatService{
|
|
|
private String getAccessToken (boolean force) {
|
|
|
String access_token = (String) redisTemplate.opsForValue().get("WX_ACCESS_TOKEN");
|
|
|
if (!StringUtils.isEmpty(access_token) && !force) {
|
|
|
+ logger.info("从缓存中得到 access_token: {}", access_token);
|
|
|
return access_token;
|
|
|
}
|
|
|
AuthTokenParams authTokenParams = new AuthTokenParams(WeChatUtil.APPID, WeChatUtil.APPSECRET,"client_credential");
|
|
|
String json = HttpReqUtil.doGet(WeChatUtil.GET_ACCESS_TOKEN, authTokenParams.getParams());
|
|
|
AccessToken accessToken = FlexJsonUtils.fromJson(json, AccessToken.class);
|
|
|
access_token = accessToken.getAccess_token();
|
|
|
+ logger.info("请求微信接口,得到 access_token: {}", access_token);
|
|
|
redisTemplate.opsForValue().set("WX_ACCESS_TOKEN", access_token, ACCESS_TOKEN_EXPIRES_IN, TimeUnit.SECONDS);
|
|
|
return access_token;
|
|
|
}
|