溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點(diǎn)擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

在laravel中如何使用順豐同城配送的擴(kuò)展包

發(fā)布時(shí)間:2021-08-11 14:52:38 來源:億速云 閱讀:147 作者:小新 欄目:編程語言

這篇文章主要介紹在laravel中如何使用順豐同城配送的擴(kuò)展包,文中介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們一定要看完!

                           

公司項(xiàng)目需要用到順豐外賣,所以看了下有沒有現(xiàn)成的擴(kuò)展包可用,但是發(fā)現(xiàn)沒有,官方也沒有SDK,所以自己寫了一個包,省了不少工作量。

安裝

$ composer require ycstar/sfopenic -vvv

配置

在使用本擴(kuò)展之前,你需要去順豐同城開放平臺注冊賬號,然后申請開發(fā)者ID,獲取相應(yīng)的配置

使用

    use Ycstar\Sfopenic\Sfopenic;

    $config = [
        'host'    => 'xxxxxxxxxxxx',
        'dev_id'  => 'xxxxxxxxxxxx',
        'dev_key' => 'xxxxxxxxxxxx'
    ];

    $sfopenic = new Sfopenic($config);

預(yù)創(chuàng)建訂單

    $data = [
        'shop_id' => 'xxxxxxxxxxxx',
        'user_address' => "北京市海淀區(qū)學(xué)清嘉創(chuàng)大廈A座15層",
        'user_lng' => '116.352569',
        'user_lat' => '40.014838',
        'weight' => 100,
        'product_type' => 1,
        'pay_type' => 1,
        'is_appoint' => 0,
        'is_insured' => 0,
        'is_person_direct' => 0
    ];

    $res = $sfopenic->preCreateOrder($data);

創(chuàng)建訂單

    $array = [
        'shop_id' => 'xxxxxxxxxxxx',
        'shop_order_id' => 'xxxxxxxxxxxx',
        'order_source' => 'xx',
        'pay_type' => 1,
        'order_time' => time(),
        'is_appoint' => 0,
        'is_insured' => 0,
        'is_person_direct' => 0,
        'version' => 17,
        'order_sequence' => 'xx',
        'remark' => 'xx'
    ];

    $receive =[
        'user_name' => "xx",
        'user_phone' => "xxxxxxxxxx",
        'user_address' => "北京市海淀區(qū)學(xué)清嘉創(chuàng)大廈A座15層",
        'user_lng' => '116.352569',
        'user_lat' => '40.014838',
    ];

    $order_detail = [
        'total_price' => 1,//總金額
        'product_type' => 1, //物品類型 1:送餐 8:飲品
        'weight_gram' => 100,//物品重量
        'product_num' => 3,//物品個數(shù)
        'product_type_num' => 1,//物品種類個數(shù)
    ];

    $product_detail[]=[
        'product_name'=>'xxx',//物品名稱
        'product_num' => 1,//物品數(shù)量
    ];

    $order_detail['product_detail'] = $product_detail;

    $array['order_detail'] = $order_detail;

    $array['receive'] = $receive;

    $res = $sfopenic->createOrder($data);

取消訂單

    $data = [
        'order_id' => 'xxxxxxxxxxxx',
        'order_type' => 1 //1、順豐訂單號 2、商家訂單號
        'shop_id' => 0,   //order_type=2時(shí)必傳shop_id與shop_type
        'shop_type' => 1, //1、順豐店鋪ID 2、接入方店鋪ID
        'cancel_code' => 313, //不填時(shí)默認(rèn)cancel_code=313,cancel_reason=商家發(fā)起取消
        'cancel_reason' => ''
    ];

    $res = $sfopenic->cancelOrder($data);

預(yù)取消訂單

    $data = [
        'order_id' => 'xxxxxxxxxxxx',
        'order_type' => 1 //1、順豐訂單號 2、商家訂單號
        'shop_id' => 0,   //order_type=2時(shí)必傳shop_id與shop_type
        'shop_type' => 1, //1、順豐店鋪ID 2、接入方店鋪ID
        'cancel_reason' => ''
    ];

    $res = $sfopenic->preCancelOrder($data);

訂單加小費(fèi)

    $data = [
        'order_id' => 'xxxxxxxxxxxx',
        'order_type' => 1 //1、順豐訂單號 2、商家訂單號
        'shop_id' => 0,
        'shop_type' => 1, //1、順豐店鋪ID 2、接入方店鋪ID
        'gratuity_fee' => 0
    ];

    $res = $sfopenic->addOrderGratuityFee($data);

獲取訂單加小費(fèi)信息

    $data = [
        'order_id' => 'xxxxxxxxxxxx',
        'order_type' => 1 //1、順豐訂單號 2、商家訂單號
        'shop_id' => 0,
        'shop_type' => 1, //1、順豐店鋪ID 2、接入方店鋪ID
    ];

    $res = $sfopenic->getOrderGratuityFee($data);

