SDK是用于实现与软件平台连接、调用的类,被需要的适配器引用并实例化。实例化时,会传入基本的连接参数给SDK构造方法。
namespace Adapter\PlatformName\SDK;
class PlatformNameSDK
{
protected $connectorId = 'connectorId';
protected $env = '';
protected $host = '';
protected $login = ['appKey' => 'xxxxxx', 'appSecret' => 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxx',];
protected $token = null;
protected $client = \GuzzleHttp\Client::class;
public function __construct($connectorId, $params, string $env = '')
{
$this->connectorId = $connectorId;
$this->host = $params['host'];
$this->login = $params;
$this->env = $env;
$this->client = new \GuzzleHttp\Client();
}
public function invoke(string $api, $params = [], $method = 'POST')
{
}
public function connection()
{
}
}
实现SDK->connection(),连接到目标平台的方法,主要针对需要token鉴权的平台,用于管理token。
public function connection()
{
$cacheKey = $this->connectorId . $this->env;
$token = Cache::get($cacheKey);
if ($token) {
$this->token = $token;
return ['status' => true, 'token' => $token];
}
$url = $this->host . '/open-apis/auth/v3/tenant_access_token/internal';
$response = $this->client->post($url, ['form_params' => $this->login, 'headers' => ['Content-Type' => 'application/json; charset=utf-8',]]);
$body = $response->getBody();
$arr = json_decode((string)$body, true);
if ($arr['code'] == 0) {
$this->token = $arr['tenant_access_token'];
Cache::put($cacheKey, $this->token, $arr['expire'] - 100);
}
return $arr;
}
实现SDK->invoke(),实现具体接口调用方法。
public function invoke(string $api, $params = [], $method = 'POST')
{
$url = $this->host . $api;
$sign = $this->generateSign($params);
$headers = ['accesstoken' => $this->token, 'sign' => $sign, 'Content-Type' => 'application/json'];
if ($method === 'get' || $method === 'GET') {
$response = $this->client->get($url, ['query' => $params,'http_errors' => false,'headers' => $headers]);
} else {
$response = $this->client->post($url, ['body'=>json_encode($params),'http_errors' => false,'headers' => $headers]);
}
$body = $response->getBody();
$bodyStr = (string)$body;
$arr = json_decode($bodyStr,true);
return $arr;
}
protected function generateSign($params)
{
$jsonStr = json_encode($params).$this->login['appKey'];
return md5($jsonStr);
}
2023-08-11 14:01:14 | |
2023-03-31 21:08:37 | |
2022-02-14 07:12:09 | |
2024-08-21 23:03:06 | |
2021-11-02 23:40:33 | |
2024-01-20 02:49:42 | |
2024-01-07 09:04:52 | |
2023-07-20 18:40:13 | |
2021-12-29 14:32:26 | |
2023-08-26 22:37:18 | |
2024-11-25 06:59:32 | |
2024-10-28 14:08:32 | |
2024-12-05 06:40:11 | |
2024-12-23 05:45:53 | |
2024-11-20 07:48:41 | |
2024-10-27 19:00:29 | |
2024-12-23 14:00:12 | |
2024-11-06 01:38:45 | |
2024-10-21 08:53:41 | |
2025-03-15 11:26:12 | |
2024-03-07 14:30:40 | |
2024-03-07 11:30:21 | |
2024-03-07 11:25:58 | |
2024-03-07 11:16:24 | |
2024-03-07 11:16:03 |
黄宏棵 13286997615
数据集成顾问 资深系统集成顾问,专长于ERP、电商OMS、钉钉及CRM系统。他能提供高效的集成方案,优化企业运营流程,提升业务效率和决策智能化。
何海波 18175716035
数据集成顾问 轻易云的技术专家,拥有丰富的数据集成规划经验。他能够为客户提供专业、全面的数据集成规划方案,熟练掌握多种集成技术和工具,帮助企业在数据集成领域得到长远发展。
卢剑航 13760755942
数据集成专家 拥有十多年丰富的经验,擅长ERP、MES、数据中台、营销云中台等集成。他能够根据客户需求,为其提供一站式集成解决方案,帮助企业快速实现各类系统数据集成服务。
胡秀丛 15813570600
数据集成顾问 项目总监 她以卓越的数据集成专长,精通ERP、MES系统,以及数据中台的构建与优化。通过创新的一站式解决方案,她助力企业实现数据的无缝对接,提升业务流程效率,确保信息流通无障碍,为企业的数字化转型提供强有力的支持。