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

 

?>

posted @   会飞的斧头  阅读(2704)  评论(0编辑  收藏  举报
编辑推荐:
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
阅读排行:
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 单元测试从入门到精通
· 上周热点回顾(3.3-3.9)
· winform 绘制太阳,地球,月球 运作规律
点击右上角即可分享
微信分享提示