Last active
August 1, 2019 07:28
-
-
Save JellyBool/a1039242ccfa6a8d16ff to your computer and use it in GitHub Desktop.
Pingxx verify , depence on pingxx package
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Ping++ 的数据可以这样获取 | |
// $rawData = file_get_contents('php://input'); | |
// 判断是否返回 1 ,最后记得返回 http_response_code(200); | |
protected function verifyPing($rawData) { | |
$headers = \Pingpp\Util\Util::getRequestHeaders();//这是Ping++的package提供的 | |
$signature = isset($headers['X-Pingplusplus-Signature']) ? $headers['X-Pingplusplus-Signature'] : NULL; | |
$publicKeyContents = file_get_contents(public_path(). '/rsa_public_key.pem');//注意这里面的文件路径相对应 | |
return openssl_verify($rawData, base64_decode($signature), $publicKeyContents, 'sha256'); | |
} | |
protected function verifyPingFail($result) | |
{ | |
if ( $result === 0 ) { | |
http_response_code(400); | |
echo 'verification failed'; | |
exit; | |
} | |
http_response_code(400); | |
echo 'verification error'; | |
exit; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment