| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172 |
- <?php
- namespace common\pay\eagle;
- class PayUtils
- {
- /**
- * @param array $data
- * @param string $secretKey
- * @return string
- */
- public static function makeSign($data, $secretKey)
- {
- $str = '';
- ksort($data);
- foreach ($data as $key => $value) {
- if ($key == 'sign') {
- continue;
- }
- $value = strval($value);
- if ($value === '') {
- continue;
- }
- $str .= "{$key}={$value}&";
- }
- $str = rtrim($str, '&') . "&key={$secretKey}";
- file_put_contents('190903.txt',$str);
- file_put_contents('190903md5.txt',strtoupper(md5($str)));
- return strtoupper(md5($str));
- }
- /**
- * @param array $data 参数
- * @param string $secretKey
- * @return bool
- */
- public static function checkSign($data, $secretKey)
- {
- $sign = isset($data['sign']) ? $data['sign'] : null;
- if ($sign == null) {
- return false;
- }
- return self::makeSign($data, $secretKey) === $sign;
- }
-
- /**
- * 发送post请求
- * @param string $url 请求地址
- * @param array $post_data post键值对数据
- * @return string
- */
- public static function sendPost($url, $post_data) {
- $postdata = http_build_query($post_data);
- $options = array(
- 'http' => array(
- 'method' => 'POST',
- 'header' => 'Content-type:application/x-www-form-urlencoded',
- 'content' => $postdata,
- 'timeout' => 15 * 60 // 超时时间(单位:s)
- )
- );
- $context = stream_context_create($options);
- $result = file_get_contents($url, false, $context);
- return $result;
- }
- }
|