我试图弄清楚如何使用 PHP 和 Bronto API 来识别用户是否订阅或取消订阅特定的电子邮件列表。
我正在使用下面的代码,我的问题是,无论用户是订阅还是取消订阅,我总是会为用户获得“活动”状态,我需要查看的不是他们是否在列表中而是取消订阅或在列出并订阅。
无论如何知道我应该改变什么?
<?php
$client = new SoapClient('https://api.bronto.com/v4?wsdl', array('trace' => 1,
'features' => SOAP_SINGLE_ELEMENT_ARRAYS));
try {
//token
$token = "abc 123 and yz";
//print "logging in\n";
$sessionId = $client->login(array('apiToken' => $token))->return;
$session_header = new SoapHeader("http://api.bronto.com/v4",
'sessionHeader',
array('sessionId' => $sessionId));
$client->__setSoapHeaders(array($session_header));
// set up a filter to read contacts and match on email address
$filter = array('email' => array(array('operator' => 'EqualTo',
'value' => 'fake.person@gmail.com'
),
),
);
$contacts = $client->readContacts(array('pageNumber' => 1,
'includeLists' => false,
'filter' => $filter,
)
)->return;
// print matching contact email addresses
foreach ($contacts as $contact) {
//$contact->status always seems to have a status of active or null ??
if($contact->status ='subscribed')
{
echo " <a href='' class='btn btn-primary'>Unsubscribe</a>";
}
else if($contact->status ='Unsubscribed')
{
echo " <a href=''>Subscribe</a>";
}
//print $contact->email . ': ' . $contact->status . "\n";
}
} catch (Exception $e) {
print "uncaught exception\n";
print_r($e);
}