公司項(xiàng)目需要用到順豐外賣,所以看了下有沒有現(xiàn)成的擴(kuò)展包可用,但是發(fā)現(xiàn)沒有,官方也沒有sdk,所以自己寫了一個(gè)包,省了不少工作量。
安裝
$ composer require ycstar/sfopenic -vvv
配置
在使用本擴(kuò)展之前,你需要去順豐同城開放平臺(tái)注冊(cè)賬號(hào),然后申請(qǐng)開發(fā)者ID,獲取相應(yīng)的配置
使用
use YcstarSfopenicSfopenic; $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,//物品個(gè)數(shù) 'product_type_num' => 1,//物品種類個(gè)數(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、順豐訂單號(hào) 2、商家訂單號(hào) '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、順豐訂單號(hào) 2、商家訂單號(hào) '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、順豐訂單號(hào) 2、商家訂單號(hào) '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、順豐訂單號(hào) 2、商家訂單號(hào) 'shop_id' => 0, 'shop_type' => 1, //1、順豐店鋪ID 2、接入方店鋪ID ]; $res = $sfopenic->getOrderGratuityFee($data);
訂單狀態(tài)流查詢
$data = [ 'order_id' => 'xxxxxxxxxxxx', 'order_type' => 1 //1、順豐訂單號(hào) 2、商家訂單號(hào) '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、順豐訂單號(hào) 2、商家訂單號(hào) '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、順豐訂單號(hào) 2、商家訂單號(hào) '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、順豐訂單號(hào) 2、商家訂單號(hào) '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)緯度依賴這個(gè)坐標(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、順豐訂單號(hào) 2、商家訂單號(hào) '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、順豐訂單號(hào) 2、商家訂單號(hào) '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、順豐訂單號(hào) 2、商家訂單號(hào) '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 中使用也是同樣的安裝方式,【推薦:《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
可以用兩種方式來獲取 YcstarSfopenicSfopenic 實(shí)例:
- 方法參數(shù)注入
. . . public function preCreateOrder(Sfopenic $sfopenic) { $res = $sfopenic->preCreateOrder($data); } . . .
- 服務(wù)名訪問
. . . public function preCreateOrder() { $res = app('sfopenic')->preCreateOrder($data); } . . .
相關(guān)推薦:laravel教程? ? ? ?
? 版權(quán)聲明
文章版權(quán)歸作者所有,未經(jīng)允許請(qǐng)勿轉(zhuǎn)載。
THE END
喜歡就支持一下吧
相關(guān)推薦