BaseClient.php 3.0 KB

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