thealgoslingers/autoprice

AutoPrice类提供了根据用户位置动态计算价格的功能。

v2.2.0 2024-07-13 22:01 UTC

This package is auto-updated.

Last update: 2024-09-13 22:19:07 UTC


README

利用Autoprice实时数据和高级算法根据用户位置计算价格。

要求

请从IP2LOCATION.IO获取API密钥。

安装

composer require thealgoslingers/autoprice

使用

注意:

Autoprice返回与其关联的货币代码的(转换后的)货币。因此,您不需要在末尾再次手动添加货币代码。例如,将10美元转换为加纳塞地,Autoprice将返回"GHS15.152"而不是仅仅"15.532"。

某些API计划不包括国家的货币代码。在这种情况下,将返回原始数据。即没有货币代码的金额。

有关更多详细信息,请参阅ip2location

<?php
require 'vendor/autoload.php';

use thealgoslingers\AutoPrice;

// Usage example
$api_key = 'your_api_key_here'; // api key from ip2location.io

// the default base price is approximately
// or same as 1 USD. So we assume price is 
// being converted from USD 
$base_price = 100.0;//base price to be converted from

$dp = new AutoPrice($api_key, $base_price);
$user_ip = '8.8.8.8';// ip of the user 

echo $dp->calculatePrice($user_ip);