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

 

?>


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM