定制 faiznurullah/rajaongkir 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

faiznurullah/rajaongkir

Composer 安装命令:

composer require faiznurullah/rajaongkir

包简介

package for php application for connect with rajaongkir service

README 文档

README

A lightweight PHP library to access RajaOngkir endpoints through https://rajaongkir.komerce.id/api/v1.

Features

  • Get provinces
  • Get cities by province
  • Get districts by city
  • Get subdistricts by district
  • Calculate domestic shipping cost by district
  • Track waybill (AWB)
  • Search domestic destinations

Requirements

  • PHP 7.4+
  • Composer

Installation

If you are using this package in another project:

composer require faiznurullah/rajaongkir

For local development in this repository:

composer install

Quick Start

<?php

require_once __DIR__ . '/vendor/autoload.php';

use Faiznurullah\Rajaongkir\RajaOngkir;

$apiKey = 'YOUR_API_KEY';
$rajaOngkir = new RajaOngkir($apiKey);

$provinces = $rajaOngkir->getProvinces();
print_r($provinces);

API Methods

1) Get Provinces

$response = $rajaOngkir->getProvinces();

2) Get Cities

$provinceId = 5;
$response = $rajaOngkir->getCities($provinceId);

3) Get Districts

$cityId = 39;
$response = $rajaOngkir->getDistrict($cityId);

4) Get Subdistricts

$districtId = 574;
$response = $rajaOngkir->getSubdistrict($districtId);

5) Calculate District Shipping Cost

$originDistrictId = 574;
$destinationDistrictId = 114;
$weight = 1000; // grams
$courier = 'jne';

$response = $rajaOngkir->calculateDistrictCost(
	$originDistrictId,
	$destinationDistrictId,
	$weight,
	$courier
);

6) Track Waybill

$waybill = 'JP1234567890';
$courier = 'jne';

$response = $rajaOngkir->trackWaybill($waybill, $courier);

7) Search Domestic Destination

$query = 'Bandung';

// With optional limit and offset
$response = $rajaOngkir->searchDomesticDestination($query, 10, 0);

// Without optional arguments
$response = $rajaOngkir->searchDomesticDestination($query);

Error Handling

All methods return an array.

If a request fails, the library returns an array with an error description (from Guzzle exception or generic exception), for example:

[
	'rajaongkir' => [
		'status' => [
			'code' => 500,
			'description' => 'Error: ...'
		]
	]
]

Run Local Test Script

This repository includes src/test.php.

From project root:

php src/test.php

Or from src directory:

php test.php

Troubleshooting

Class not found (RajaOngkir)

Make sure Composer autoload is loaded before using the class:

require_once __DIR__ . '/../vendor/autoload.php';

Warning: Module "ftp" is already loaded

This warning comes from your PHP extension configuration and is unrelated to this package.

Check your php.ini and remove duplicate extension=ftp entries.

License

MIT

统计信息

  • 总下载量: 29
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 3
  • 点击次数: 1
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 3
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2024-08-07

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固