PayUtils.php 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. <?php
  2. namespace common\pay\payplat;
  3. class PayUtils
  4. {
  5. /**
  6. * @param array $data
  7. * @param string $secretKey
  8. * @return string
  9. */
  10. public static function makeSign($data)
  11. {
  12. $str = '';
  13. ksort($data);
  14. foreach ($data as $key => $value) {
  15. if ($key == 'sign') {
  16. continue;
  17. }
  18. $value = strval($value);
  19. if ($value === '') { //参数为空不参与签名
  20. continue;
  21. }
  22. $str .= "{$key}={$value}&";
  23. }
  24. $str = rtrim($str, '&');
  25. file_put_contents('sting.txt',$str);
  26. return strtoupper(md5($str));
  27. }
  28. /**
  29. * @param array $data 参数
  30. * @param string $secretKey
  31. * @return bool
  32. */
  33. public static function checkSign($data)
  34. {
  35. $sign = isset($data['sign']) ? $data['sign'] : null;
  36. if ($sign == null) {
  37. return false;
  38. }
  39. return self::makeSign($data) === strtoupper($sign);
  40. }
  41. }