post request php code

<?php

 

/**

 * Send a post request

 * @Param string $ url address request

 * @Param array $ post_data post key data

 * @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 // delay time (unit: s)

    )

  );

  $context = stream_context_create($options);

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

  return $result;

}

 

// post data

$post_data = array(

    'user_id'   => '148 206',                                 // user ID

    'APP_ID'     => '85',                                     // application ID

    'order_sn'   => 'P201909062014389901',                     // aggregation platform Order No.

    'The attach'     => '878910012825534479_878910012825534466',   // order number game

    'Money'     => '1',                                       // order amount (unit: minutes)

    'Server'     => '3101',                                   // Game area clothing name

    'Role'       => 'aaa',                                     // game character name

    'IP'         => '115.171.217.6',                           // user IP

    'ADD_TIME'   => '1567772078',                             // order creation time aggregation platform

    'Sign'       => '1030893470d8e65ee4c4c65359ba6405'         // Signed

);

 

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

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

print_r($res);

 

?>

Guess you like

Origin www.cnblogs.com/xingchong/p/11482095.html