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);
}
2024-01-16 17:35:23 | |
2021-11-08 09:54:41 | |
2024-09-23 05:32:30 | |
2024-04-20 15:44:52 | |
2021-09-10 23:17:44 | |
2022-03-30 02:02:49 | |
2021-11-16 03:03:15 | |
2022-12-26 23:16:21 | |
2023-01-16 03:43:20 | |
2023-10-16 08:52:05 | |
2024-11-04 00:24:51 | |
2024-12-30 05:28:23 | |
2024-11-12 01:55:35 | |
2024-10-24 08:03:46 | |
2024-10-28 09:16:03 | |
2024-12-27 05:17:40 | |
2024-12-18 07:52:34 | |
2024-11-24 17:36:25 | |
2024-10-25 04:49:12 | |
2024-10-31 11:28:43 | |
2023-01-26 10:06:37 | |
2023-01-26 10:06:36 | |
2023-01-26 10:06:35 | |
2023-01-26 10:06:34 | |
2023-01-26 10:06:34 |
何海波 18175716035
数据集成顾问 轻易云的技术专家,拥有丰富的数据集成规划经验。他能够为客户提供专业、全面的数据集成规划方案,熟练掌握多种集成技术和工具,帮助企业在数据集成领域得到长远发展。
胡秀丛 15813570600
数据集成顾问 项目总监 她以卓越的数据集成专长,精通ERP、MES系统,以及数据中台的构建与优化。通过创新的一站式解决方案,她助力企业实现数据的无缝对接,提升业务流程效率,确保信息流通无障碍,为企业的数字化转型提供强有力的支持。
卢剑航 13760755942
数据集成专家 拥有十多年丰富的经验,擅长ERP、MES、数据中台、营销云中台等集成。他能够根据客户需求,为其提供一站式集成解决方案,帮助企业快速实现各类系统数据集成服务。
黄宏棵 13286997615
数据集成顾问 资深系统集成顾问,专长于ERP、电商OMS、钉钉及CRM系统。他能提供高效的集成方案,优化企业运营流程,提升业务效率和决策智能化。