Rumah > rangka kerja php > Laravel > teks badan

Kongsi pakej pengembangan untuk penghantaran dalam bandar SF Express dan gunakannya dalam laravel

藏色散人
Lepaskan: 2021-08-12 09:03:07
ke hadapan
2035 orang telah melayarinya
Projek syarikat perlu menggunakan SF takeaway, jadi saya telah melihat sama ada terdapat pakej pengembangan siap sedia tersedia.

Pemasangan

$ composer require ycstar/sfopenic -vvv
Salin selepas log masuk

Konfigurasi

Sebelum menggunakan sambungan ini, anda perlu mendaftar akaun di SF Express platform terbuka dalam bandar , kemudian mohon ID pembangun dan dapatkan konfigurasi yang sepadan

Gunakan

    use Ycstar\Sfopenic\Sfopenic;

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

    $sfopenic = new Sfopenic($config);
Salin selepas log masuk

untuk pra-membuat pesanan

    $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);
Salin selepas log masuk

Buat pesanan

    $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);
Salin selepas log masuk

Batalkan pesanan

    $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);
Salin selepas log masuk

Pra-batalkan pesanan

    $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);
Salin selepas log masuk

Pesan tambah tip

    $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);
Salin selepas log masuk

Dapatkan pesanan tambah maklumat tip

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

    $res = $sfopenic->getOrderGratuityFee($data);
Salin selepas log masuk

Pertanyaan aliran status pesanan

    $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);
Salin selepas log masuk

Pesan pertanyaan maklumat masa nyata

    $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);
Salin selepas log masuk

Peringatan

    $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);
Salin selepas log masuk

Tukar pesanan

    $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);
Salin selepas log masuk

Dapatkan koordinat masa nyata antara muka orang penghantaran

    $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);
Salin selepas log masuk

Dapatkan trek orang penghantar 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);
Salin selepas log masuk

Pesan butiran panggil balik

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

    $res = $sfopenic->getCallbackInfo($data);
Salin selepas log masuk

Dapatkan data panggilan balik dan respons kandungan

    $data = $sfopenic->getNotify();
    .
    .
    .
    return $sfopenic->getNotifySuccessReply();
Salin selepas log masuk

Menggunakan dalam laravel

Kaedah pemasangan yang sama digunakan dalam Laravel, [Disyorkan: "

tutorial laravel"]

Gunakan arahan berikut untuk mengeksport fail konfigurasi

php artisan vendor:publish --tag="ycstar-sfopenic"
Salin selepas log masuk
Konfigurasi ditulis dalam config/sfopenic.php:

    return [

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

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

        'dev_key' => env('SF_OPENIC_DEV_KEY')

      ];
Salin selepas log masuk
Kemudian konfigurasikan SF_OPENIC_HOST, SF_OPENIC_DEV_ID, SF_OPENIC_DEV_KEY dalam .env:

    SF_OPENIC_HOST = xxxxxxxxxxxx    
    SF_OPENIC_DEV_ID = xxxxxxxxxxxx    
    SF_OPENIC_DEV_KEY = xxxxxxxxxxxx
Salin selepas log masuk
Anda boleh mendapatkan contoh YcstarSfopenicSfopenic dalam dua cara:

    Akses nama perkhidmatan
  •   .
      .
      .
      public function preCreateOrder(Sfopenic $sfopenic)
      {
          $res = $sfopenic->preCreateOrder($data);
      }
      .
      .
      .
    Salin selepas log masuk
  • Pengesyoran berkaitan:
      .
      .
      .
      public function preCreateOrder()
      {
          $res = app('sfopenic')->preCreateOrder($data);
      }
      .
      .
      .
    Salin selepas log masuk
    Lima tutorial video Laravel terbaharu
 

Atas ialah kandungan terperinci Kongsi pakej pengembangan untuk penghantaran dalam bandar SF Express dan gunakannya dalam laravel. Untuk maklumat lanjut, sila ikut artikel berkaitan lain di laman web China PHP!

Label berkaitan:
sumber:learnku.com
Kenyataan Laman Web ini
Kandungan artikel ini disumbangkan secara sukarela oleh netizen, dan hak cipta adalah milik pengarang asal. Laman web ini tidak memikul tanggungjawab undang-undang yang sepadan. Jika anda menemui sebarang kandungan yang disyaki plagiarisme atau pelanggaran, sila hubungi admin@php.cn
Tutorial Popular
Lagi>
Muat turun terkini
Lagi>
kesan web
Kod sumber laman web
Bahan laman web
Templat hujung hadapan
Tentang kita Penafian Sitemap
Laman web PHP Cina:Latihan PHP dalam talian kebajikan awam,Bantu pelajar PHP berkembang dengan cepat!