Last active
March 14, 2019 07:22
-
-
Save showsky/3fddb37fd300277e83a02438782ffe8c to your computer and use it in GitHub Desktop.
Can check whether support iOS universal links or Android app link
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| function curl_get($url) { | |
| $header_array = array( | |
| 'Content-Type: application/json', | |
| 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.119 Safari/537.36' | |
| ); | |
| $options = array( | |
| CURLOPT_URL => $url, | |
| CURLOPT_RETURNTRANSFER => TRUE, | |
| CURLOPT_VERBOSE => FALSE, | |
| CURLOPT_SSL_VERIFYPEER => FALSE, | |
| ); | |
| $options[CURLOPT_HTTPHEADER] = $header_array; | |
| $ch = curl_init(); | |
| curl_setopt_array($ch, $options); | |
| if ( ! $result = curl_exec($ch)) { | |
| trigger_error(curl_error($ch)); | |
| } | |
| switch (curl_getinfo($ch, CURLINFO_HTTP_CODE)) { | |
| case 200: | |
| break; | |
| default: | |
| $result = FALSE; | |
| } | |
| curl_close($ch); | |
| return $result; | |
| } | |
| function check_json($data) { | |
| json_decode($data); | |
| return (json_last_error() == JSON_ERROR_NONE); | |
| } | |
| function check_ios($hostname, $is_retuen = FALSE) { | |
| $url_array = array( | |
| sprintf('https://%s/apple-app-site-association', $hostname), | |
| sprintf('https://%s/.well-known/apple-app-site-association', $hostname) | |
| ); | |
| $size = count($url_array); | |
| for ($i = 0; $i < $size; $i++) { | |
| $result = curl_get($url_array[$i]); | |
| if ( ! $result || ! check_json($result)) { | |
| return FALSE; | |
| } | |
| } | |
| if ($is_retuen) { | |
| return $result; | |
| } | |
| return TRUE; | |
| } | |
| function check_android($hostname, $is_retuen = FALSE) { | |
| $url_array = array( | |
| sprintf('https://%s/.well-known/assetlinks.json', $hostname), | |
| ); | |
| $size = count($url_array); | |
| for ($i = 0; $i < $size; $i++) { | |
| $result = curl_get($url_array[$i]); | |
| if ( ! $result || ! check_json($result)) { | |
| return FALSE; | |
| } | |
| } | |
| if ($is_retuen) { | |
| return $result; | |
| } | |
| return TRUE; | |
| } | |
| if (count($argv) < 2) { | |
| exit('hostname error'); | |
| } | |
| $hostname = $argv[1]; | |
| $result = array( | |
| sprintf('android app link: %s', var_export(check_android($hostname), TRUE)), | |
| sprintf('ios universal Links: %s', var_export(check_ios($hostname), TRUE)) | |
| ); | |
| var_export($result); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
