dmmes/README.md

63 lines
1.4 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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