BaseOrder.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. <?php
  2. namespace crmeb\services\easywechat\orderShipping;
  3. use crmeb\exceptions\AdminException;
  4. use EasyWeChat\Core\AbstractAPI;
  5. use EasyWeChat\Core\AccessToken;
  6. use EasyWeChat\Support\Collection;
  7. class BaseOrder extends AbstractAPI
  8. {
  9. public $config;
  10. public $accessToken;
  11. const BASE_API = 'https://api.weixin.qq.com/';
  12. const ORDER = 'wxa/sec/order/';
  13. const EXPRESS = 'cgi-bin/express/delivery/open_msg/';
  14. const PATH = '/pages/goods/order_details/index';
  15. public function __construct(AccessToken $accessToken, $config)
  16. {
  17. parent::__construct($accessToken);
  18. $this->config = $config;
  19. $this->accessToken = $accessToken;
  20. }
  21. private function resultHandle(Collection $result)
  22. {
  23. if (empty($result)) {
  24. throw new AdminException('微信接口返回异常');
  25. }
  26. $res = $result->toArray();
  27. if ($res['errcode'] == 0) {
  28. return $res;
  29. } else {
  30. throw new AdminException("微信接口异常:code = {$res['errcode']} msg = {$res['errmsg']}");
  31. }
  32. }
  33. /**
  34. * 发货
  35. * @param $params
  36. * @return array
  37. * @throws \EasyWeChat\Core\Exceptions\HttpException
  38. *
  39. * @date 2023/05/09
  40. * @author yyw
  41. */
  42. public function shipping($params)
  43. {
  44. return $this->resultHandle($this->parseJSON('POST', [self::BASE_API . self::ORDER . 'upload_shipping_info', json_encode($params, JSON_UNESCAPED_UNICODE)]));
  45. }
  46. /**
  47. * 合单
  48. * @param $params
  49. * @return array
  50. * @throws \EasyWeChat\Core\Exceptions\HttpException
  51. *
  52. * @date 2023/05/09
  53. * @author yyw
  54. */
  55. public function combinedShipping($params)
  56. {
  57. return $this->resultHandle($this->parseJSON('POST', [self::BASE_API . self::ORDER . 'upload_combined_shipping_info', json_encode($params)]));
  58. }
  59. /**
  60. * 签收消息提醒
  61. * @param $params
  62. * @return array
  63. * @throws \EasyWeChat\Core\Exceptions\HttpException
  64. *
  65. * @date 2023/05/09
  66. * @author yyw
  67. */
  68. public function notifyConfirm($params)
  69. {
  70. return $this->resultHandle($this->parseJSON('POST', [self::BASE_API . self::ORDER . 'notify_confirm_receive', json_encode($params)]));
  71. }
  72. /**
  73. * 查询小程序是否已开通发货信息管理服务
  74. * @return array
  75. * @throws \EasyWeChat\Core\Exceptions\HttpException
  76. *
  77. * @date 2023/05/09
  78. * @author yyw
  79. */
  80. public function isManaged()
  81. {
  82. $params = [
  83. 'appid' => $this->config['config']['mini_program']['app_id']
  84. ];
  85. return $this->resultHandle($this->parseJSON('POST', [self::BASE_API . self::ORDER . 'is_trade_managed', json_encode($params)]));
  86. }
  87. /**
  88. * 设置跳转连接
  89. * @param $path
  90. * @return array
  91. * @throws \EasyWeChat\Core\Exceptions\HttpException
  92. *
  93. * @date 2023/05/10
  94. * @author yyw
  95. */
  96. public function setMesJumpPath($path)
  97. {
  98. $params = [
  99. 'path' => $path
  100. ];
  101. return $this->resultHandle($this->parseJSON('POST', [self::BASE_API . self::ORDER . 'set_msg_jump_path', json_encode($params)]));
  102. }
  103. /**
  104. * 获取运力id列表get_delivery_list
  105. * @return array
  106. * @throws \EasyWeChat\Core\Exceptions\HttpException
  107. *
  108. * @date 2023/05/09
  109. * @author yyw
  110. */
  111. public function getDeliveryList()
  112. {
  113. return $this->resultHandle($this->parseJSON('POST', [self::BASE_API . self::EXPRESS . 'get_delivery_list', "{}"]));
  114. }
  115. }