php post请求方法,不用curl方法的解决办法
/** * file_get_contents方法 请求 * @param string $url 接口url * @param string $post_data 接口参数 * @return string */ if (!function_exists('send_post')) { 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' => $postdata, 'timeout' => 15 * 60 // 超时时间(单位:s) ) ); $context = stream_context_create($options); $result = @file_get_contents($url, false, $context); return $result; } }
调用实例
$data = array( "mobile" => $orderData['phone'], 'pay_price' => $orderData['orderAmount'], 'send_price' => 0, 'id' => 0, 'mall_id' => $merchantInfo['xiaowei_id'], ); $url = 'https://xiaowei23.shop.test/web/index.php?_mall_id='.$merchantInfo['xiaowei_id'].'&r=api/open/balance-recharge'; $res = send_post($url,$data); // dd($res); $res = json_decode($res,true);