formatd / geoip
Neos集成maxmind geoip2客户端
v1.2.1
2023-02-28 16:27 UTC
Requires
- geoip2/geoip2: ~2.13.0
- neos/neos: ^7.0 || ^8.0
README
这是一个Neos CMS集成Maxmind geoip2 api客户端地理位置服务的客户端(maxmind.com)。
它做什么?
此包提供了一个服务类和eel助手,用于访问用户的地理位置信息(通过使用maxmind api分析IP地址)。可选地,您可以集成一个提示,将用户重定向到与他当前位置匹配的内容维度。
兼容性
版本控制方案
1.0.0
| | |
| | Bugfix Releases (non breaking)
| Neos Compatibility Releases (non breaking except framework dependencies)
Feature Releases (breaking)
发布和兼容性
在您自己的插件中使用服务
将IPLocalizationService注入到您的类中,并根据maxmind端点(getCountry,getCity,getInsights)调用方法。geoip2库的相应模型将返回所有可用信息。
在融合中使用服务
要获取小写的国家ISO代码,请调用此eel助手。
${String.toLowerCase(FormatD.GeoIP.country())}
此eel助手接受一个可选参数"key"(例如:"continent.code"),以便直接访问geoip2提供的数据。
使用维度切换提示
要显示一个层,告诉用户如果他位于其他地方需要切换维度,请集成此融合原型并将其放置在您需要的位置。
- 在您的网站上放置融合原型
include: resource://FormatD.GeoIP/Private/Fusion/LocationBasedDimensionSwitchPrompt.fusion
page.someWhereInYourSite = FormatD.GeoIP:LocationBasedDimensionSwitchPrompt
-
将LocationBasedDimensionSwitchPrompt.js集成到您的网站js捆绑中(它需要jQuery)
-
在Settings.yaml中配置映射(哪个ISO代码映射到哪个维度值)(参见配置)
-
使用CSS使其看起来更美观
配置选项
在Settings.yaml中设置您的maxmind凭据
FormatD:
GeoIP:
geoIpUserId: 123456
geoIpLicense: 'somepassword'
对于本地测试,您可以使用调试并模拟您的IP地址启用调试
FormatD:
GeoIP:
debug:
enable: true
simulateIpAddress: '8.8.8.8' # example us ip (google)
为了使LocationBasedDimensionSwitchPrompt正常工作,您必须配置要将哪个ISO代码重定向到哪个维度值。
FormatD:
GeoIP:
locationBasedDimensionSwitch:
dimensionName: 'country'
countryIsoCodeToPresetMap:
gb: 'uk'
de: 'de'
API调用缓存一天。您可以在Caches.yaml中修改默认的生存时间。