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