multoo/shipping-myparcel
Composer 安装命令:
composer require multoo/shipping-myparcel
包简介
MyParcel
关键字:
README 文档
README
API documentatie: http://www.myparcel.nl/api-documentatie
/**
* Communication with the MyParcel API
*/
session_start();
define('TARGET_SITE_API', 'http://www.myparcel.nl/api/');
define('NONCE', 0); // note: this should be incremented in case 2 requests occur within the same timestamp (second)
define('TIMESTAMP', time());
define('USERNAME', ''); // your username
define('API_KEY', ''); // your key is provided by MyParcel
/**
* Authentication example
*/
if(isset($_GET['example']) && $_GET['example'] == 'auth')
{
// create JSON
$array = array(
'test JSON' => '1337',
);
$json = urlencode(json_encode($array));
// create GET string (keys in alphabetical order)
$get = implode('&', array(
'json=' . $json,
'nonce=' . NONCE,
'timestamp=' . TIMESTAMP,
'username=' . USERNAME,
));
// create hash
$signature = hash_hmac('sha1', 'GET' . '&' . urlencode($get), API_KEY);
// create final request
$request = TARGET_SITE_API . 'test-authentication/?' . $get . '&signature=' . $signature;
// process request
$result = file_get_contents($request);
// show result
$decode = json_decode($result, true);
var_dump($decode);
exit;
}
/**
* Consignment example
*/
if(isset($_GET['example']) && $_GET['example'] == 'consignment')
{
// NOTE: You can create multiple consignments by creating an array of multiple JSON arrays like below.
// If you do, please make sure you call the create-consignments action (with an 's' at the end).
// create JSON
$array = array(
'process' => 0, // NOTE: process parameter is inactive, put on 1 to create a consignment and process it
'consignment' => array(
'shipment_type' => 'standard', // standard | letterbox | unpaid_letter
'ToAddress' => array(
'country_code' => 'NL', // letterbox packages will always be forced to NL
'name' => 'Lars',
'business' => 'MyParcel',
'postcode' => '2131BC', // if country_code = NL
'house_number' => '679', // if country_code = NL
'number_addition' => '', // if country_code = NL
'eps_postcode' => '', // if country_code != NL
'street' => 'Hoofdweg',
'town' => 'Hoofddorp',
'email' => 'info@myparcel.nl',
'phone_number' => '',
),
'PgAddress' => array( // NOTE: only include if you are shipping to a PostNL PakjeGemak location
'name' => '', // should contain an address exactly as returned by the Locatiekiezer
'street' => '',
'house_number' => '',
'number_addition' => '',
'postcode' => '',
'town' => '',
),
'ProductCode' => array(
'extra_size' => 0,
'home_address_only' => 1,
'signature_on_receipt' => 1,
'return_if_no_answer' => 0,
'insured' => 0,
),
'insured_amount' => '',
'custom_id' => 'TEST API',
'comments' => '',
),
);
$json = urlencode(json_encode($array));
// create GET string (keys in alphabetical order)
$string = implode('&', array(
'json=' . $json,
'nonce=' . NONCE,
'test=' . 1, // NOTE: test parameter is active, put on 0 to actually create a consignment
'timestamp=' . TIMESTAMP,
'username=' . USERNAME,
));
$method = 'POST'; // GET or POST
if($method == 'POST')
{
// hash request POST example
$signature = hash_hmac('sha1', 'POST' . '&' . urlencode($string), API_KEY);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, TARGET_SITE_API . 'create-consignment');
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $string . '&signature=' . $signature);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 60);
$result = curl_exec($ch);
curl_close ($ch);
}
else // GET
{
// hash request GET example
$signature = hash_hmac('sha1', 'GET' . '&' . urlencode($string), API_KEY);
$request = TARGET_SITE_API . 'create-consignment/?' . $string . '&signature=' . $signature;
$result = file_get_contents($request);
}
// show result
$decode = json_decode($result, true);
var_dump($decode);
exit; // remove the exit to continue into the print function, which will process the consignment
/**
* PDF example (this is another api call) NOTE: this will process the consignment, if not already processed
*/
// create JSON
$array = array(
'consignment_id' => $decode['consignment_id'],
'format' => 'json',
);
$json = urlencode(json_encode($array));
// create GET string (keys in alphabetical order)
$string = implode('&', array(
'json=' . $json,
'nonce=' . NONCE,
'timestamp=' . time(),
'username=' . USERNAME,
));
// create hash
$signature = hash_hmac('sha1', 'GET' . '&' . urlencode($string), API_KEY);
// create final request
$request = TARGET_SITE_API . 'retrieve-pdf/?' . $string . '&signature=' . $signature;
// display pdf link (for this example to work, you should use format=pdf in the JSON)
echo '<a href="' . $request . '" target="_blank">' . $request . '</a>';
// process request
$result = file_get_contents($request);
// show result
$decode = json_decode($result, true);
var_dump($decode);
exit;
}
/**
* Status example
*/
if(isset($_GET['example']) && $_GET['example'] == 'status')
{
// create JSON
$array = array(
'consignment_id' => '2596171', // your consignment ID here (a comma-separated list is also possible)
);
$json = urlencode(json_encode($array));
// create GET string (keys in alphabetical order)
$get = implode('&', array(
'json=' . $json,
'nonce=' . NONCE,
'timestamp=' . TIMESTAMP,
'username=' . USERNAME,
));
// create hash
$signature = hash_hmac('sha1', 'GET' . '&' . urlencode($get), API_KEY);
// create final request
$request = TARGET_SITE_API . 'retrieve-status/?' . $get . '&signature=' . $signature;
echo $request;
// process request
$result = file_get_contents($request);
// show result
$decode = json_decode($result, true);
var_dump($decode);
exit;
}
/**
* Retourlink example
*/
if(isset($_GET['example']) && $_GET['example'] == 'retourlink')
{
// create JSON
$array = array(
'email' => 'martin.boer@trq.nl', // no data | 'email' | 'consignment_id'
);
$json = urlencode(json_encode($array));
// create GET string (keys in alphabetical order)
$get = implode('&', array(
'json=' . $json,
'nonce=' . NONCE,
'timestamp=' . TIMESTAMP,
'username=' . USERNAME,
));
// create hash
$signature = hash_hmac('sha1', 'GET' . '&' . urlencode($get), API_KEY);
// create final request
$request = TARGET_SITE_API . 'create-retourlink/?' . $get . '&signature=' . $signature;
// process request
$result = file_get_contents($request);
// show result
$decode = json_decode($result, true);
var_dump($decode);
exit;
}
/**
* Credit consignment example
*/
if(isset($_GET['example']) && $_GET['example'] == 'credit')
{
// create JSON
$array = array(
'consignment_id' => '12345',
);
$json = urlencode(json_encode($array));
// create GET string (keys in alphabetical order)
$get = implode('&', array(
'json=' . $json,
'nonce=' . NONCE,
'timestamp=' . TIMESTAMP,
'username=' . USERNAME,
));
// create hash
$signature = hash_hmac('sha1', 'GET' . '&' . urlencode($get), API_KEY);
// create final request
$request = TARGET_SITE_API . 'consignment-credit/?' . $get . '&signature=' . $signature;
// process request
$result = file_get_contents($request);
// show result
$decode = json_decode($result, true);
var_dump($decode);
exit;
}
multoo/shipping-myparcel 适用场景与选型建议
multoo/shipping-myparcel 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 30 次下载、GitHub Stars 达 0, 最近一次更新时间为 2026 年 03 月 23 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「shipping-myparcel」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 multoo/shipping-myparcel 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 multoo/shipping-myparcel 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 30
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 13
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: proprietary
- 更新时间: 2026-03-23