mooore/magento2-module-geoip

Magento 2 模块,提供基本的 Geo IP 检测。

安装次数: 22,721

依赖者: 0

建议者: 0

安全: 0

星标: 5

关注者: 5

分支: 1

开放问题: 0

类型:magento2-module

1.1.1 2021-06-10 09:04 UTC

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

配置

此模块依赖于几个输入的回退依赖

  1. GeoIP 变量 GEOIP_COUNTRY_CODE
  2. GeoIP2 变量 COUNTRY_CODE
  3. Cloudflare 头部 CF-IPCountry
  4. IpInfo.io API。

要使用 IpInfo.io 进行回退,请按照以下步骤操作

  1. ipinfo.io 上有一个账户(每月免费50,000次请求)。
  2. 拥有 ipinfo.io API 密钥。
  3. 在 Magento 2 后端中配置它(高级 -> 系统 -> GeoIP):配置