我已经设置了一个全局变量,等于一个访问令牌,当我打印_($session_id)时,令牌是可见的。我想做的是把这个变量传给我的CURLOPT_HTTPHEADER,并在下面的函数get_field_data_id()中让它等于 "Session"。
function get_session_id() {
global $session_id;
$curl = curl_init();
$session_url = "/auth";
curl_setopt_array($curl, array(
CURLOPT_URL => $session_url ,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
CURLOPT_HTTPHEADER => array(
"Content-Type: application/json",
"Accept: application/json",
"username: USER",
"password: PASS",
"authorizationkey: KEY"
$response = curl_exec($curl);
curl_close($curl);
$session_id = $response;
} add_filter( 'gform_after_submission_4', 'get_session_id' );
function get_field_data_id() {
global $session_id;
$curl = curl_init();
$file_url = "URL";
curl_setopt_array($curl, array(
CURLOPT_URL => $file_url,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
CURLOPT_HTTPHEADER => array(
"Content-Type: application/json",
"Accept: application/json",
"Session: {$session_id}"
$response = curl_exec($curl);
curl_close($curl);