RegisterApiTest.php 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. <?php
  2. namespace 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. dump([
  61. 'url' => $this->url,
  62. 'headers' => $headers,
  63. 'body' => $body,
  64. 'response' => $response->body(),
  65. ]);
  66. }
  67. /**
  68. * @test
  69. */
  70. public function registerApiTest2()
  71. {
  72. $this->service->registerApi(['75464485214976','75464484634676']);
  73. }
  74. /**
  75. * @test
  76. */
  77. public function prod_test()
  78. {
  79. $result = $this->service->registerApi(['4314519335027']);
  80. $this->assertEquals('0000', $result->code);
  81. }
  82. }