存客宝应用接口初始化

This commit is contained in:
Ghost
2026-01-05 10:25:32 +08:00
parent fa37227954
commit 02797ba50a
414 changed files with 85530 additions and 75 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,67 @@
<?php
namespace WeChatDeviceApi\Contracts;
interface WeChatServiceInterface
{
/**
* 添加好友
* @param string $deviceId 设备ID
* @param string $targetWxId 目标微信ID
* @return bool 是否成功
* @throws \WeChatDeviceApi\Exceptions\ApiException
*/
public function addFriend(string $deviceId, string $targetWxId): bool;
/**
* 朋友圈点赞
* @param string $deviceId 设备ID
* @param string $momentId 朋友圈ID
* @return bool 是否成功
*/
public function likeMoment(string $deviceId, string $momentId): bool;
/**
* 获取群列表
* @param string $deviceId 设备ID
* @return array 群信息列表
*/
public function getGroupList(string $wxId): array;
/**
* 获取好友列表
* @param string $deviceId 设备ID
* @return array 好友信息列表
*/
public function getFriendList(string $deviceId): array;
/**
* 获取设备信息
* @param string $deviceId 设备ID
* @return array 设备详情
*/
public function getDeviceInfo(string $deviceId): array;
/**
* 绑定设备到公司
* @param string $deviceId 设备ID
* @param string $companyId 公司ID
* @return bool 是否成功
*/
public function bindDeviceToCompany(string $deviceId, string $companyId): bool;
/**
* 获取群成员列表
* @param string $deviceId 设备ID
* @param string $chatroomId 群ID
* @return array 群成员列表
*/
public function getChatroomMemberList(string $deviceId, string $chatroomId): array;
// 获取指定微信的朋友圈内容/列表
public function getMomentList(string $deviceId, string $wxId): array;
// 发送微信朋友圈
public function sendMoment(string $deviceId, string $wxId, string $moment): bool;
// ... 其他方法定义
}

View File

@@ -0,0 +1,7 @@
<?php
namespace WeChatDeviceApi\Exceptions;
class ApiException extends \RuntimeException // 或者 \Exception
{
// 可以添加更多上下文信息
}

View File

@@ -0,0 +1,94 @@
<?php
namespace WeChatDeviceApi;
use think\facade\Config;
use WeChatDeviceApi\Contracts\WeChatServiceInterface;
class Manager
{
/**
* @var array 适配器实例缓存
*/
protected $adapters = [];
/**
* @var array 配置
*/
protected $config;
public function __construct(array $config = null)
{
$this->config = $config ?: Config::get('wechat_device_api.');
if (empty($this->config)) {
throw new \InvalidArgumentException("WeChat Device API configuration not found.");
}
}
/**
* 获取指定的适配器实例
*
* @param string|null $name 适配器名称 (例如 'vendor_a', 'vendor_b')null 则使用默认
* @return WeChatServiceInterface
* @throws \InvalidArgumentException
*/
public function adapter(string $name = null): WeChatServiceInterface
{
$name = $name ?: $this->getDefaultAdapterName();
if (!isset($this->config['adapters'][$name])) {
throw new \InvalidArgumentException("Adapter [{$name}] configuration not found.");
}
if (!isset($this->adapters[$name])) {
$this->adapters[$name] = $this->createAdapter($name);
}
return $this->adapters[$name];
}
/**
* 创建适配器实例
*
* @param string $name
* @return WeChatServiceInterface
*/
protected function createAdapter(string $name): WeChatServiceInterface
{
$adapterConfig = $this->config['adapters'][$name];
$driverClass = $adapterConfig['driver'] ?? null;
if (!$driverClass || !class_exists($driverClass)) {
throw new \InvalidArgumentException("Driver class for adapter [{$name}] not found or not specified.");
}
$adapterInstance = new $driverClass($adapterConfig);
if (!$adapterInstance instanceof WeChatServiceInterface) {
throw new \LogicException("Driver class [{$driverClass}] must implement WeChatServiceInterface.");
}
return $adapterInstance;
}
/**
* 获取默认适配器名称
*
* @return string
*/
public function getDefaultAdapterName(): string
{
return $this->config['default_adapter'] ?? '';
}
/**
* 动态调用默认适配器的方法
*
* @param string $method
* @param array $parameters
* @return mixed
*/
public function __call(string $method, array $parameters)
{
return $this->adapter()->{$method}(...$parameters);
}
}