php Aramexs 物流 createShipments

使用 php对接 Aramexs 物流

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

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

三、熟悉开发者文档,由于业务需要,只对接了发货(createShipments),其他功能未对接
https://www.aramex.com/docs/default-source/resourses/resourcesdata/shipping-services-api-manual.pdf

在这里插入图片描述

四、通过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' => 'email@users.companies',//邮箱
                'phone'      => '+123456789982',//电话
                'cell_phone' =>'+123456789982',//电话
                'country_code' =>  'SA',//国家编码
                'city' =>  'SA',//测试
                'zip_code' => '',//邮编
                'line1' => '',//发货地址
/*                'line2' => '',
                'line3' => ' ',*/
            ],
         'consignee' => [//收货人信息
                'name' => 'Steve',
                'email' => 'email@users.companies',
                'phone'      => '+123456789982',
                'cell_phone' => '+321654987789',
                '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 哦!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值