您好,登錄后才能下訂單哦!
這篇文章主要介紹在laravel中如何使用順豐同城配送的擴展包,文中介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們一定要看完!
公司項目需要用到順豐外賣,所以看了下有沒有現成的擴展包可用,但是發現沒有,官方也沒有SDK,所以自己寫了一個包,省了不少工作量。
$ composer require ycstar/sfopenic -vvv
在使用本擴展之前,你需要去順豐同城開放平臺注冊賬號,然后申請開發者ID,獲取相應的配置
use Ycstar\Sfopenic\Sfopenic; $config = [ 'host' => 'xxxxxxxxxxxx', 'dev_id' => 'xxxxxxxxxxxx', 'dev_key' => 'xxxxxxxxxxxx' ]; $sfopenic = new Sfopenic($config);
$data = [ 'shop_id' => 'xxxxxxxxxxxx', 'user_address' => "北京市海淀區學清嘉創大廈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);
$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' => "北京市海淀區學清嘉創大廈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,//物品個數 'product_type_num' => 1,//物品種類個數 ]; $product_detail[]=[ 'product_name'=>'xxx',//物品名稱 'product_num' => 1,//物品數量 ]; $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時必傳shop_id與shop_type 'shop_type' => 1, //1、順豐店鋪ID 2、接入方店鋪ID 'cancel_code' => 313, //不填時默認cancel_code=313,cancel_reason=商家發起取消 'cancel_reason' => '' ]; $res = $sfopenic->cancelOrder($data);
$data = [ 'order_id' => 'xxxxxxxxxxxx', 'order_type' => 1 //1、順豐訂單號 2、商家訂單號 'shop_id' => 0, //order_type=2時必傳shop_id與shop_type 'shop_type' => 1, //1、順豐店鋪ID 2、接入方店鋪ID 'cancel_reason' => '' ]; $res = $sfopenic->preCancelOrder($data);
$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);
$data = [ 'order_id' => 'xxxxxxxxxxxx', 'order_type' => 1 //1、順豐訂單號 2、商家訂單號 'shop_id' => 0, 'shop_type' => 1, //1、順豐店鋪ID 2、接入方店鋪ID ]; $res = $sfopenic->getOrderGratuityFee($data);
$data = [ 'order_id' => 'xxxxxxxxxxxx', 'order_type' => 1 //1、順豐訂單號 2、商家訂單號 'shop_id' => 0, //order_type=2時必傳shop_id與shop_type 'shop_type' => 1, //1、順豐店鋪ID 2、接入方店鋪ID ]; $res = $sfopenic->listOrderFeed($data);
$data = [ 'order_id' => 'xxxxxxxxxxxx', 'order_type' => 1 //1、順豐訂單號 2、商家訂單號 'shop_id' => 0, //order_type=2時必傳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時必傳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:百度坐標,2:高德坐標(默認值為2,下面的經緯度依賴這個坐標系,不傳默認高德) 'user_lng'=> '', //傳入用戶地址經緯度順豐側則不根據用戶地址解析 'user_lat'=> '', ]; $res = $sfopenic->changeOrder($data);
$data = [ 'order_id' => 'xxxxxxxxxxxx', 'order_type' => 1 //1、順豐訂單號 2、商家訂單號 'shop_id' => 0, //order_type=2時必傳shop_id與shop_type 'shop_type' => 1, //1、順豐店鋪ID 2、接入方店鋪ID ]; $res = $sfopenic->riderLatestPosition($data);
$data = [ 'order_id' => 'xxxxxxxxxxxx', 'order_type' => 1 //1、順豐訂單號 2、商家訂單號 'shop_id' => 0, //order_type=2時必傳shop_id與shop_type 'shop_type' => 1, //1、順豐店鋪ID 2、接入方店鋪ID ]; $res = $sfopenic->riderViewV2($data);
$data = [ 'order_id' => 'xxxxxxxxxxxx', 'order_type' => 1 //1、順豐訂單號 2、商家訂單號 'shop_id' => 0, 'shop_type' => 1, //1、順豐店鋪ID 2、接入方店鋪ID ]; $res = $sfopenic->getCallbackInfo($data);
$data = $sfopenic->getNotify(); . . . return $sfopenic->getNotifySuccessReply();
在laravel中使用
在 Laravel 中使用也是同樣的安裝方式,【】
使用下面的命令來導出配置文件
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 實例:
方法參數注入
. . . public function preCreateOrder(Sfopenic $sfopenic) { $res = $sfopenic->preCreateOrder($data); } . . .
服務名訪問
. . . public function preCreateOrder() { $res = app('sfopenic')->preCreateOrder($data); } . . .
以上是“在laravel中如何使用順豐同城配送的擴展包”這篇文章的所有內容,感謝各位的閱讀!希望分享的內容對大家有幫助,更多相關知識,歡迎關注億速云行業資訊頻道!
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。