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);
}
2022-12-21 12:32:23 | |
2024-03-22 05:26:01 | |
2022-01-08 00:08:17 | |
2023-01-27 13:37:56 | |
2023-04-09 03:01:29 | |
2021-08-08 19:52:27 | |
2022-06-28 09:59:51 | |
2022-07-22 23:09:47 | |
2021-02-13 04:16:35 | |
2024-05-14 15:55:26 | |
2022-10-03 02:45:08 | |
2024-10-17 02:55:26 | |
2024-12-24 09:38:16 | |
2024-12-10 05:41:12 | |
2024-11-28 08:50:02 | |
2024-12-15 01:54:49 | |
2024-10-28 09:45:15 | |
2024-10-26 16:23:12 | |
2024-11-10 12:12:08 | |
2024-11-14 04:28:10 | |
2024-01-29 07:25:15 | |
2024-01-13 06:40:47 | |
2024-01-05 03:42:55 | |
2024-01-04 03:08:28 | |
2024-01-03 12:30:07 |
胡秀丛 15813570600
数据集成顾问 项目总监 她以卓越的数据集成专长,精通ERP、MES系统,以及数据中台的构建与优化。通过创新的一站式解决方案,她助力企业实现数据的无缝对接,提升业务流程效率,确保信息流通无障碍,为企业的数字化转型提供强有力的支持。
黄宏棵 13286997615
数据集成顾问 资深系统集成顾问,专长于ERP、电商OMS、钉钉及CRM系统。他能提供高效的集成方案,优化企业运营流程,提升业务效率和决策智能化。
卢剑航 13760755942
数据集成专家 拥有十多年丰富的经验,擅长ERP、MES、数据中台、营销云中台等集成。他能够根据客户需求,为其提供一站式集成解决方案,帮助企业快速实现各类系统数据集成服务。