RegisterApiTest.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. <?php
  2. namespace Tests\Services\LogisticYDService;
  3. use App\OrderPackage;
  4. use App\Services\LogisticYDService;
  5. use Illuminate\Support\Facades\Http;
  6. use Tests\TestCase;
  7. class RegisterApiTest extends TestCase
  8. {
  9. /**
  10. * @var $service LogisticYDService
  11. */
  12. private $service;
  13. protected function setUp(): void
  14. {
  15. parent::setUp(); // TODO: Change the autogenerated stub
  16. $this->service = app('LogisticYDService');
  17. }
  18. /**
  19. * @test
  20. */
  21. public function registerApiTest()
  22. {
  23. $this->app_key = config('api_logistic.YD.test.app-key', '999999');
  24. $this->app_secret = config('api_logistic.YD.test.app-secret', '04d4ad40eeec11e9bad2d962f53dda9d');
  25. $this->url = config('api_logistic.YD.test.register.url');
  26. $body = [
  27. "orders" => [
  28. [
  29. "orderid" => "9987765544332",
  30. "mailno" => "3309876541228",
  31. "receiver" => [
  32. "address" => "青浦区盈港东路6679号",
  33. "city" => "上海市",
  34. "county" => "青浦区",
  35. "mobile" => "0553-9876542",
  36. "name" => "李四",
  37. "phone" => 17601205970,
  38. "province" => "上海市"
  39. ],
  40. "sender" => [
  41. "address" => "盈港东路 7766 号",
  42. "city" => "上海市",
  43. "county" => "青浦区",
  44. "mobile" => "0553-9876542",
  45. "name" => "张三",
  46. "phone" => 17601205970,
  47. "province" => "上海市"
  48. ],
  49. ],
  50. ]
  51. ];
  52. $sign = md5(json_encode($body, JSON_UNESCAPED_UNICODE) . '_' . $this->app_secret);
  53. $headers = [
  54. 'app-key' => $this->app_key,
  55. 'sign' => $sign,
  56. 'req-time' => now()->timestamp,
  57. "Content-Type" => "application/json"
  58. ];
  59. $response = Http::withHeaders($headers)->withBody(json_encode($body,JSON_UNESCAPED_UNICODE),'application/json')->post($this->url);
  60. $this->assertNotEmpty($response);
  61. }
  62. /**
  63. * @test
  64. */
  65. // public function registerApiTest2()
  66. // {
  67. // $this->service->registerApi(['75464485214976','75464484634676']);
  68. // }
  69. /**
  70. * @test
  71. */
  72. // public function prod_test()
  73. // {
  74. // $result = $this->service->registerApi(['4314519335027']);
  75. // $this->assertEquals('0000', $result->code);
  76. // }
  77. }