菜谱项目

check.php 1.9KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. <?php
  2. define('SECRET_KEY', 'b693013c19222873eece0526b7b85da2');
  3. if (!function_exists('getallheaders')) {
  4. function getallheaders()
  5. {
  6. $headers = [];
  7. foreach ($_SERVER as $name => $value) {
  8. if (substr($name, 0, 5) == 'HTTP_') {
  9. $headers[str_replace(' ', '-', ucwords(strtolower(str_replace('_', ' ', substr($name, 5)))))] = $value;
  10. }
  11. }
  12. return $headers;
  13. }
  14. }
  15. $headers = getallheaders();
  16. function validSign()
  17. {
  18. // print_r($request->all());exit;
  19. $sign = isset($_POST['sign']) ? $_POST['sign'] : null;
  20. $time = isset($_POST['time']) ? $_POST['time'] : 0;
  21. $time = time() - $time;
  22. if (empty($sign) || $time >= 600) {
  23. return false;
  24. }
  25. $makesign = getSignature($_POST, SECRET_KEY);
  26. if ($makesign == $sign) {
  27. return true;
  28. }
  29. return false;
  30. }
  31. function getSignature($params, $secret_key)
  32. {
  33. // 按数组键名 正序排序
  34. ksort($params);
  35. $tem = array();
  36. foreach ($params as $k => $v) {
  37. if ($k !== 'sign') {
  38. $tem[] = "$k=$v";
  39. }
  40. }
  41. $sk = implode('&', $tem) . $secret_key;
  42. $a['mm'] = $sk;
  43. return md5($sk);
  44. }
  45. function versionCompare($version1, $operator, $version2)
  46. {
  47. $_fv = intval(trim(str_replace('.', '', $version1)));
  48. $_sv = intval(trim(str_replace('.', '', $version2)));
  49. if (strlen($_fv) > strlen($_sv)) {
  50. $_sv = str_pad($_sv, strlen($_fv), 0);
  51. }
  52. if (strlen($_fv) < strlen($_sv)) {
  53. $_fv = str_pad($_fv, strlen($_sv), 0);
  54. }
  55. return version_compare((string) $_fv, (string) $_sv, $operator);
  56. }
  57. $url = isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : null;
  58. //todo sign验证
  59. //if (!validSign()) {
  60. // $data = [];
  61. // $data['rst'] = ["data" => "illegal request"];
  62. // $data['errno'] = 1008;
  63. // $data['err'] = "非法请求";
  64. // $data['timestamp'] = time();
  65. // exit(json_encode($data));
  66. //}