更新SDK用法
This commit is contained in:
parent
2e9999c877
commit
2f30a6cf6f
12
README.md
12
README.md
|
@ -30,15 +30,19 @@ $response = $w->createProductOrder([
|
|||
```
|
||||
|
||||
# 回调说明
|
||||
- 配置回调后地址后,应用服务器会以POST方式请求你的服务器地址,以便你做进一步业务流程
|
||||
- 回调你服务器地址后,可获取参数"data"、"signature"进行验签,"response" 为服务器处理结果数据
|
||||
- 配置回调后地址后,应用服务器会以POST方式请求你的服务器地址,以便你做进一步业务流程。
|
||||
- 回调你服务器地址后,可获取参数"data"、"signature"进行验签,"response" 为服务器处理结果。
|
||||
|
||||
```php
|
||||
// 回调参数调用方法
|
||||
$w = new Order($secretKey, 'callback url');
|
||||
|
||||
// 获取数据
|
||||
$request = require();
|
||||
$params = json_decode($request->contents(), true);
|
||||
|
||||
// 回调验签
|
||||
$receivedSignature = $params['signature'];
|
||||
$receivedSignature = $request->headers('signature');
|
||||
$data = json_encode($params['data']);
|
||||
/**
|
||||
* 生成HMAC签名
|
||||
|
@ -51,7 +55,7 @@ function generateHmacSignature($data): string
|
|||
return hash_hmac('sha256', $data, $secretKey);
|
||||
}
|
||||
|
||||
$calculatedSignature = $this->generateHmacSignature(json_encode($data));
|
||||
$calculatedSignature = $this->generateHmacSignature($data);
|
||||
|
||||
// 验证签名是否匹配 hash_equals($receivedSignature, $calculatedSignature)
|
||||
if ($receivedSignature === $calculatedSignature) {
|
||||
|
|
Loading…
Reference in New Issue