新增小程序带用户状态token

This commit is contained in:
wenc000 2020-06-26 11:20:08 +08:00
parent f496348f4d
commit 0f94ecdc88
3 changed files with 19 additions and 9 deletions

View File

@ -43,7 +43,7 @@ public class WechatFilter implements Filter {
private WechatOfficialAccountProperties wechatOfficialAccountProperties; private WechatOfficialAccountProperties wechatOfficialAccountProperties;
private AntPathMatcher antPathMatcher; private AntPathMatcher antPathMatcher;
private static final String WECHAT_LOGIN_URL = String.format("/**%s/sign/login", ISystemConstant.WECHAT_PREFIX); private static final String WECHAT_LOGIN_URL = String.format("/**%s/sign/login**", ISystemConstant.WECHAT_PREFIX);
/** /**
* 微信类放行 * 微信类放行
*/ */

View File

@ -37,11 +37,11 @@ public class WechatMiniAppFilter implements Filter {
/** /**
* 授权登录 * 授权登录
*/ */
private static final String WECHAT_MINI_APP_AUTH_LOGIN_URL = String.format("/**%s/auth/login", ISystemConstant.WECHAT_MINI_APP_PREFIX); private static final String WECHAT_MINI_APP_AUTH_LOGIN_URL = String.format("/**%s/auth/login**", ISystemConstant.WECHAT_MINI_APP_PREFIX);
/** /**
* 认证登录 * 认证登录
*/ */
private static final String WECHAT_MINI_APP_SIGN_LOGIN_URL = String.format("/**%s/sign/login", ISystemConstant.WECHAT_MINI_APP_PREFIX); private static final String WECHAT_MINI_APP_SIGN_LOGIN_URL = String.format("/**%s/sign/login**", ISystemConstant.WECHAT_MINI_APP_PREFIX);
/** /**
* 微信类放行 * 微信类放行
*/ */

View File

@ -6,6 +6,7 @@ import com.cm.common.exception.WechatUserInfoException;
import com.cm.common.exception.base.SystemException; import com.cm.common.exception.base.SystemException;
import com.cm.common.result.SuccessResultData; import com.cm.common.result.SuccessResultData;
import com.cm.common.utils.AesUtil; import com.cm.common.utils.AesUtil;
import com.cm.common.utils.http.RestRequestUtil;
import com.cm.common.wechat.config.pojo.WechatMiniAppProperties; import com.cm.common.wechat.config.pojo.WechatMiniAppProperties;
import com.cm.common.wechat.pojo.WechatMiniAppLoginVO; import com.cm.common.wechat.pojo.WechatMiniAppLoginVO;
import com.cm.common.wechat.pojo.WechatMiniAppUserInfo; import com.cm.common.wechat.pojo.WechatMiniAppUserInfo;
@ -20,6 +21,8 @@ import org.springframework.http.HttpEntity;
import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.web.client.HttpClientErrorException;
import org.springframework.web.client.RestClientException;
import org.springframework.web.client.RestTemplate; import org.springframework.web.client.RestTemplate;
import java.io.IOException; import java.io.IOException;
@ -88,13 +91,20 @@ public class WechatMiniAppAuthServiceImpl implements IWechatMiniAppAuthService {
Map<String, Object> params = new HashMap<>(1); Map<String, Object> params = new HashMap<>(1);
params.put("signInfo", wechatSignInfo); params.put("signInfo", wechatSignInfo);
HttpEntity<Map<String, Object>> requestBody = new HttpEntity<>(params); HttpEntity<Map<String, Object>> requestBody = new HttpEntity<>(params);
ResponseEntity<Map> result = restTemplate.postForEntity(wechatMiniAppProperties.getBindUserUrl(), requestBody, Map.class); try {
LOG.debug("状态码:{}", result.getStatusCodeValue()); ResponseEntity<Map> result = restTemplate.postForEntity(wechatMiniAppProperties.getBindUserUrl(), requestBody, Map.class);
if (HttpStatus.OK.value() != result.getStatusCodeValue()) { LOG.debug("状态码:{}", result.getStatusCodeValue());
throw new SearchException("获取Token失败"); if (HttpStatus.OK.value() != result.getStatusCodeValue()) {
throw new SearchException("获取Token失败");
}
Map body = result.getBody();
return (String) body.get("data");
} catch (HttpClientErrorException e) {
if (e.getRawStatusCode() == HttpStatus.BAD_REQUEST.value()) {
throw new SearchException(e.getResponseBodyAsString());
}
throw new SearchException("绑定用户 | 登录失败");
} }
Map body = result.getBody();
return (String) body.get("data");
} }
} }