2023-09-07 14:18:40 +08:00
|
|
|
|
# 德木自动化项目开放接口SDK
|
|
|
|
|
|
|
|
|
|
# 介绍
|
|
|
|
|
用于德木自动化对外开放接口数据交互
|
|
|
|
|
|
|
|
|
|
# 要求
|
|
|
|
|
- php版本:>=7.0
|
|
|
|
|
|
|
|
|
|
# 安装
|
|
|
|
|
|
|
|
|
|
```php
|
|
|
|
|
composer require ykxiao/dmmes
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
# 使用
|
|
|
|
|
|
|
|
|
|
```php
|
|
|
|
|
$secretKey = 'gFBfirGATxafTeq74RAngaL74Ksdxhuy';
|
|
|
|
|
|
|
|
|
|
$w = new Order($secretKey);
|
|
|
|
|
|
|
|
|
|
// 获取工单数据
|
|
|
|
|
$response = $w->getProductOrder('SN5436745676543');
|
2023-09-07 15:39:32 +08:00
|
|
|
|
|
|
|
|
|
// 创建加工工单
|
|
|
|
|
$response = $w->createProductOrder([
|
|
|
|
|
'cube_plan' => 32.23,
|
|
|
|
|
'owner' => 'ykxiao'
|
|
|
|
|
]);
|
2023-09-07 14:18:40 +08:00
|
|
|
|
```
|
2023-09-08 10:42:34 +08:00
|
|
|
|
|
|
|
|
|
# 回调说明
|
2023-09-08 14:17:19 +08:00
|
|
|
|
- 配置回调后地址后,应用服务器会以POST方式请求你的服务器地址,以便你做进一步业务流程。
|
|
|
|
|
- 回调你服务器地址后,可获取参数"data"、"signature"进行验签,"response" 为服务器处理结果。
|
2023-09-08 10:53:35 +08:00
|
|
|
|
|
2023-09-08 10:42:34 +08:00
|
|
|
|
```php
|
|
|
|
|
// 回调参数调用方法
|
|
|
|
|
$w = new Order($secretKey, 'callback url');
|
|
|
|
|
|
2023-09-08 14:17:19 +08:00
|
|
|
|
// 获取数据
|
|
|
|
|
$request = require();
|
|
|
|
|
$params = json_decode($request->contents(), true);
|
|
|
|
|
|
2023-09-08 10:42:34 +08:00
|
|
|
|
// 回调验签
|
2023-09-08 14:17:19 +08:00
|
|
|
|
$receivedSignature = $request->headers('signature');
|
2023-09-08 10:42:34 +08:00
|
|
|
|
$data = json_encode($params['data']);
|
|
|
|
|
/**
|
|
|
|
|
* 生成HMAC签名
|
|
|
|
|
* @param $data
|
|
|
|
|
* @return string
|
|
|
|
|
*/
|
|
|
|
|
function generateHmacSignature($data): string
|
|
|
|
|
{
|
|
|
|
|
$secretKey = 'YOUR_SECRET_KEY'; // 应用服务器密钥
|
|
|
|
|
return hash_hmac('sha256', $data, $secretKey);
|
|
|
|
|
}
|
|
|
|
|
|
2023-09-08 14:17:19 +08:00
|
|
|
|
$calculatedSignature = $this->generateHmacSignature($data);
|
2023-09-08 10:42:34 +08:00
|
|
|
|
|
|
|
|
|
// 验证签名是否匹配 hash_equals($receivedSignature, $calculatedSignature)
|
|
|
|
|
if ($receivedSignature === $calculatedSignature) {
|
|
|
|
|
return json_encode($data);
|
|
|
|
|
} else {
|
|
|
|
|
throw new Exception('数据签名验证失败!');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
```
|