Home > PHP Framework > Laravel > body text

Share an expansion package for SF Express intra-city delivery and use it in laravel

藏色散人
Release: 2021-08-12 09:03:07
forward
2068 people have browsed it

The company's project needs to use SF takeaway, so I have seen whether there are ready -made expansion packs available.

Installation

$ composer require ycstar/sfopenic -vvv
Copy after login

Configuration

Before using this extension, you need to register an account on the SF Express City Open Platform, and then Apply for a developer ID and obtain the corresponding configuration

Use

    use Ycstar\Sfopenic\Sfopenic;

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

    $sfopenic = new Sfopenic($config);
Copy after login

Pre-create an order

    $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);
Copy after login

Create order

    $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);
Copy after login

Cancel order

    $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);
Copy after login

Pre-cancel order

    $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);
Copy after login

Add tip to order

    $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);
Copy after login

Get order plus tip information

    $data = [
        'order_id' => 'xxxxxxxxxxxx',
        'order_type' => 1 //1、顺丰订单号 2、商家订单号
        'shop_id' => 0,
        'shop_type' => 1, //1、顺丰店铺ID 2、接入方店铺ID
    ];

    $res = $sfopenic->getOrderGratuityFee($data);
Copy after login

Order status flow query

    $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);
Copy after login

Order real-time Information Query

    $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);
Copy after login

Remind Order

    $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);
Copy after login

Change Order

    $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);
Copy after login

Get the real-time coordinates of the delivery person Interface

    $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);
Copy after login

Get delivery person track H5

    $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);
Copy after login

Order callback details

    $data = [
        'order_id' => 'xxxxxxxxxxxx',
        'order_type' => 1 //1、顺丰订单号 2、商家订单号
        'shop_id' => 0,
        'shop_type' => 1, //1、顺丰店铺ID 2、接入方店铺ID
    ];

    $res = $sfopenic->getCallbackInfo($data);
Copy after login

Get callback Data and reply content

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

Used in laravel

The same installation method is used in Laravel, [Recommended: " laravel tutorial》]

Use the following command to export the configuration file

php artisan vendor:publish --tag="ycstar-sfopenic"
Copy after login

The configuration is written in config/sfopenic.php:

    return [

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

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

        'dev_key' => env('SF_OPENIC_DEV_KEY')

      ];
Copy after login

Then configure SF_OPENIC_HOST, SF_OPENIC_DEV_ID, SF_OPENIC_DEV_KEY in .env:

    SF_OPENIC_HOST = xxxxxxxxxxxx    
    SF_OPENIC_DEV_ID = xxxxxxxxxxxx    
    SF_OPENIC_DEV_KEY = xxxxxxxxxxxx
Copy after login

You can obtain the Ycstar\Sfopenic\Sfopenic instance in two ways:

  • Method parameter injection
      .
      .
      .
      public function preCreateOrder(Sfopenic $sfopenic)
      {
          $res = $sfopenic->preCreateOrder($data);
      }
      .
      .
      .
    Copy after login
  • Service name access
      .
      .
      .
      public function preCreateOrder()
      {
          $res = app('sfopenic')->preCreateOrder($data);
      }
      .
      .
      .
    Copy after login
Related recommendations:The latest five Laravel video tutorials

The above is the detailed content of Share an expansion package for SF Express intra-city delivery and use it in laravel. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:learnku.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template