ソースを参照

丰桥API测试

ANG YU 5 年 前
コミット
25d1670313

+ 29 - 0
app/Providers/LogisticProvider.php

@@ -0,0 +1,29 @@
+<?php
+
+namespace App\Providers;
+
+use Illuminate\Support\ServiceProvider;
+use \Illuminate\Contracts\Support\DeferrableProvider;
+
+class LogisticProvider extends ServiceProvider implements DeferrableProvider
+{
+    /**
+     * Register services.
+     *
+     * @return void
+     */
+    public function register()
+    {
+        
+    }
+
+    /**
+     * Bootstrap services.
+     *
+     * @return void
+     */
+    public function boot()
+    {
+        //
+    }
+}

+ 34 - 0
app/Services/LogisticQiaoSFService.php

@@ -0,0 +1,34 @@
+<?php
+
+
+namespace App\Services;
+
+
+use Exception;
+use Illuminate\Support\Facades\Http;
+
+class LogisticQiaoSFService
+{
+    public function get()
+    {
+        $url = config('api_logistic.SF.url');
+        $head = config('api_logistic.SF.head');
+        $checkWord = config('api_logistic.SF.checkWord');
+        $xml = <<<xml
+<?xml version="1.0" encoding="utf-8" ?>
+    <Request service='RouteService' lang='zh-CN'>
+    <Head>$head</Head>
+    <Body>
+    <RouteRequest
+    tracking_type='1'
+    method_type='1'
+    tracking_number='XJFS_071100251'/>
+    </Body>
+    </Request>
+xml;
+        $checkingJson=$xml.$checkWord;
+        $verifyCode=base64_encode(md5($checkingJson,true));
+        $response = Http::withHeaders(['Content-Type'=>'text/xml'])->get($url, ['xml' => $xml, 'verifyCode' => $verifyCode]);
+        return $response->body();
+    }
+}

+ 8 - 0
config/api_logistic.php

@@ -0,0 +1,8 @@
+<?php
+return [
+    'SF' => [
+        'url' =>  'https://sfapi-sbox.sf-express.com/sfexpressService',
+        'head' =>  'BSGYLGL',
+        'checkWord' =>  'DcauTQEavq5qqpFaYmltzR7gzVCTjvtz',
+    ],
+];

+ 27 - 0
tests/Services/LogisticQiaoSFService/LogisticQiaoSFServiceTest.php

@@ -0,0 +1,27 @@
+<?php
+
+namespace LogisticQiaoSFService;
+
+use App\Services\LogisticQiaoSFService;
+use Tests\TestCase;
+
+class LogisticQiaoSFServiceTest extends TestCase
+{
+    protected $logisticQiaoSFService;
+
+    protected function setUp(): void
+    {
+        parent::setUp(); // TODO: Change the autogenerated stub
+        $this->logisticQiaoSFService = new LogisticQiaoSFService();
+    }
+
+
+    /**
+     * @test
+     */
+    public function testGet()
+    {
+        $response = $this->logisticQiaoSFService->get([]);
+        dd($response);
+    }
+}