您现在的位置是:首页 > 开发开发

PHP file_get_contents()发送post,UUID

2023-07-27 11:39:18【开发】人已围观

简介PHP file_get_contents()发送post示例,和生成UUID

PHP file_get_contents()发送post示例
//生成UUID
function create_uuid() {
    $chars = md5(uniqid(mt_rand(), true));
    $uuid = substr ( $chars, 0, 8 ) . '-'
        . substr ( $chars, 8, 4 ) . '-'
        . substr ( $chars, 12, 4 ) . '-'
        . substr ( $chars, 16, 4 ) . '-'
        . substr ( $chars, 20, 12 );
    return $uuid ;
}
$requestID = create_uuid();

//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;charset=utf-8',
            'content' => $postdata,
            'timeout' => 15 * 60 // 超时时间(单位:s)
        )
    );
    $context = stream_context_create($options);
    $result = file_get_contents($url, false, $context);
    return $result;
}
//发送参数
$post_data = array(
    'partnerID' => $partnerID,
    'requestID' => $requestID,
    'serviceCode' => $serviceCode,
    'timestamp' => $timestamp,
    'msgDigest' => $msgDigest,
    'msgData' => $msgData
);
$url='http://www.cgjx.net';//
$resultCont = send_post($url, $post_data); //沙盒环境
print_r(json_decode($resultCont)); //打印返回结果

很赞哦! ()

相关文章

文章评论

热评榜