php Aramexs 物流 createShipments

php Aramexs 物流 createShipments使用 php 对接 Aramexs 物流 一 打开 Aramexs 官网 https www aramex com sa en aramex home 并注册账号 二 注册后 设置一下自己是发货地址 地址记得用国际的国家编码哦 三 熟悉开发者文档 由于业务需要 只对接了发货

大家好,我是讯享网,很高兴认识大家。

使用 php对接 Aramexs 物流

一、打开 Aramexs 官网 https://www.aramex.com/sa/en/aramex-home,并注册账号

二、注册后,设置一下自己是发货地址(地址记得用国际的国家编码哦)

在这里插入图片描述
讯享网

四、通过github获取一下大佬代码 https://github.com/hakanersu/amaran-laravel
在大佬的基础上,调整了一下
https://github.com/yanggcn/php-aramex

五、上代码

 / * Notes:发货 * Interface:createShipment * @return array */ public function createShipment(){ 
    $result = Aramex::createShipment([ 'shipper' => [ 'name' => 'SA',//发货人地址 与你填写的地址保持一致哦 'email' => 'es',//邮箱 'phone' => '+2',//电话 'cell_phone' =>'+2',//电话 'country_code' => 'SA',//国家编码 'city' => 'SA',//测试 'zip_code' => '',//邮编 'line1' => '',//发货地址 /* 'line2' => '', 'line3' => ' ',*/ ], 'consignee' => [//收货人信息 'name' => 'Steve', 'email' => 'es', 'phone' => '+2', 'cell_phone' => '+9', 'country_code' => 'AE', 'city' => 'Abadilah', 'zip_code' => '', 'line1' => 'Line1 Details', 'line2' => 'Line2 Details', 'line3' => 'Line3 Details', ], 'shipping_date_time' => time() + 50000, 'due_date' => time() + 60000, 'comments' => 'No Comment', 'pickup_location' => 'Reception', 'customs_value_amount' => 100, 'weight' => 1, 'number_of_pieces' => 1, 'description' => '商品描述',//商品描述 ]); if ($result->HasErrors) { 
    return $result->Notifications->Notification; }elseif ($result->errors){ 
    return $result->Notifications->Notification; }else{ 
    $results = $result->Shipments->ProcessedShipment; // $results = json_decode( json_encode($results),true); $label_url = $results->ShipmentLabel->LabelURL;//获取物流编码图片 $shipment_no = $results->ID;//物流编码 } return $results ; } 

讯享网

六,获取国家城市信息

讯享网 / * Notes:获取国家/城市 数据 * @param string $country_code 国家编号 * @param $is_city 0=国家;1=城市 */ public function getCountries($country_code='',$is_city=0){ 
    if($is_city){ 
    $list = Aramex::fetchCities($country_code); }else{ 
    $list = Aramex::fetchCountries($country_code); } return $list; } public static function fetchCities($code, $nameStartWith = null) { 
    $soapClient = AramexHelper::getSoapClient(AramexHelper::LOCATION); $aramex = new Core; $aramex->initializeFetchCities($code, $nameStartWith); $call = $soapClient->FetchCities($aramex->getParam()); $ret = new \stdClass; if ($call->HasErrors) { 
    $ret->error = 1; $ret->errors = $call->Notifications; } else{ 
    $ret = $call; } return $ret; } 

七,注意事项
1、国家城市数据比较多,如果存数据库里,查询的时候需要优化一下,否则你会卡死的
2、发货时填写的国家区号,需要注意下,用的international code 哦!

小讯
上一篇 2025-02-13 11:13
下一篇 2025-04-05 11:15

相关推荐

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容,请联系我们,一经查实,本站将立刻删除。
如需转载请保留出处:https://51itzy.com/kjqy/114859.html