yonge 3 năm trước cách đây
mục cha
commit
86ce3d4c1a

+ 8 - 3
mec-student/src/main/java/com/ym/mec/student/controller/WechatController.java

@@ -12,6 +12,7 @@ import java.util.TreeMap;
 import java.util.UUID;
 
 import org.apache.commons.codec.digest.DigestUtils;
+import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.GetMapping;
 import org.springframework.web.bind.annotation.RequestMapping;
@@ -71,8 +72,12 @@ public class WechatController extends BaseController {
 
 	private String getAccessToken(String appid, String secret) throws IOException {
 
-		if(redisCache.exists(WX_ACCESS_TOKEN)){
-			return redisCache.get(WX_ACCESS_TOKEN).toString();
+		if (redisCache.exists(WX_ACCESS_TOKEN)) {
+			if (redisCache.get(WX_ACCESS_TOKEN) != null) {
+				if (StringUtils.isNotEmpty(redisCache.get(WX_ACCESS_TOKEN).toString())) {
+					return redisCache.get(WX_ACCESS_TOKEN).toString();
+				}
+			}
 		}
 		Map<String, Object> parameterMap = new HashMap<String, Object>();
 		parameterMap.put("grant_type", "client_credential");
@@ -95,5 +100,5 @@ public class WechatController extends BaseController {
 
 		return (String) JSONPath.extract(result, "$.ticket");
 	}
-
+	
 }