Express.php 4.3 KB

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