php代码post请求

<?php

 

/**

 * 发送post请求

 * @param string $url 请求地址

 * @param array $post_data post键值对数据

 * @return string

 */

function send_post($url, $post_data) {

  $postdata = http_build_query($post_data);

  $options = array(

    'http' => array(

      'method' => 'POST',

      'header' => 'Content-type:application/x-www-form-urlencoded,Content-Length: .strlen($query)',

      'content' => $postdata,

      'timeout' => 5 // 超时时间(单位:s)

    )

  );

  $context = stream_context_create($options);

  $result  = file_get_contents($url, false, $context);

  return $result;

}

 

//post数据

$post_data = array(

    'user_id'   => '148206',                                 // 用户ID

    'app_id'    => '85',                                     // 应用ID

    'order_sn'  => 'P201909062014389901',                    // 聚合平台订单号

    'attach'    => '878910012825534479_878910012825534466',  // 游戏订单号

    'money'     => '1',                                      // 订单金额(单位:分)

    'server'    => '3101',                                   // 游戏区服名

    'role'      => 'aaa',                                    // 游戏角色名

    'ip'        => '115.171.217.6',                          // 用户IP

    'add_time'  => '1567772078',                             // 聚合平台订单创建时间

    'sign'      => '1030893470d8e65ee4c4c65359ba6405'        // 签名

);

 

$url = 'http://11-1111.11.com:7904/pay_cadd_lesqi';

$res = send_post($url, $post_data);

print_r($res);

 

?>

猜你喜欢

转载自www.cnblogs.com/xingchong/p/11482095.html
今日推荐