weezqydy / sematimeapi
Requires
- php: >=5.5.9
- nategood/httpful: *
- vlucas/phpdotenv: ^2.1
This package is auto-updated.
Last update: 2022-02-01 13:02:15 UTC
README
这是一个PHP包,您可以将它轻松集成到项目中以使用Sematime API发送短信消息。要开始使用此包,请使用Composer(PHP依赖管理工具)在项目中引入它。如果您还没有安装Composer,请访问Composer并进行安装。
要将此包添加到您的项目中,请将以下内容添加到您的composer.json文件中,然后运行composer update。
{
"require": {
"weezqydy/sematimeapi": "~1.0"
}
}
简介
Sematime API使您能够从PHP应用程序发送品牌化和个性化的短信消息。此外,API还公开了联系人管理功能,允许您代表用户存储、编辑或删除联系人。
在您开始使用API之前,我们需要您完成以下操作:
创建免费Sematime账户
在您开始使用我们的API之前,需要一个Sematime账户。如果您还没有Sematime账户,请访问Sematime并创建一个账户。
获取API凭证
- 要与sematime API交互,您需要拥有API密钥和Sematime账户的用户ID。我们使用这些凭证来验证您的请求。
- 登录您的Sematime账户,然后点击右上角的“我的账户”下拉菜单,选择“API集成”,然后点击“生成密钥”。您将获得一个32字符长的API密钥以及相应的用户ID。
入门
- 现在在项目的根目录下创建一个新的文件,命名为.env
- 在您刚刚创建的文件中,添加您的API密钥和用户ID,如下所示:
API_KEY = "your-sematime-api-key"
USER_ID = "user-id-from-sematime"
消息
发送消息
在一切配置正确后,我们现在可以开始使用sematime发送第一条消息。
// Include the composer autoloader if its not included yet require __DIR__.'/vendor/autoload.php'; use Sematime\Api\Sematime; // An Array of recipients $recipients = ['1234567890','0987654321','6789054321']; // Initialize The Sematime Api $gateway = new Sematime(); //Create Your Message $message='A nice message send using Sematime'; $results = $gateway->AddTo($recipients)->message($message)->send(); // if evrything goes well you will get a response from Sematime echo $results;
在构建消息时,您可以可选地添加其他参数。
- salutation() - 一个可选参数,其值是使用的问候语类型。如果提供,每个收件人将收到一条个性化的消息,以问候语开头,然后是他们的名字。例如:尊敬的Admin,尊敬的Lucy,尊敬的Jean等,在这种情况下,问候语是单词“Dear”。
//you can chain the parameters in any order $sema->message('message to send')->addTo(['1234567890'])->salutation('Dear')->send();
-
signature() - 一个可选参数,其值是附加在您发送的所有消息末尾的唯一消息。例如,由Sematime团队发送。拨打0706129100。
-
scheduledTime() - 一个可选参数,其值是在未来的日期发送消息的日期和时间(毫秒)。
-
senderId() - 一个可选参数,其值是用于发送消息的发送者ID/品牌。如果没有指定,将使用您的Sematime账户的发送者ID。
-
callbackUrl() – 可选参数,其值是我们发送计划消息后传递投递报告时要调用的URL。所有回调都通过HTTP POST调用。
-
extra() – 包含您可能需要传递给我们API以供系统后续处理的额外参数的可选参数。例如,账户号码、用户ID等。我们不处理这些参数,在调用您的回调时将它们传递给您。
// all these methods are chainable $sema->signature('Sent by The Sematime team. Call 0706129100') ->senderId('Sematime') // Use this option only if you have an existing ID ->scheduledTime('1466683660000') // Must be a future timestamp ->callbackUrl('https://api.mydomain.com/callback') // must be an existing and Valid URL ->extra('extra=extra data') // Only accepts strings ->addTo(array('1234567890')) // addTo expects an array of recipients ->message('an awesome message') ->send(); // send the message
获取计划消息
要检索计划消息
$sema = new Sematime\Api\Sematime(); $scheduled= $sema->getAllScheduled(); // returns the first 20 scheduled messages /* retrieve more scheduled messages or retrieve from a certain point.*/ $startFrom = 15; $fetch=40; // retrieves 40 messages starting form the 15th $scheduled= $sema->getAllScheduled($fetch, $startFrom); print $scheduled;
联系人
Sematime 将联系人组织成组。一个组通常包含具有某些关系的联系人。例如,“销售团队”组将是公司销售团队成员的组。
添加联系人
我们还可以将联系人添加到您的 Sematime 账户中,只需准备好您的联系人并保存即可。
require __DIR__.'/vendor/autoload.php'; use Sematime\Api\Sematime; // Initialize The Sematime Api $sema = new Sematime(); $response=$sema->groupName('My Group') // the group name you wish to add contacts ->addId('1') // contact id for the contact you want to add ->addName('John Doe') // a name for your contact ->addPhone('1234567890') // phone number you wish to add ->save(); // finally save your contact print $response; // {"statusCode":200, "description":"Contacts added successfully.","totalContacts":1, "contactsAdded":1}
检索联系人
- 从组中获取联系人 - 提供您要检索的联系人所在的组名
use Sematime/Api/Sematime; $sema= new Sematime(); $group = 'My Group'; // The group you want to get contacts; $contacts= $sema->getGroupContacts($group); // you will get a json formated string of your contacts
- 从组中获取单个联系人 - 将 contactId 作为第一个参数传递,然后传递 groupName
use Sematime/Api/Sematime; $sema= new Sematime(); $group = 'My Group'; // The group you want to get contacts; $contactId= '14578652'; $contacts= $sema->getContacts($contactId, $group); // you will get a json formated string of the contact
编辑联系人
要编辑您的联系人,您只需提供该联系人的新名字或新电话号码即可。
use Semamatime/Api/Sematime; $sema= new Sematime(); $contactId = '145367'; // provide the contact id to edit this required $groupName = 'My Group'; // The group in which the contact exists this is required $newName = 'David Clerk'; // New name for contact optional $newPhoneNumber = '1234567890'; // New phone Number to the contact, optional $response= $sema->editContact($constactId, $group, $newName, $newPhoneNumber); echo $response; // Contact updated successfully. ``` #### Deleting Contacts Deleting a contact only requires you to provide the group and ID of the contact you wish to delete ```php use Semamatime/Api/Sematime; $sema= new Sematime(); $contactId = '145367'; // provide the contact id to edit this required $groupName = 'My Group'; // The group in which the contact exists this is required $response = $sema->deleteContact($contactId, $group); echo $response; // Contact Deleted successfully ``` #### Account details To retrieve your account details ```php use Semamatime/Api/Sematime; $sema= new Sematime(); $response = $sema->accountDetails(); echo $response //{"account":{"accountId":"xxxxxxxxxxxxx", "name":"Your Name", "phoneNumber":"123456789", "smsBalance":0, "accountType":"school", "senderId":"Sematime", "paymentPlan":"prepaid", "createdOn":"Wed, 09\/09\/2015 04:59 PM"}, "statusCode":200, "description":"Account profile retrieved successfully."}