我正在使用重力形式与wordpress集成垂直响应订阅表单和curl以授权持有者令牌,但无法建立连接
function post_to_vr($entry, $form ) {
$raw_data = [
'email' => $entry
];
$authorization = "Authorization: Bearer x7ab8errzuj87u24qemzytu3";
$ch = curl_init('https://vrapi.verticalresponse.com/api/v1/lists/36283883717887/contacts');
$data = json_encode($raw_data);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json' , $authorization ));
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
$result = curl_exec($ch);
curl_close($ch);
return json_decode($result);
}
add_action("gform_after_submission", "post_to_vr",10, 2);
它看起来还不错,除了一件事,即
取代:
$raw_data = [
'email' => $entry
];
跟:
$raw_data = [
'email' => $entry[x]
];
其中">x"将是保存电子邮件数据的数组的索引值。
希望这会有所帮助。快乐编码。