diff --git a/composer.json b/composer.json index 8f0620f..95b32a1 100644 --- a/composer.json +++ b/composer.json @@ -43,7 +43,8 @@ "ramsey/uuid": "^4.7", "google/recaptcha": "^1.3", "vlucas/phpdotenv": "^5.6", - "yiisoft/yii2-httpclient": "^2.0" + "yiisoft/yii2-httpclient": "^2.0", + "ipinfo/ipinfo": "^3.1" }, "require-dev": { "yiisoft/yii2-debug": "~2.1.0", diff --git a/utils/IPLocation.php b/utils/IPLocation.php new file mode 100644 index 0000000..9b78b55 --- /dev/null +++ b/utils/IPLocation.php @@ -0,0 +1,36 @@ +client = new IPinfo(Yii::$app->params['ipinfoToken']); + } + public static function getDetails(string $ip): ?Details + { + $instance = new self(); + try { + return $instance->client->getDetails($ip); + } catch (IPinfoException $e) { + Yii::error($e->getMessage()); + /* + * Note: + * 如果出现SSL certificate problem: unable to get local issuer certificate + * 下载 https://curl.haxx.se/ca/cacert.pem 到 php\extras\ssl 并在php.ini中配置 + * curl.cainfo = "文件的绝对路径" + * 解决方法参考: https://martinsblog.dk/windows-iis-with-php-curl-60-ssl-certificate-problem-unable-to-get-local-issuer-certificate/ + */ + return null; + } + } + +} \ No newline at end of file