项目需要用到顺丰外卖,所以查了一下有没有现成的扩展包,发现没有,也没有官方的SDK,所以自己写了一个包,省了很多工作。
安装
<pre>$ composer require ycstar/sfopenic -vvv </pre>
配置:
使用本扩展前需要先到顺丰开放平台注册账号,然后申请开发者ID获取对应配置
使用:
<pre>
use Ycstar\Sfopenic\Sfopenic;
$config = [
‘host’ => ‘xxxxxxxxxxxx’,
‘dev_id’ => ‘xxxxxxxxxxxx’,
‘dev_key’ => ‘xxxxxxxxxxxx’
];
$sfopenic = new Sfopenic($config); </pre>
预创建订单
<pre>$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); </pre>
创建订单
<pre>$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); </pre>
取消订单
<pre>$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); </pre>
预取消订单
<pre>$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); </pre>
订单加小费
<pre>$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); </pre>
获取订单加小费信息
<pre>$data = [
‘order_id’ => ‘xxxxxxxxxxxx’,
‘order_type’ => 1 //1、顺丰订单号 2、商家订单号
‘shop_id’ => 0,
‘shop_type’ => 1, //1、顺丰店铺ID 2、接入方店铺ID
];
$res = $sfopenic->getOrderGratuityFee($data); </pre>
订单状态流查询
<pre>$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); </pre>
订单实时信息查询
<pre>$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); </pre>
催单
<pre>$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); </pre>
改单
<pre>$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); </pre>
获取配送员实时坐标接口
<pre>$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); </pre>
获取配送员轨迹H5
<pre>$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); </pre>
订单回调详情
<pre>$data = [
‘order_id’ => ‘xxxxxxxxxxxx’,
‘order_type’ => 1 //1、顺丰订单号 2、商家订单号
‘shop_id’ => 0,
‘shop_type’ => 1, //1、顺丰店铺ID 2、接入方店铺ID
];
$res = $sfopenic->getCallbackInfo($data); </pre>
获取回调数据及回复内容
<pre>$data = $sfopenic->getNotify();
.
.
.
return $sfopenic->getNotifySuccessReply(); </pre>
在laravel中使用
在 Laravel 中使用也是同样的安装方式,使用下面的命令来导出配置文件
php artisan vendor:publish –tag=”ycstar-sfopenic”
配置写在 config/sfopenic.php 中:
<pre>return [
‘host’ => env(‘SF_OPENIC_HOST’),
‘dev_id’ => env(‘SF_OPENIC_DEV_ID’),
‘dev_key’ => env(‘SF_OPENIC_DEV_KEY’)
]; </pre>
然后在 .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 实例:
方法参数注入
<pre>…
public function preCreateOrder(Sfopenic $sfopenic)
{
$res = $sfopenic->preCreateOrder($data);
}
…
服务名访问
…
public function preCreateOrder()
{
$res = app(‘sfopenic’)->preCreateOrder($data);
}
… </pre>
2.分享目的仅供大家学习和交流,您必须在下载后24小时内删除!
3.不得使用于非法商业用途,不得违反国家法律。否则后果自负!
4.本站提供的源码、模板、插件等其他资源,都不包含技术服务请大家谅解!
5.如有链接无法下载或失效,请联系管理员处理!
6.本站资源售价只是赞助,收取费用仅维持本站的日常运营所需!