You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
First, checking for the existence of property is a must. Otherwise you'll encounter errors.
For example (Authentic Experience but not the same ip address):
IP:103.58.137.100 has not got region property.
the break is in the wrong place and it would cause your multiple API settings to fail.
foreach ($servicesas$service) {
if ($service->name() === $name) {
$this->serviceSelected = $service;
//where the break should be
}
break; //wrong place
}
Suggestion:
Please consider turning to/adding the option ipinfo.io for much more detailed location and fewer "unknown" hosts, as ipsb marks so many regions as unknown in China.
The difference is that ipinfo.io needs us to sign up, and its free plan allows 50k requests per month(, which in fact is fairly enough in my mind.)
Example code:
<?php/* * This file is part of GBCLStudio Project. * * Copyright (c) 2023 GBCLStudio PHP Project Team. * * For the full copyright and license information, please view the LICENSE.md * file that was distributed with this source code. */namespaceGBCLStudio\GeoIp\Api\Service;
useGBCLStudio\GeoIp\Api\GeoIpInterface;
useGBCLStudio\GeoIp\ServiceResponse;
useGuzzleHttp\Client;
useGuzzleHttp\Exception\GuzzleException;
classIpInfoIoimplementsGeoIpInterface
{
privateClient$client;
publicfunction__construct()
{
$this->client = newClient([
'base_uri' => 'https://ipinfo.io/',
// 'base_uri' => 'https://ip.sb/',
]);
}
publicfunctionname(): string
{
return'ipinfoio';
}
/** Get IP info from upstream API. * * @param string $ip * @return ServiceResponse * @throws GuzzleException */// public function get(string $ip): ServiceResponse// {// $res = $this->client->get("/geoip/$ip");// $body = json_decode($res->getBody());// return (new ServiceResponse())// ->setCountryCode($body->country_code)// ->setRegion($body->region)// ->setIsp($body->isp)// ->setAddress($ip);// }// public function get(string $ip): ServiceResponse// {// $res = $this->client->get("/geoip/$ip");// $body = json_decode($res->getBody());// // 创建一个新的 ServiceResponse 实例// $response = new ServiceResponse();// $response->setAddress($ip);// // 检查每个属性是否存在,并相应地设置它们// if (isset($body->country_code))$response->setCountryCode($body->country_code);// if (isset($body->region))$response->setRegion($body->region);// if (isset($body->isp))$response->setIsp($body->isp);// return $response;// }publicfunctionget(string$ip, string$api_key): ServiceResponse
{
$res = $this->client->get("/$ip/json?token=$api_key");
$body = json_decode($res->getBody());
// 创建一个新的 ServiceResponse 实例$response = newServiceResponse();
$response->setAddress($ip);
// 检查每个属性是否存在,并相应地设置它们if (isset($body->city))
$response->setRegion($body->city);
if (isset($body->region)) {
$response->setCountryCode($body->region);
}
if (isset($body->country))
$response->setIsp($body->country);
return$response;
}
}
The text was updated successfully, but these errors were encountered:
Due to my personal academic reasons and poor time planning, the bugs mentioned under this issue will be fixed in the next six months, and I'm sorry for bringing you a bad experience!
Bug Report::
For example (Authentic Experience but not the same ip address):
IP:103.58.137.100 has not got
region
property.break
is in the wrong place and it would cause your multiple API settings to fail.Suggestion:
Please consider turning to/adding the option ipinfo.io for much more detailed location and fewer "unknown" hosts, as ipsb marks so many regions as unknown in China.
The difference is that ipinfo.io needs us to sign up, and its free plan allows 50k requests per month(, which in fact is fairly enough in my mind.)
Example code:
The text was updated successfully, but these errors were encountered: