浏览代码

腾讯企业邮件接口优化

MaxKey 2 年之前
父节点
当前提交
4424d677ef

+ 26 - 11
maxkey-protocols/maxkey-protocol-extendapi/src/main/java/org/maxkey/authz/exapi/endpoint/adapter/ExtendApiQQExmailAdapter.java

@@ -95,22 +95,32 @@ public class ExtendApiQQExmailAdapter extends AbstractAuthorizeAdapter {
     public String getToken(String corpid , String corpsecret) {
     	String accessToken = tokenCache.getIfPresent(corpid);
     	if(accessToken ==  null) {
+    		_logger.debug("corpid {} , corpsecret {}" , corpid , corpsecret);
+    		_logger.debug("get token url {}" , String.format(TOKEN_URI,corpid,corpsecret));
 	    	String responseBody = new HttpRequestAdapter().get(String.format(TOKEN_URI,corpid,corpsecret),null);
-			Token token =JsonUtils.gsonStringToObject(responseBody,Token.class);
-			_logger.debug("access_token {}" , token);
-			accessToken = token.getAccess_token();
-			tokenCache.put(corpid, accessToken);
+	    	_logger.debug("Response Body {}" , responseBody);
+			Token token = JsonUtils.gsonStringToObject(responseBody,Token.class);
+			if(token.getErrcode() == 0 ) {
+				_logger.debug("access_token {}" , token);
+				accessToken = token.getAccess_token();
+				tokenCache.put(corpid, accessToken);
+			}else {
+				_logger.debug("Error Code {}" , exMailMsgMapper.get(token.getErrcode()));;
+			}
     	}
     	return accessToken;
     }
     
     public ExMailLoginUrl getLoginUrl(String accessToken,String userId) {
-    	_logger.debug("userId {}" , userId);
-		String authKeyBody = new HttpRequestAdapter().get(String.format(AUTHKEY_URI,accessToken,userId),null);
-		
-		ExMailLoginUrl exMailLoginUrl = JsonUtils.gsonStringToObject(authKeyBody, ExMailLoginUrl.class);
-		_logger.debug("LoginUrl {} " , exMailLoginUrl);
-		return exMailLoginUrl;
+    	if(accessToken != null) {
+	    	_logger.debug("userId {}" , userId);
+			String authKeyBody = new HttpRequestAdapter().get(String.format(AUTHKEY_URI,accessToken,userId),null);
+			
+			ExMailLoginUrl exMailLoginUrl = JsonUtils.gsonStringToObject(authKeyBody, ExMailLoginUrl.class);
+			_logger.debug("LoginUrl {} " , exMailLoginUrl);
+			return exMailLoginUrl;
+    	}
+		return new ExMailLoginUrl(-1,"access_token is null .");
     }
     
 	class ExMailMsg{
@@ -168,7 +178,7 @@ public class ExtendApiQQExmailAdapter extends AbstractAuthorizeAdapter {
 		@Override
 		public String toString() {
 			StringBuilder builder = new StringBuilder();
-			builder.append("Token [access_token=");
+			builder.append("Token [access_token = ");
 			builder.append(access_token);
 			builder.append("]");
 			return builder.toString();
@@ -190,6 +200,11 @@ public class ExtendApiQQExmailAdapter extends AbstractAuthorizeAdapter {
 		
 		public ExMailLoginUrl() {
 		}
+		
+		public ExMailLoginUrl(Integer errcode,String errmsg) {
+			super.errcode = errcode;
+			super.errmsg = errmsg;
+		}
 
 		@Override
 		public String toString() {

+ 1 - 2
maxkey-protocols/maxkey-protocol-saml-2.0/src/main/java/org/maxkey/authz/saml20/binding/decoder/OpenHTTPRedirectDecoder.java

@@ -83,8 +83,7 @@ public class OpenHTTPRedirectDecoder extends HTTPRedirectDeflateDecoder {
 		String receiverEndpoint = DatatypeHelper
 				.safeTrimOrNullString(getActualReceiverEndpointURI(messageContext));
 
-		log.debug("Intended message destination endpoint: {}",
-				messageDestination);
+		log.debug("Intended message destination endpoint: {}",messageDestination);
 		log.debug("Actual message receiver endpoint: {}", receiverEndpoint);
 
 		// 协议头统一(http或https,需要和destination统一)