LG88888888 3 năm trước cách đây
mục cha
commit
7422592ebe

+ 10 - 13
src/main/java/net/chenlin/dp/common/openapi4j/commons/TokenManager.java

@@ -4,17 +4,22 @@ import java.math.BigDecimal;
 import java.util.Properties;
 
 import net.chenlin.dp.common.openapi4j.exception.OpenAPIException;
+import net.chenlin.dp.common.openapi4j.service.AccountService;
 import org.apache.commons.lang.StringUtils;
 
 import com.alibaba.fastjson.JSONObject;
 
 import net.chenlin.dp.common.openapi4j.util.HttpUtil;
 import net.chenlin.dp.common.openapi4j.util.PropUtil;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 public class TokenManager {
 
 	public static AccessToken accessToken;
 
+	final static Logger logger = LoggerFactory.getLogger(AccountService.class);
+
 	public static String getToKenId() {
 
 		long nowTime = System.currentTimeMillis();
@@ -22,19 +27,9 @@ public class TokenManager {
 			if (accessToken == null) {
 				accessToken = getAccessToken();
 			}
-//			else if ((nowTime - accessToken.getCreateTime() + 10000) >= accessToken.getExpiresIn()) {
-//				accessToken = getAccessToken();
-//			}
-			else{
-				BigDecimal time=new BigDecimal("120000");
-				BigDecimal subtract1 = new BigDecimal(accessToken.getCreateTime()).subtract(time);
-				BigDecimal subtract = new BigDecimal(nowTime).subtract(subtract1);
-				BigDecimal divide = subtract.divide(new BigDecimal("1000"),0, BigDecimal.ROUND_UP);
-				if (Long.parseLong(divide.toString())>=accessToken.getExpiresIn()){
-					accessToken = getAccessToken();
-				}
+			else if ((nowTime - accessToken.getCreateTime() + 10000) >= accessToken.getExpiresIn()) {
+				accessToken = getAccessToken();
 			}
-
 		} catch (OpenAPIException e) {
 			e.printStackTrace();
 		}
@@ -51,14 +46,16 @@ public class TokenManager {
 		url = StringUtils.replace(url, "{from_account}", from_account);
 		url = StringUtils.replace(url, "{app_key}", app_key);
 		url = StringUtils.replace(url, "{app_secret}", app_secret);
-
 		String str = null;
+		logger.debug(url);
 		try {
 			str = HttpUtil.get(url);
+			logger.debug(str);
 		} catch (Exception e) {
 			// TODO Auto-generated catch block
 			throw new OpenAPIException(e.getMessage(), e);
 		}
+
 		JSONObject jsonObject = JSONObject.parseObject(str);
 		JSONObject tokenObject = jsonObject.getJSONObject("token");
 		AccessToken token = new AccessToken();