訂單狀態(tài)流查詢

    $data = [
        'order_id' => 'xxxxxxxxxxxx',
        'order_type' => 1 //1、順豐訂單號 2、商家訂單號
        'shop_id' => 0,   //order_type=2時(shí)必傳shop_id與shop_type
        'shop_type' => 1, //1、順豐店鋪ID 2、接入方店鋪ID
    ];

    $res = $sfopenic->listOrderFeed($data);

訂單實(shí)時(shí)信息查詢

    $data = [
        'order_id' => 'xxxxxxxxxxxx',
        'order_type' => 1 //1、順豐訂單號 2、商家訂單號
        'shop_id' => 0,   //order_type=2時(shí)必傳shop_id與shop_type
        'shop_type' => 1, //1、順豐店鋪ID 2、接入方店鋪ID
    ];

    $res = $sfopenic->getOrderStatus($data);

催單

    $data = [
        'order_id' => 'xxxxxxxxxxxx',
        'order_type' => 1 //1、順豐訂單號 2、商家訂單號
        'shop_id' => 0,   //order_type=2時(shí)必傳shop_id與shop_type
        'shop_type' => 1, //1、順豐店鋪ID 2、接入方店鋪ID
    ];

    $res = $sfopenic->reminderOrder($data);

改單

    $data = [
        'order_id' => 'xxxxxxxxxxxx',
        'order_type' => 1 //1、順豐訂單號 2、商家訂單號
        'shop_id' => 0,
        'shop_type' => 1, //1、順豐店鋪ID 2、接入方店鋪ID
        'user_name'=> '',
        'user_phone'=> '',
        'user_address'=> '',
        'lbs_type'=> 2, //1:百度坐標(biāo),2:高德坐標(biāo)(默認(rèn)值為2,下面的經(jīng)緯度依賴這個坐標(biāo)系,不傳默認(rèn)高德)
        'user_lng'=> '', //傳入用戶地址經(jīng)緯度順豐側(cè)則不根據(jù)用戶地址解析
        'user_lat'=> '',
    ];

    $res = $sfopenic->changeOrder($data);

獲取配送員實(shí)時(shí)坐標(biāo)接口

    $data = [
        'order_id' => 'xxxxxxxxxxxx',
        'order_type' => 1 //1、順豐訂單號 2、商家訂單號
        'shop_id' => 0,   //order_type=2時(shí)必傳shop_id與shop_type
        'shop_type' => 1, //1、順豐店鋪ID 2、接入方店鋪ID
    ];

    $res = $sfopenic->riderLatestPosition($data);

獲取配送員軌跡H5

    $data = [
        'order_id' => 'xxxxxxxxxxxx',
        'order_type' => 1 //1、順豐訂單號 2、商家訂單號
        'shop_id' => 0,   //order_type=2時(shí)必傳shop_id與shop_type
        'shop_type' => 1, //1、順豐店鋪ID 2、接入方店鋪ID
    ];

    $res = $sfopenic->riderViewV2($data);

訂單回調(diào)詳情

    $data = [
        'order_id' => 'xxxxxxxxxxxx',
        'order_type' => 1 //1、順豐訂單號 2、商家訂單號
        'shop_id' => 0,
        'shop_type' => 1, //1、順豐店鋪ID 2、接入方店鋪ID
    ];

    $res = $sfopenic->getCallbackInfo($data);

獲取回調(diào)數(shù)據(jù)及回復(fù)內(nèi)容

    $data = $sfopenic->getNotify();
    .
    .
    .
    return $sfopenic->getNotifySuccessReply();

在laravel中使用

在 Laravel 中使用也是同樣的安裝方式,【】

使用下面的命令來導(dǎo)出配置文件

php artisan vendor:publish --tag="ycstar-sfopenic"

配置寫在 config/sfopenic.php 中:

    return [

        'host' => env('SF_OPENIC_HOST'),

        'dev_id' => env('SF_OPENIC_DEV_ID'),

        'dev_key' => env('SF_OPENIC_DEV_KEY')

      ];

然后在 .env 中配置 SF_OPENIC_HOST, SF_OPENIC_DEV_ID, SF_OPENIC_DEV_KEY:

    SF_OPENIC_HOST = xxxxxxxxxxxx    
    SF_OPENIC_DEV_ID = xxxxxxxxxxxx    
    SF_OPENIC_DEV_KEY = xxxxxxxxxxxx

可以用兩種方式來獲取 Ycstar\Sfopenic\Sfopenic 實(shí)例:

  • 方法參數(shù)注入

      .
      .
      .
      public function preCreateOrder(Sfopenic $sfopenic)
      {
          $res = $sfopenic->preCreateOrder($data);
      }
      .
      .
      .
  • 服務(wù)名訪問

      .
      .
      .
      public function preCreateOrder()
      {
          $res = app('sfopenic')->preCreateOrder($data);
      }
      .
      .
      .

以上是“在laravel中如何使用順豐同城配送的擴(kuò)展包”這篇文章的所有內(nèi)容,感謝各位的閱讀!希望分享的內(nèi)容對大家有幫助,更多相關(guān)知識,歡迎關(guān)注億速云行業(yè)資訊頻道!

向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI