1

我试图弄清楚如何使用 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);
        }
4

1 回答 1

0

我认为您在滥用对象属性“状态”。如果您查看此页面https://help.bronto.com/bmp/reference/r_api_soap_contactfilter.html,它会显示所有状态等于的事物。老实说,我认为最好使用此过滤器功能来选择未订阅的用户并根据过滤器的结果执行逻辑。 $contact->status == "unsub" 返回什么?我的意思是总是有这个https://help.bronto.com/bmp/reference/r_api_soap_readunsubscribes.html方法用于选择未订阅的用户,然后对该组中未找到的用户执行逻辑。

        // print matching contact email addresses
         foreach ($contacts as $contact) {
         //$contact->status  always seems to have a status of active or null ??
          if($contact->status != 'unsub')
         {
            echo " <a href='' class='btn btn-primary'>Unsubscribe</a>";
         }
          else if($contact->status =='unsub')
         {
            echo " <a href=''>Subscribe</a>";
         }
           //print $contact->email . ': ' . $contact->status . "\n";
        }

我刚刚注意到您的运营商不对。你有“=”,不应该是“==”吗?

于 2019-01-24T20:35:39.860 回答