123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130 |
- <?php
- namespace crmeb\services\wechat\orderShipping;
- use crmeb\exceptions\AdminException;
- use crmeb\services\wechat\config\MiniProgramConfig;
- use EasyWeChat\Kernel\BaseClient as EasyWeChatBaseClient;
- /**
- * Class BaseClient
- * @package crmeb\services\wechat\orderShipping
- */
- class BaseClient extends EasyWeChatBaseClient
- {
- public $config;
- public $accessToken;
- const BASE_API = 'https://api.weixin.qq.com/';
- const ORDER = 'wxa/sec/order/';
- const EXPRESS = 'cgi-bin/express/delivery/open_msg/';
- const PATH = '/pages/goods/order_details/index';
- /**
- * @param $result
- * @return mixed
- */
- private function resultHandle($result)
- {
- if (empty($result)) {
- throw new AdminException('微信接口返回异常');
- }
- if ($result['errcode'] == 0) {
- return $result;
- } else {
- throw new AdminException("微信接口异常:code = {$result['errcode']} msg = {$result['errmsg']}");
- }
- }
- /**
- * 发货
- * @param $params
- * @return array
- * @throws \EasyWeChat\Core\Exceptions\HttpException
- *
- *
- */
- public function shipping($params)
- {
- return $this->resultHandle($this->httpPostJson(self::ORDER . 'upload_shipping_info', $params));
- }
- /**
- * 合单
- * @param $params
- * @return array
- * @throws \EasyWeChat\Core\Exceptions\HttpException
- *
- *
- */
- public function combinedShipping($params)
- {
- return $this->resultHandle($this->httpPostJson(self::ORDER . 'upload_combined_shipping_info', $params));
- }
- /**
- * 签收消息提醒
- * @param $params
- * @return array
- * @throws \EasyWeChat\Core\Exceptions\HttpException
- *
- *
- */
- public function notifyConfirm($params)
- {
- return $this->resultHandle($this->httpPostJson(self::ORDER . 'notify_confirm_receive', $params));
- }
- /**
- * 查询小程序是否已开通发货信息管理服务
- * @return array
- * @throws \EasyWeChat\Core\Exceptions\HttpException
- *
- *
- */
- public function isManaged()
- {
- /** @var MiniProgramConfig $make */
- $make = app()->make(MiniProgramConfig::class);
- $params = [
- 'appid' => $make->get('appId')
- ];
- return $this->resultHandle($this->httpPostJson(self::ORDER . 'is_trade_managed', $params));
- }
- /**
- * 设置跳转连接
- * @param $path
- * @return array
- * @throws \EasyWeChat\Core\Exceptions\HttpException
- *
- *
- */
- public function setMesJumpPath($path)
- {
- $params = [
- 'path' => $path
- ];
- return $this->resultHandle($this->httpPostJson(self::ORDER . 'set_msg_jump_path', $params));
- }
- /**
- * 获取运力id列表get_delivery_list
- * @return array
- * @throws \EasyWeChat\Core\Exceptions\HttpException
- *
- *
- */
- public function getDeliveryList()
- {
- return $this->resultHandle($this->httpPostJson(self::EXPRESS . 'get_delivery_list', []));
- }
- }
|