名目需要用到顺丰外卖,以是看了下有无现成的扩年夜包可用,然而发明不,民间也不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//一、顺丰定单号二、商家定单号
'shop_id'=>0,//order_type=2时必传shop_id与shop_type
'shop_type'=>1,//一、顺丰店铺ID二、接入方店铺ID
'cancel_code'=>313,//不填时默认cancel_code=313,cancel_reason=商家发起废除了
'cancel_reason'=>''
];$res=$sfopenic->cancelOrder($data);
预废除了定单
$data = [
'order_id'=>'xxxxxxxxxxxx',
'order_type'=>1//一、顺丰定单号二、商家定单号
'shop_id'=>0,//order_type=2时必传shop_id与shop_type
'shop_type'=>1,//一、顺丰店铺ID二、接入方店铺ID
'cancel_reason'=>''
];$res=$sfopenic->preCancelOrder($data);
定单加小费
$data = [
'order_id'=>'xxxxxxxxxxxx',
'order_type'=>1//一、顺丰定单号二、商家定单号
'shop_id'=>0,
'shop_type'=>1,//一、顺丰店铺ID二、接入方店铺ID
'gratuity_fee'=>0
];$res=$sfopenic->addOrderGratuityFee($data);
获取定单加小费信息
$data = [
'order_id'=>'xxxxxxxxxxxx',
'order_type'=>1//一、顺丰定单号二、商家定单号
'shop_id'=>0,
'shop_type'=>1,//一、顺丰店铺ID二、接入方店铺ID
];$res=$sfopenic->getOrderGratuityFee($data);
定单状态流盘问
$data = [
'order_id'=>'xxxxxxxxxxxx',
'order_type'=>1//一、顺丰定单号二、商家定单号
'shop_id'=>0,//order_type=2时必传shop_id与shop_type
'shop_type'=>1,//一、顺丰店铺ID二、接入方店铺ID
];$res=$sfopenic->listOrderFeed($data);
定单实时信息盘问
$data = [
'order_id'=>'xxxxxxxxxxxx',
'order_type'=>1//一、顺丰定单号二、商家定单号
'shop_id'=>0,//order_type=2时必传shop_id与shop_type
'shop_type'=>1,//一、顺丰店铺ID二、接入方店铺ID
];$res=$sfopenic->getOrderStatus($data);
催单
$data = [
'order_id'=>'xxxxxxxxxxxx',
'order_type'=>1//一、顺丰定单号二、商家定单号
'shop_id'=>0,//order_type=2时必传shop_id与shop_type
'shop_type'=>1,//一、顺丰店铺ID二、接入方店铺ID
];$res=$sfopenic->reminderOrder($data);
改单
$data = [
'order_id'=>'xxxxxxxxxxxx',
'order_type'=>1//一、顺丰定单号二、商家定单号
'shop_id'=>0,
'shop_type'=>1,//一、顺丰店铺ID二、接入方店铺ID
'user_name'=>'',
'user_phone'=>'',
'user_address'=>'',
'lbs_type'=>2,//1:baidu坐标,2:高德坐标(默认值为2,下面的经纬度依靠这个坐标系,不传默认高德)
'user_lng'=>'',//传入用户所在经纬度顺丰侧则不依据用户所在剖析
'user_lat'=>'',
];$res=$sfopenic->changeOrder($data);
获取配送员实时坐标接口
$data = [
'order_id'=>'xxxxxxxxxxxx',
'order_type'=>1//一、顺丰定单号二、商家定单号
'shop_id'=>0,//order_type=2时必传shop_id与shop_type
'shop_type'=>1,//一、顺丰店铺ID二、接入方店铺ID
];$res=$sfopenic->riderLatestPosition($data);
获取配送员轨迹H5
$data = [
'order_id'=>'xxxxxxxxxxxx',
'order_type'=>1//一、顺丰定单号二、商家定单号
'shop_id'=>0,//order_type=2时必传shop_id与shop_type
'shop_type'=>1,//一、顺丰店铺ID二、接入方店铺ID
];$res=$sfopenic->riderViewV2($data);
定单回调详情
$data = [
'order_id'=>'xxxxxxxxxxxx',
'order_type'=>1//一、顺丰定单号二、商家定单号
'shop_id'=>0,
'shop_type'=>1,//一、顺丰店铺ID二、接入方店铺ID
];$res=$sfopenic->getCallbackInfo($data);
获取回调数据及复原内容
$data = $sfopenic->getNotify();
.
.
.
return$sfopenic->getNotifySuccessReply();
在laravel中应用
在Laravel中应用也是异样的布置形式,应用下面的命令来导出配置文件
phpartisanvendor: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')
];
SF_OPENIC_HOST=xxxxxxxxxxxx
SF_OPENIC_DEV_ID=xxxxxxxxxxxx
SF_OPENIC_DEV_KEY=xxxxxxxxxxxx
能够用两种形式来获取Ycstar\Sfopenic\Sfopenic实例:
方法参数注入
...
publicfunctionpreCreateOrder(Sfopenic$sfopenic)
{
$res=$sfopenic->preCreateOrder($data);
}
...效劳名访问
...
publicfunctionpreCreateOrder()
{
$res=app('sfopenic')->preCreateOrder($data);
}
...
本文链接:https://addon.ciliseo.com/yi-ge-shun-feng-tong-cheng-pei-song-de-kuo-zhan-bao-bing-zai-laravel.html
网友评论