Skip to content

Instantly share code, notes, and snippets.

@JellyBool
Last active August 1, 2019 07:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 5 You must be signed in to fork a gist
  • Save JellyBool/a1039242ccfa6a8d16ff to your computer and use it in GitHub Desktop.
Save JellyBool/a1039242ccfa6a8d16ff to your computer and use it in GitHub Desktop.
Pingxx verify , depence on pingxx package
<?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