PayUtils.php 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. <?php
  2. namespace common\pay\rtw;
  3. use Yii;
  4. use yii\helpers\VarDumper;
  5. class PayUtils
  6. {
  7. /**
  8. * @param array $data
  9. * @return string
  10. */
  11. public static function makeSign($data, $md5Key)
  12. {
  13. $str = '';
  14. ksort($data);
  15. foreach ($data as $key => $value) {
  16. $str .= "{$key}={$value}&";
  17. }
  18. Yii::warning('签名参数,' . $str.$md5Key, __METHOD__);
  19. return md5($str . $md5Key);
  20. }
  21. /**
  22. * 发送post请求
  23. * @param string $url 请求地址
  24. * @param array $post_data post键值对数据
  25. * @return string
  26. */
  27. public static function sendPost($url, $post_data) {
  28. $postdata = http_build_query($post_data);
  29. $options = array(
  30. 'http' => array(
  31. 'method' => 'POST',
  32. 'header' => 'Content-type:application/x-www-form-urlencoded',
  33. 'content' => $postdata,
  34. 'timeout' => 15 * 60 // 超时时间(单位:s)
  35. )
  36. );
  37. $context = stream_context_create($options);
  38. $result = file_get_contents($url, false, $context);
  39. return $result;
  40. }
  41. }