| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859 |
- <?php
- namespace common\pay\dinpay;
- class PayUtils
- {
-
- /**
- * 发送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;
- }
- /**
- * 构造自动提交表单
- * @param array $params
- * @param string $action
- * @return string
- */
- public static function createHtml($params, $action)
- {
- $encodeType = isset ($params ['encoding']) ? $params ['encoding'] : 'UTF-8';
- $html = <<<eot
- <html>
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset={$encodeType}" />
- </head>
- <body onload="javascript:document.pay_form.submit();">
- <form id="pay_form" name="pay_form" action="{$action}" method="post">
- eot;
- foreach ($params as $key => $value) {
- $html .= " <input type=\"hidden\" name=\"{$key}\" id=\"{$key}\" value=\"{$value}\" />\n";
- }
- $html .= <<<eot
- <!-- <input type="submit" type="hidden">-->
- </form>
- </body>
- </html>
- eot;
- return $html;
- }
- }
|