| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546 |
- <?php
- namespace common\pay\rtw;
- use Yii;
- use yii\helpers\VarDumper;
- class PayUtils
- {
- /**
- * @param array $data
- * @return string
- */
- public static function makeSign($data, $md5Key)
- {
- $str = '';
- ksort($data);
- foreach ($data as $key => $value) {
- $str .= "{$key}={$value}&";
- }
- Yii::warning('签名参数,' . $str.$md5Key, __METHOD__);
- return md5($str . $md5Key);
- }
-
- /**
- * 发送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;
- }
- }
|