mooore / magento2-module-geoip
Magento 2 模块,提供基本的 Geo IP 检测。
1.1.1
2021-06-10 09:04 UTC
Requires
- magento/framework: ^102.0|^103.0
- psr/log: ^1.0
This package is auto-updated.
Last update: 2024-09-10 16:22:22 UTC
README
Magento 2 模块,提供基本的 Geo IP 检测。
API
REST
$ curl https://<magento site>/rest/V1/countryCode "NL"
PHP
<?php namespace Acme\Component; use Mooore\GeoIp\Api\CountryCodeInterface; class SomeComponent { /** * @var \Mooore\GeoIp\Api\CountryCodeInterface */ private $countryCode; public function __construct(CountryCodeInterface $countryCode) { $this->countryCode = $countryCode; } public function execute(): void { //output: Country is NL echo sprintf('Country is %s', $this->countryCode->get()); } }
安装
composer require mooore/magento2-module-geoip bin/magento setup:upgrade
配置
此模块依赖于几个输入的回退依赖
- GeoIP 变量
GEOIP_COUNTRY_CODE
。 - GeoIP2 变量
COUNTRY_CODE
。 - Cloudflare 头部
CF-IPCountry
。 - IpInfo.io API。
要使用 IpInfo.io 进行回退,请按照以下步骤操作
- 在 ipinfo.io 上有一个账户(每月免费50,000次请求)。
- 拥有 ipinfo.io API 密钥。
- 在 Magento 2 后端中配置它(高级 -> 系统 -> GeoIP):