| 
					
				 | 
			
			
				@@ -9,8 +9,10 @@ import io.jsonwebtoken.impl.DefaultJwtBuilder; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import lombok.extern.slf4j.Slf4j; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import org.apache.commons.codec.binary.Base64; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import org.springframework.beans.factory.annotation.Value; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import org.springframework.context.annotation.Configuration; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import org.springframework.core.io.ClassPathResource; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import org.springframework.http.*; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import org.springframework.util.LinkedMultiValueMap; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import org.springframework.util.MultiValueMap; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import org.springframework.web.client.RestTemplate; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -29,24 +31,42 @@ import java.util.Map; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 @Slf4j 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+@Configuration 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 public class AppleUtil { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    @Value("${apple.KEYS_URL}") 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     private static String APPLE_KEYS_URL; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     //Revoke tokens 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     //由于苹果注册后,删除用户需要revoke tokens 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     public static String privateKeyStr; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    @Value("${apple.REVOKE_TOKENS_URL}") 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     private static String APPLE_REVOKE_TOKENS_URL; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    @Value("${apple.AUTH_TOKENS_URL}") 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     private static String APPLE_AUTH_TOKENS_URL; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				- 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    @Value("${apple.TEAM_ID}") 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     private static String APPLE_TEAM_ID; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    @Value("${apple.KID}") 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     private static String APPLE_KID; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    @Value("${apple.BUNDLE_IDENTIFIER}") 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     private static String APPLE_BUNDLE_IDENTIFIER; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    @Value("${apple.KEYS_URL}") 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    public void set_APPLE_KEYS_URL(String APPLE_KEYS_URL) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        AppleUtil.APPLE_KEYS_URL = APPLE_KEYS_URL; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    @Value("${apple.REVOKE_TOKENS_URL}") 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    public void set_REVOKE_TOKENS_URL(String REVOKE_TOKENS_URL) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        AppleUtil.APPLE_REVOKE_TOKENS_URL = REVOKE_TOKENS_URL; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    @Value("${apple.AUTH_TOKENS_URL}") 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    public void set_APPLE_AUTH_TOKENS_URL(String AUTH_TOKENS_URL) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        AppleUtil.APPLE_AUTH_TOKENS_URL = AUTH_TOKENS_URL; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    @Value("${apple.TEAM_ID}") 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    public void set_APPLE_TEAM_ID(String TEAM_ID) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        AppleUtil.APPLE_TEAM_ID = TEAM_ID; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    @Value("${apple.KID}") 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    public void set_APPLE_KID(String KID) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        AppleUtil.APPLE_KID = KID; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    @Value("${apple.BUNDLE_IDENTIFIER}") 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    public void set_APPLE_BUNDLE_IDENTIFIER(String BUNDLE_IDENTIFIER) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        AppleUtil.APPLE_BUNDLE_IDENTIFIER = BUNDLE_IDENTIFIER; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     /** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				      * 获取苹果的公钥 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				      * @return 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -143,7 +163,7 @@ public class AppleUtil { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				      */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     private static Key getPrivateKey() { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         try { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            ClassPathResource resource = new ClassPathResource("static/config/AuthKey_8G9994KW4L.p8"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            ClassPathResource resource = new ClassPathResource("config/AuthKey_63NM7757SN.p8"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             InputStream inputStream = resource.getInputStream(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             Reader reader = new InputStreamReader(inputStream, "utf-8"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             BufferedReader br = new BufferedReader(reader); 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -205,20 +225,22 @@ public class AppleUtil { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 //        JSONObject jsonObject = null; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         try { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            privateKeyStr = buildJwt(APPLE_TEAM_ID, APPLE_BUNDLE_IDENTIFIER, APPLE_KID); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            Map<String, String> stringStringHashMap = new HashMap<>(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            stringStringHashMap.put("client_id", APPLE_BUNDLE_IDENTIFIER); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            stringStringHashMap.put("client_secret", privateKeyStr); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            stringStringHashMap.put("code", code); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            stringStringHashMap.put("grant_type", "authorization_code"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            privateKeyStr = buildJwt(APPLE_TEAM_ID, APPLE_BUNDLE_IDENTIFIER, APPLE_KID); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            MultiValueMap<String, String> stringStringHashMap = new LinkedMultiValueMap<>(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            stringStringHashMap.add("client_id", APPLE_BUNDLE_IDENTIFIER); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            stringStringHashMap.add("client_secret", privateKeyStr); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            stringStringHashMap.add("code", code); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            stringStringHashMap.add("grant_type", "authorization_code"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             HttpHeaders headers = new HttpHeaders(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             HttpEntity request = new HttpEntity<>(stringStringHashMap,headers); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             RestTemplate restTemplate = new RestTemplate(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             JSONObject jsonObject = restTemplate.postForObject(APPLE_AUTH_TOKENS_URL,request,JSONObject.class); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            System.out.println(jsonObject); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             return jsonObject.get("access_token").toString(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         } catch (Exception e) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            System.out.println(e.getMessage()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             throw new RuntimeException(e); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -227,13 +249,11 @@ public class AppleUtil { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     public static Boolean appleRevoke(String code) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         try { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             String authToken = getAuthToken(code); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            Map<String, String> requestMap = new HashMap<>(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            requestMap.put("client_id", APPLE_BUNDLE_IDENTIFIER); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            requestMap.put("client_secret", privateKeyStr); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            requestMap.put("token", authToken); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            requestMap.put("token_type_hint", "access_token"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            System.out.println(requestMap); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				- 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            MultiValueMap<String, String> requestMap = new LinkedMultiValueMap<>(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            requestMap.add("client_id", APPLE_BUNDLE_IDENTIFIER); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            requestMap.add("client_secret", privateKeyStr); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            requestMap.add("token", authToken); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            requestMap.add("token_type_hint", "access_token"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             HttpHeaders headers = new HttpHeaders(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             HttpEntity request = new HttpEntity<>(requestMap,headers); 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -256,4 +276,4 @@ public class AppleUtil { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+} 
			 |