| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849 |
- <?php
- namespace common\pay\payplat;
- class PayUtils
- {
- /**
- * @param array $data
- * @param string $secretKey
- * @return string
- */
- public static function makeSign($data)
- {
- $str = '';
- ksort($data);
- foreach ($data as $key => $value) {
- if ($key == 'sign') {
- continue;
- }
- $value = strval($value);
- if ($value === '') { //参数为空不参与签名
- continue;
- }
- $str .= "{$key}={$value}&";
- }
- $str = rtrim($str, '&');
- file_put_contents('sting.txt',$str);
- return strtoupper(md5($str));
- }
- /**
- * @param array $data 参数
- * @param string $secretKey
- * @return bool
- */
- public static function checkSign($data)
- {
- $sign = isset($data['sign']) ? $data['sign'] : null;
- if ($sign == null) {
- return false;
- }
- return self::makeSign($data) === strtoupper($sign);
- }
- }
|