mailup rest client
1.0.0
Fazland的Mailup REST客戶端是電子郵件和SMS GatewayProvider Mailup的非官方PHP REST客戶端。
建議的安裝方法是通過作曲家:
$ composer require fazland/mailup-rest-client這真的很簡單。首先,配置!
強製配置參數是:
usernamepasswordclient_idclient_secret唯一的可選參數是cache_dir 。如果設置,則將訪問令牌保存在該路徑中。
只需創建一個將參數傳遞給構造函數的Context像作為數組:
use Fazland MailUpRestClient Context ;
$ config = [
' username ' => ' your_username ' ,
' password ' => ' your_password ' ,
' client_id ' => ' your_client_id ' ,
' client_secret ' => ' your_client_secret ' ,
' cache_dir ' => ' path_to_your_cache_dir ' , // Optional
];
$ httpClient = new HttpClientImplementation ();
$ context = new Context ( $ config , $ httpClient );要創建MailingList您可以按照此示例。請,請參閱Mailup官方API文檔中的$params陣列。
use Fazland MailUpRestClient MailingList ;
$ email = " [email protected] " ;
$ listName = " list_name " ;
$ params = [
// your params...
];
$ list = MailingList:: create ( $ context , $ listName , $ email , $ params );您還可以通過調用靜態方法MailingList::getAll()來獲取郵件帳戶中的所有現有列表:
use Fazland MailUpRestClient MailingList ;
$ lists = MailingList:: getAll ( $ context );一旦擁有MailingList的實例,就可以執行以下操作:
Recipient use Fazland MailUpRestClient Recipient ;
$ list -> addRecipient ( new Recipient ( ' Aragorn ' , ' [email protected] ' , ' 3333333333 ' , ' +39 ' ));Recipient use Fazland MailUpRestClient Recipient ;
$ list -> updateRecipient ( new Recipient ( ' Aragorn ' , ' [email protected] ' , ' 3334444444 ' , ' +39 ' ));Recipient use Fazland MailUpRestClient Recipient ;
$ list -> removeRecipient ( new Recipient ( ' Aragorn ' , ' [email protected] ' , ' 3333333333 ' , ' +39 ' ));email找到Recipient $ recipient = $ list -> findRecipient ( ' [email protected] ' ); // null returned if current email was not found $ groups = $ list -> getGroups (); $ countRecipients = $ list -> countRecipients (); // equal to $list->countRecipients(Recipient::STATUS_SUBSCRIBED);
// OR
$ countRecipients = $ list -> countRecipients (Recipient:: STATUS_UNSUBSCRIBED );
// OR
$ countRecipients = $ list -> countRecipients (Recipient:: STATUS_PENDING ); $ recipients = $ list -> getRecipientsPaginated ( $ pageNumber , $ pageSize );Recipient對象: $ list -> import ( $ recipients );每個MailingList可以分為多組。可用的操作如下:
$ group -> getName ();
$ group -> setName ( ' Gondor Army ' ); $ group -> getNotes ();
$ group -> setNotes ( ' 10.000 knights and 20.000 peons ' ); $ group -> isDeletable ();
$ group -> setDeletable ( true ); $ group -> delete (); use Fazland MailUpRestClient Recipient ;
$ legolas = new Recipient ( ' Legolas Thranduilion ' , ' [email protected] ' , ' 3334444444 ' , ' +39 ' );
$ group -> addRecipient ( $ legolas );
$ group -> removeRecipient ( $ legolas );
$ lothlorienCitizens = $ group -> getRecipients ();歡迎捐款。請隨時在Github上打開PR或提交問題!
MailUp REST客戶端已根據MIT許可證獲得許可 - 有關詳細信息,請參見許可證文件