juhara / rajaongkir
高级 RajaOngkir API PHP 类
v1.0.1
2023-05-05 01:15 UTC
Requires
- php: ^7.4|^8.0.2
- guzzlehttp/guzzle: ^7.0
Requires (Dev)
- phpunit/phpunit: ^9.6
This package is not auto-updated.
Last update: 2024-09-20 14:15:58 UTC
README
RajaOngkir API PHP 客户端
- 支持所有类型的 RajaOngkir 账户(Starter、Basic、Pro)。
- 根据重量(克)和/或体积(宽度 x 高度 x 长度)获取运费。
这是原始 RajaOngkir 库的分支,目的是添加 PHP 8.0 支持,并替换 HTTP 客户端为 Guzzle。
要求
安装
$ composer require juhara/rajaongkir
使用
初始化
为 Starter 账户创建实例
$rajaongkir = new Juhara\Rajaongkir('YOUR_API_KEY', Rajaongkir::ACCOUNT_STARTER);
当未设置账户类型时,默认为 starter,因此以下代码与上述代码相同。
$rajaongkir = new Juhara\Rajaongkir('YOUR_API_KEY');
为 Basic 账户创建实例
use Juhara\Rajaongkir; $rajaongkir = new Rajaongkir('YOUR_API_KEY', Rajaongkir::ACCOUNT_BASIC);
为 Pro 账户创建实例
use Juhara\Rajaongkir; $rajaongkir = new Rajaongkir('YOUR_API_KEY', Rajaongkir::ACCOUNT_PRO);
获取省份列表
$provinces = $rajaongkir->getProvinces();
获取一个省份的详细信息
// province ID = 1 $province = $rajaongkir->getProvince(1);
获取所有城市的列表
$cities = $rajaongkir->getCities();
获取一个省份中所有城市的列表
// province id = 1 $cities = $rajaongkir->getCities(1);
获取城市详情
// city id = 1 $city = $rajaongkir->getCity(1);
获取一个城市中所有区县的列表
// city id = 39 $subdistricts = $rajaongkir->getSubdistricts(39);
获取区县详情
// subdistrict id = 537 $subdistrict = $rajaongkir->getSubdistrict(537);
获取所有支持国际运输的城市列表
// not available for starter $internationalOrigins = $rajaongkir->getInternationalOrigins();
获取一个省份中所有支持国际运输的城市列表
// not available for starter // province id = 6 $internationalOrigins = $rajaongkir->getInternationalOrigins(6);
获取国际出发详情
// not available for starter // city id = 152 // province id = 6 $internationalOrigin = $rajaongkir->getInternationalOrigin(152, 6);
获取国际国家列表
// not available for starter $internationalDestinations = $rajaongkir->getInternationalDestinations();
获取国际目的地详情
// not available for starter // country id = 108 $internationalDestination = $rajaongkir->getInternationalDestination(108);
根据重量(克)获取运费
// origin city id = 501 // destination subdistrict id = 574 // weight 1000 gram // courier = 'jne' $cost = $rajaongkir->getCost(['city' => 501], ['subdistrict' => 574], 1000, 'jne');
根据体积获取运费
// origin city id = 501 // destination subdistrict id = 574 // volume 50x60x70 // courier = 'jne' $cost = $rajaongkir->getCost( ['city' => 501], ['subdistrict' => 574], [ 'width' => 50, 'height' => 60, 'length' => 70, ], 'jne' );
根据重量或体积获取运费
// origin city id = 501 // destination subdistrict id = 574 // weight 1000 gram // volume 50x60x70 // courier = 'jne' $cost = $rajaongkir->getCost( ['city' => 501], ['subdistrict' => 574], [ 'weight' => 1000, 'length' => 50, 'width' => 50, 'height' => 50, ], 'jne' );
根据重量获取国际运费
// not available for starter // origin city id = 152 // destination country id = 108 // weight 1400 gram // courier = 'pos' $cost = $rajaongkir->getCost( ['city' => 152], ['country' => 108], 1400, 'pos' );
跟踪运输
// receipt id (no resi pengiriman) = 'SOCAG00183235715' // courier = 'jne' $waybill = $rajaongkir->getWaybill('SOCAG00183235715', 'jne');
获取印尼盾(IDR)货币兑换至美元(USD)
$currency = $rajaongkir->getCurrency();
获取最新的错误信息
// get latest error if(false === ($waybill = $rajaongkir->getWaybill('SOCAG00183235715', 'jne'))) { var_dump($rajaongkir->getErrors()); }
根据账户类型获取快递列表
$supportedCouriers = $rajaongkir->getSupportedCouriers();
根据账户类型获取运单跟踪列表
$supportedWayBills = $rajaongkir->getSupportedWayBills();