Express.php 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. <?php
  2. /**
  3. * Created by PhpStorm
  4. * User: song
  5. * Date: 2020/9/29/0029
  6. * Time: 16:45
  7. */
  8. namespace crmeb\services\express\storage;
  9. use crmeb\basic\BaseExpress;
  10. use crmeb\exceptions\ApiException;
  11. /**
  12. * Class Express
  13. * @package crmeb\services\express\storage
  14. */
  15. class Express extends BaseExpress
  16. {
  17. /**
  18. * 注册服务
  19. */
  20. const EXPRESS_OPEN = 'expr/open';
  21. /**
  22. * 电子面单模版
  23. */
  24. const EXPRESS_TEMP = 'expr/temp';
  25. /**
  26. * 快递公司
  27. */
  28. const EXPRESS_LIST = 'expr/express';
  29. /**
  30. * 快递查询
  31. */
  32. const EXPRESS_QUERY = 'expr/query';
  33. /**
  34. * 面单打印
  35. */
  36. const EXPRESS_DUMP = 'expr/dump';
  37. /** 初始化
  38. * @param array $config
  39. * @return mixed|void
  40. */
  41. protected function initialize(array $config = [])
  42. {
  43. parent::initialize($config); // TODO: Change the autogenerated stub
  44. }
  45. /**
  46. * 开通物流服务
  47. * @return bool|mixed
  48. */
  49. public function open()
  50. {
  51. return $this->accessToken->httpRequest(self::EXPRESS_OPEN, []);
  52. }
  53. /**
  54. * 获取电子面单模版
  55. * @param $com 快递公司编号
  56. * @param int $page
  57. * @param int $limit
  58. * @return bool|mixed
  59. */
  60. public function temp($com, $page = 0, $limit = 10)
  61. {
  62. $param = [
  63. 'com' => $com,
  64. 'page' => $page,
  65. 'limit' => $limit
  66. ];
  67. return $this->accessToken->httpRequest(self::EXPRESS_TEMP, $param);
  68. }
  69. /**
  70. * 获取物流公司列表
  71. * @param int $type 快递类型:1,国内运输商;2,国际运输商;3,国际邮政
  72. * @return bool|mixed
  73. */
  74. public function express(int $type = 1, int $page = 0, int $limit = 10)
  75. {
  76. $param = [
  77. 'type' => $type,
  78. 'page' => $page,
  79. 'limit' => $limit
  80. ];
  81. return $this->accessToken->httpRequest(self::EXPRESS_LIST, $param);
  82. }
  83. /**
  84. * 查询物流信息
  85. * @param $com
  86. * @param $num
  87. * @return bool|mixed
  88. * @return 是否签收 ischeck
  89. * @return 物流状态:status 0在途,1揽收,2疑难,3签收,4退签,5派件,6退回,7转单,10待清关,11清关中,12已清关,13清关异常,14收件人拒签
  90. * @return 物流详情 content
  91. */
  92. public function query($com, $num)
  93. {
  94. $param = [
  95. 'com' => $com,
  96. 'num' => $num
  97. ];
  98. return $this->accessToken->httpRequest(self::EXPRESS_QUERY, $param);
  99. }
  100. /**
  101. * 电子面单打印
  102. * @param array $data 必需参数: com(快递公司编码)、to_name(寄件人)、to_tel(寄件人电话)、to_addr(寄件人详细地址)、from_name(收件人)、from_tel(收件人电话)、from_addr(收件人地址)、temp_id(电子面单模板ID)、siid(云打印机编号)、count(商品数量)
  103. * @return bool|mixed
  104. */
  105. public function dump($data)
  106. {
  107. $param = $data;
  108. $param['com'] = $data['com'] ?? '';
  109. if (!$param['com']) throw new ApiException('快递公司编码缺失');
  110. $param['to_name'] = $data['to_name'] ?? '';
  111. $param['to_tel'] = $data['to_tel'] ?? '';
  112. $param['to_addr'] = $data['to_addr'] ?? '';
  113. if (!$param['to_addr'] || !$param['to_tel'] || !$param['to_name']) throw new ApiException('寄件人信息缺失');
  114. $param['from_name'] = $data['from_name'] ?? '';
  115. $param['from_tel'] = $data['from_tel'] ?? '';
  116. $param['from_addr'] = $data['from_addr'] ?? '';
  117. if (!$param['from_name'] || !$param['from_tel'] || !$param['from_addr']) throw new ApiException('收件人信息缺失');
  118. $param['temp_id'] = $data['temp_id'] ?? '';
  119. if (!$param['temp_id']) throw new ApiException('电子面单模板ID缺失');
  120. $param['siid'] = $data['siid'] ?? '';
  121. if (!$param['siid']) throw new ApiException('云打印机编号缺失');
  122. $param['count'] = $data['count'] ?? '';
  123. if (!$param['count']) throw new ApiException('商品数量缺失');
  124. $param['cargo'] = $data['cargo'] ?? '';
  125. $param['partner_id'] = $data['partner_id'] ?? 0;
  126. $param['partner_key'] = $data['partner_key'] ?? '';
  127. $param['net'] = $data['net'] ?? '';
  128. return $this->accessToken->httpRequest(self::EXPRESS_DUMP, $param);
  129. }
  130. }