Skip to content

Instantly share code, notes, and snippets.

@Ravenna
Last active August 5, 2020 22:48
Show Gist options
  • Save Ravenna/50d94f443364e0025308295f130cbe8e to your computer and use it in GitHub Desktop.
Save Ravenna/50d94f443364e0025308295f130cbe8e to your computer and use it in GitHub Desktop.
function httpRequest($url, $body) {
$method = "POST";
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_HEADER, 0);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
if ($body) {
curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query($body));
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, $method);
curl_setopt($curl, CURLOPT_HTTPHEADER, array("Content-Type: application/x-www-form-urlencoded"));
}
Log::info('CURL');
Log::info($curl);
$data = curl_exec($curl);
if ($this->debug) {
echo "In httpRequest: Recieved DATA\n===========\n" . $data . "\n===========\n";
}
if(curl_error($curl))
{
Log::info('curl error:' . curl_error($curl));
return "AC Fail";
}
curl_close($curl);
return $data;
}
// Trigger the Message notification to a member
// @param $acID = user->active_campaign_id / integer
// @param $type = type of message to be sent / string
// @param $msg = message to be sent to user / string
// @param $adminMsg = message to be sent to system admin / string
// @param $referrer = optional
//
function sendMessageViaAC($acEmail, $type, $msg = NULL, $subject = NULL, $adminMsg = NULL, $referrer = NULL){
// AC Field ID's
// Temp Message Type = 26
// Temp Message Text = 27
// Temp Referrer = 28
// Temp System Msg = 29
$addUrl = $this->base_url . "/admin/api.php?api_action=contact_sync";
$body = array(
'api_action' => 'contact_edit',
'api_key' => $this->secure_token,
'api_output' => 'json',
'email' => $acEmail,
'field[26, 0]' => $type,
'field[27, 0]' => $msg,
'field[29, 0]' => $adminMsg,
);
//Log::info(print_r($body, true));
if($referrer){
$body['field[28, 0]'] = $referrer;
}
if($subject){
$body['field[32, 0]'] = $subject;
}
$request = $this->httpRequest($addUrl, $body);
$contact = json_decode($request, true);
return $contact;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment