首页 > Web开发 > 详细

php代码post请求

时间:2019-09-07 18:43:37      阅读:96      评论:0      收藏:0      [点我收藏+]

<?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);

 

?>

php代码post请求

原文:https://www.cnblogs.com/xingchong/p/11482095.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!