مكتبة غير رسمية داخلية للمساعدة في تفاعلات API لمسوق النص.
ext-mbstring
ext-dom
composer require nessworthytextmarketer
$ apiCredentials = new Nessworthy TextMarketer Authentication Simple ( ' api_username ' , ' api_password ' );
$ httpClient = new GuzzleHttp Client ();
$ textMarketer = new Nessworthy TextMarketer TextMarketer ( $ apiCredentials , $ httpClient );
NessworthyTextMarketerAuthentication
NessworthyTextMarketerTextMarketer::ENDPOINT_PRODUCTION
(افتراضي)NessworthyTextMarketerTextMarketer::ENDPOINT_SANDBOX
GuzzleHttpClientInterface
GuzzleHttpClient
. $ messageCommand = new Nessworthy TextMarketer Message SendMessage (
' This is a test message ' , // Your SMS Message.
[ ' 447777777777 ' ], // The array of contact numbers.
' TestCompanyInc ' , // Who the message was sent from.
' testmessage ' , // Optional: Tag your message for delivery report filtering.
24 , // Optional: Mark the message as time-sensitive: Should only be sent if it is within X hours.
true , // Optional: If true, if any recipient is matched in your STOP group the message will not be sent.
' [email protected] ' // Optional : Your txtUS enterprise email (txtUS accounts only).
);
$ deliveryResult = $ textMarketer -> sendMessage ( $ messageCommand );
if ( $ deliveryResult -> isSent ()) {
echo ' Message sent with the ID of ' . $ deliveryResult -> getMessageId ();
} elseif ( $ deliveryResult -> isQueued ()) {
echo ' Message queued with the ID of ' . $ deliveryResult -> getMessageId ();
} elseif ( $ deliveryResult -> isScheduled ()) {
echo ' Is scheduled with the ID of ' . $ deliveryResult -> getScheduledId ();
}
$ scheduledDate = ( new DateTimeImmutable )-> modify ( ' +1 month ' );
$ deliveryResult = $ textMarketer -> sendScheduledMessage ( $ messageCommand , $ scheduledDate );
// Scheduled message ID can be found from the delivery result for scheduled messages:
// $scheduledMessageId = $deliveryResult->getScheduledId();
$ textMarketer -> deleteScheduledMessage ( $ scheduledMessageId );
echo sprintf ( ' I have %d remaining credits! ' , $ textMarketer -> getCreditCount ());
$ transferResult = $ textMarketer -> transferCreditsToAccountById ( 100 , $ someAccountId );
// Or by credentials:
$ destinationCredentials = new Nessworthy TextMarketer Authentication Simple ( ' username ' , ' password ' ));
$ transferResult = $ textMarketer -> transferCreditsToAccountByCredentials ( 100 , $ destinationCredentials );
echo sprintf (
' I had %d credits. After transferring, I now have %d! ' ,
$ transferResult -> getSourceCreditsBeforeTransfer (),
$ transferResult -> getSourceCreditsAfterTransfer ()
);
echo ' <br> ' ;
echo sprintf (
' The target account had %d credits. After transferring, it now has %d! ' ,
$ transferResult -> getTargetCreditsBeforeTransfer (),
$ transferResult -> getTargetCreditsAfterTransfer ()
);
$ keyword = ' mykeyword ' ;
$ keywordAvailability = $ textMarketer -> checkKeywordAvailability ( $ keyword );
echo sprintf (
' The keyword "%s" %s available! It %s been recycled (used previously). ' ,
$ keyword ,
( $ keywordAvailability -> isAvailable () ? ' is ' : ' is not ' ),
( $ keywordAvailability -> isRecycled () ? ' has ' : ' has not ' )
);
$ groupCollection = $ textMarketer -> getGroupsList ();
echo sprintf (
' I have %s groups! ' ,
$ groupCollection -> isEmpty () ? ' no ' : $ groupCollection -> getTotal ()
);
echo ' <br> ' ;
echo ' Here is a summary of each group: ' ;
foreach ( $ groupCollection -> asArray () as $ groupSummary ) {
echo sprintf (
' Group name: %s (ID: %d) has %s numbers. It %s a stop group! ' ,
$ groupSummary -> getName (),
$ groupSummary -> getId (),
$ groupSummary -> getNumberCount (),
$ groupSummary -> isStopGroup () ? ' IS ' : ' IS NOT '
);
echo ' <br/> ' ;
}
$ numbersToAdd = new Nessworthy TextMarketer Message Part PhoneNumberCollection ([
' 44700000000 ' ,
' 44700000001 ' ,
' 44700000002 ' ,
]);
$ result = $ textMarketer -> addNumbersToGroup ( ' MyGroupNameOrID ' , $ numbersToAdd );
// Of the numbers - which ones were actually added to the list.
echo ' Added numbers: ' . $ textMarketer -> getTotalAddedNumbers ();
echo ' Numbers added:<br> ' . implode ( ' <br> ' , $ textMarketer -> getAddedNumbers ();
echo ' <br> ' ;
// Of the numbers - which ones were not added because they were on a STOP list.
echo ' Stopped numbers: ' . $ textMarketer -> getTotalStoppedNumbers ();
echo ' Numbers added:<br> ' . implode ( ' <br> ' , $ textMarketer -> getStoppedNumbers ();
echo ' <br> ' ;
// Of the numbers - which ones were not added because they were already on it.
echo ' Duplicated numbers: ' . $ textMarketer -> getTotalDuplicateNumbers ();
echo ' Numbers added:<br> ' . implode ( ' <br> ' , $ textMarketer -> getDuplicateNumbers ();
$ group = $ textMarketer -> createGroup ( ' mygroup ' );
echo sprintf (
' A new group was created by the name "%s" with an assigned ID of "%d"! The group %s a stop group. ' ,
$ group -> getName (),
$ group -> getId (),
$ group -> isStopGroup () ? ' IS ' : ' IS NOT '
);
// You can also use getNumberCount() and getNumbers(), which will return 0 and an empty array, respectively.
$ group = $ textMarketer -> getGroupInformation ( ' mygroup ' );
echo sprintf (
' The group is called "%s" with an assigned ID of "%d"! The group %s a stop group. ' ,
$ group -> getName (),
$ group -> getId (),
$ group -> isStopGroup () ? ' IS ' : ' IS NOT '
);
echo ' <br/> ' ;
echo sprintf (
' The group has %d numbers. Here they are:<br>%s ' ,
$ group -> getNumberCount (),
implode ( ' <br> ' , $ group -> getNumbers ())
);
$ reportCollection = $ textMarketer -> getDeliveryReportList ();
echo sprintf (
' I have %s reports in total! ' ,
$ reportCollection -> isEmpty () ? ' no ' : $ reportCollection -> getTotal ()
);
foreach ( $ reportCollection -> asArray () as $ report ) {
echo ' <br> ' ;
echo sprintf (
' Report %s (last updated: %s) has extension %s. ' ,
$ report -> getName (),
$ report -> getLastUpdated -> format ( ' d-m-Y H:i:s ' ),
$ report -> getExtension ()
);
}
جميع المكالمات المتعلقة بالتقرير تُرجع النتائج بنفس التنسيق المذكور أعلاه.
$ reportCollection = $ textMarketer -> getDeliveryReportListByName ( ' ReportName ' );
$ from = new DateTimeImmutable ();
$ to = $ from -> modify ( ' -1 week ' );
$ dateRange = new Nessworthy TextMarketer DateRange ( $ from , $ to );
$ reportCollection = $ textMarketer -> getDeliveryReportListByNameAndDateRange ( ' ReportName ' , $ dateRange );
$ from = new DateTimeImmutable ();
$ reportCollection = $ textMarketer -> getDeliveryReportListByNameAndTag ( ' ReportName ' , ' mytag ' );
$ from = new DateTimeImmutable ();
$ to = $ from -> modify ( ' -1 week ' );
$ dateRange = new Nessworthy TextMarketer DateRange ( $ from , $ to );
$ reportCollection = $ textMarketer -> getDeliveryReportListByNameTagAndDateRange ( ' ReportName ' , ' mytag ' , $ dateRange );
جميع الطرق هنا تُرجع مثيلًا لـ NessworthyTextMarketerAccountAccountInformation
. تحتوي هذه الكائنات على بيانات اعتماد API وواجهة برمجة التطبيقات - سيكون من الحكمة عدم ذاكرة التخزين المؤقت أو حفظها بطريقة أخرى كما هي!
$ accountInformation = $ textMarketer -> getAccountInformation ();
echo ' Account ID: ' . $ accountInformation -> getId ();
echo ' <br>Company Name: ' . $ accountInformation -> getCompanyName ();
echo ' <br>Account Created At: ' . $ accountInformation -> getCreatedDate ()-> format ( ' d/m/Y H:i:s ' );
echo ' <br>Remaining Credits: ' . $ accountInformation -> getRemainingCredits ();
echo ' <br>Notification Email: ' . $ accountInformation -> getNotificationEmail ();
echo ' <br>Notification Mobile Number: ' . $ accountInformation -> getNotificationMobile ();
echo ' <br>Account Username: ' . $ accountInformation -> getUiUserName ();
echo ' <br>Account Password: ' . $ accountInformation -> getUiPassword ();
echo ' <br>API Username: ' . $ accountInformation -> getApiUserName ();
echo ' <br>API Password: ' . $ accountInformation -> getApiPassword ();
ملاحظة: يجب كتابة معرف الحساب كسلسلة.
$ accountInformation = $ textMarketer -> getAccountInformationForAccountId ( $ accountId );
ملاحظة: لا توجد طريقة لتحديث معلومات حساب آخر - يجب عليك استخدام بيانات الاعتماد الخاصة بهم.
جميع الحقول الخاصة بـ UpdateAccountInformation
اختياري - تمرير null
عندما لا ترغب في تغيير حقل معين.
تنطبق بعض القيود عند تحديث معلومات حسابك. انظر هنا لما يمكنك استخدامه.
$ newAccountDetails = new Nessworthy TextMarketer Account UpdateAccountInformation (
' uiusername ' , // The new UI Username.
' uipassword ' , // The new UI Password.
' apiusername ' , // The new API Username.
' apipassword ' , // The new API Password.
' Company Name ' , // The new company name.
' [email protected] ' , // The new notification email address.
' 447000000000 ' , // The new notification mobile number.
);
$ updatedAccountInformation = $ textMarketer -> updateAccountInformation ( $ newAccountDetails );
ملاحظة: يتم تعطيل إنشاء حساب جديد افتراضيًا - ستحتاج إلى الاتصال بمقياس النص لتمكين ذلك. مثل تحديث حسابك ، يجب عليك على الأقل تقديم عنوان بريد إلكتروني للإخطار أو رقم هاتف محمول للإخطار
تخضع هذه الحقول لنفس القيود عند تحديث معلومات الحساب.
$ subAccount = new Nessworthy TextMarketer Account CreateSubAccount (
' uiusername ' , // The new account's username
' uipassword ' , // Optional: The new account's password. If null is given, a random password will be generated.
' Company Name ' , // The new account's company name.
' [email protected] ' , // Optional: The new account's notification email address.
' 447000000000 ' , // Optional: The new account's notification mobile number.
false , // Whether to use the same pricing as the parent account.
' PROMOCODE ' // Optional : A promo code for the account if you have one.
);
// All exceptions extend NessworthyTextMarketerTextMarketerException.
try {
// Send a text marketer request.
} catch ( Nessworthy TextMarketer Endpoint EndpointException $ e ) {
// $e->getMessage() and $e->getCode() return the first message & message code.
// Or for all errors...
foreach ( $ e -> getAllEndpointErrors () as $ error ) {
error_log ( sprintf ( ' TextMarketer Message Error: [%s] %s ' , $ error -> getCode (), $ error -> getMessage ()));
}
}