joshuachinemezu / smsglobal-laravel
用于集成SmsGlobal的Laravel包
v0.1.0
2020-05-30 19:31 UTC
Requires
- php: ^7.3
- guzzlehttp/guzzle: 5.*|6.*
- illuminate/support: ^5.0|^6.0|^7.0|^8.0
Requires (Dev)
- mockery/mockery: ^1.4@dev
- orchestra/testbench: ^6.0@dev
- phpunit/phpunit: ^9.2@dev
This package is auto-updated.
Last update: 2024-09-29 05:22:27 UTC
README
Laravel 5、6和7版本的SmsGlobal包
用于无缝集成SmsGlobal的Laravel包
安装
需要PHP 5.4+或HHVM 3.3+,Laravel 5.6+,以及Composer。
要获取SmsGlobal Laravel的最新版本,只需要求它。
composer require joshuachinemezu/smsglobal-laravel
或者将以下行添加到您的`composer.json`文件的`require`块中。
"joshuachinemezu/smsglobal-laravel": "^0.1.*"
然后,您需要运行`composer install`或`composer update`来下载它并更新自动加载器。
一旦安装了包,您需要注册服务提供者。打开`config/app.php`,并将以下内容添加到`providers`键。
'providers' => [ ... JoshuaChinemezu\SmsGlobal\SmsGlobalServiceProvider::class, ... ]
如果您使用的是Laravel >= 5.5,您可以跳过此步骤并转到
配置。
JoshuaChinemezu\SmsGlobal\SmsGlobalServiceProvider::class
同时,注册Facade如下所示
'aliases' => [ ... 'SmsGlobal' => JoshuaChinemezu\SmsGlobal\Facades\SmsGlobal::class, ... ]
配置
您可以使用此命令发布配置文件
php artisan vendor:publish --provider="JoshuaChinemezu\SmsGlobal\SmsGlobalServiceProvider"
一个名为`smsglobal.php`的配置文件,其中包含默认值,将被放置在您的`config`目录中
<?php return [ /** * Hash algorithm to use with hash_hmac. Use hash_algos() to get a list of * supported algos. SMSGlobal uses sha256 */ 'hashAlgo' => env('SMSGLOBAL_HASH_ALGO', 'sha256'), /** * API Key: Your SmsGlobal APIKey. Get it from https://mxt.smsglobal.com/integrations * */ 'apiKey' => env('SMSGLOBAL_API_KEY'), /** * Secret Key: Your SmsGlobal secretKey. Sign up on https://www.smsglobal.com/mxt-sign-up/ to get one from your integrations page * */ 'secretKey' => env('SMSGLOBAL_SECRET_KEY'), /** * Host name * */ 'host' => env('SMSGLOBAL_HOST', 'api.smsglobal.com'), /** * Protocol * */ 'protocol' => env('SMSGLOBAL_PROTOCOL', 'https'), /** * Port * */ 'port' => env('SMSGLOBAL_PORT', 443), /** * API Version * */ 'apiVersion' => env('SMSGLOBAL_API_VERSION', 'v2'), /** * Debug mode * */ 'debug' => env('SMSGLOBAL_DEBUG', false), ];
用法
打开您的`.env`文件,并添加您的API密钥和密钥,这些密钥可以从SmsGlobal集成页面生成
SMSGLOBAL_API_KEY=xxxxxxxxxxxxx SMSGLOBAL_SECRET_KEY=xxxxxxxxxxxxx
如果您正在使用像Heroku这样的托管服务,请记住将以上详细信息添加到您的配置变量中。
<?php namespace App\Http\Controllers; use Illuminate\Http\Request; use App\Http\Requests; use App\Http\Controllers\Controller; use JoshuaChinemezu\SmsGlobal\RestApi\RestApiClient; class SmsController extends Controller { /** * Get * @return json */ public function getSmsGlobalDedicatedNumbers() { $smsglobal = new RestApiClient; return $smsglobal->getAllDedicatedNumbers(); } /** * This method can be implemented in a Queue - this is just an example * @return json */ public function sendSms() { $smsglobal = new RestApiClient; return $smsglobal->sendMessage([ "destination" => "xxxx", // Destination mobile number. 3-15 digits "message" => "Hello", // The SMS message. If longer than 160 characters (GSM) or 70 characters (Unicode), splits into multiple SMS ]); // Check https://www.smsglobal.com/rest-api/ for more options } }
此包提供的方法的解释。
<?php /** * Get the auto top-up information associated to the authenticated account. */ $smsglobal->getAutoTopUpInfo(); /** * Alternatively, use the helper. */ smsglobal()->getAutoTopUpInfo(); /** * Delete a contact * @param integer $id * @return json */ $smsglobal->deleteContact($id); /** * Alternatively, use the helper. */ smsglobal()->deleteContact($id); /** * Get the contact as identified by the given id. * @param integer $id * @return json */ $smsglobal->getContactByID($id); /** * Alternatively, use the helper. */ smsglobal()->getContactByID($id); /** * Update the contact as identified by the given id. You can only update the * default fields associated with each contact. * @param integer $id * @return json */ $smsglobal->updateContactByID($id); /** * Alternatively, use the helper. */ smsglobal()->updateContactByID($id); /** * Get a list of all contact groups. * @param array $queryOptions * See https://www.smsglobal.com/rest-api/ - /v2/group - GET * @return json */ $smsglobal->getAllContactGroups($queryOptions); /** * Alternatively, use the helper. */ smsglobal()->getAllContactGroups($queryOptions); /** * Create a new contact group. * @param array $formData * See https://www.smsglobal.com/rest-api/ - /v2/group - POST * @return json * $formData = [ * "name" => "Joshua Group", * "keyword" => "smsgroup", * "defaultOrigin" => "", * "isGlobal" => false, * ] */ $smsglobal->createContactGroup($formData); /** * Alternatively, use the helper. */ smsglobal()->createContactGroup($formData); /** * Create a new contact group. * @param integer $groupId * @param array $formData * @return json * $formData = [ * "msisdn" => "Joshua Contact", * "givenName" => "Joshua", * See on https://www.smsglobal.com/rest-api/ - group/{groupId}/contact - POST * ] */ $smsglobal->createContact($groupId, $formData); /** * Alternatively, use the helper. */ smsglobal()->createContact($groupId, $formData); /** * Get a list of all contacts in a group. * @param integer $groupId * @param array $filters * @return json * $filters = [ * "offset" => 1, * "limit" => 20, * "sort" => "id" * ] */ $smsglobal->getContactsByGroupID($groupId, $filters); /** * Alternatively, use the helper. */ smsglobal()->getContactsByGroupID($groupId, $filters); /** * Delete a contact group * @param integer $id * @return json */ $smsglobal->deleteContactGroup($id); /** * Alternatively, use the helper. */ smsglobal()->deleteContactGroup($id); /** * Get the contact group as identified by the given id. * @param integer $id * @return json */ $smsglobal->getContactGroupByID($id); /** * Alternatively, use the helper. */ smsglobal()->getContactGroupByID($id); /** * Update fields of a group as identified by the given id * @param integer $id * @param array $param * $param = [ * "name" => "Joshua Group", * "keyword" => "", * ... More options on https://www.smsglobal.com/rest-api/ * ] * @return json */ $smsglobal->updateGroupFieldByID($id, $param); /** * Alternatively, use the helper. */ smsglobal()->updateGroupFieldByID($id, $param); /** * View list of dedicated numbers * @return json */ $smsglobal->getAllDedicatedNumbers(); /** * Alternatively, use the helper. */ smsglobal()->getAllDedicatedNumbers(); /** * View list of opted out numbers * @param array $filters * $filters = [ * "phoneNumber" => xxx, * "offset" => 1, * "limit" => 20, * ] * @return json */ $smsglobal->getAllOptedOutNumbers($filters); /** * Alternatively, use the helper. */ smsglobal()->getAllOptedOutNumbers($filters); /** * Opt out mobile numbers * @param array $mobileNumbers * $mobileNumbers = [xxx. xxx, xxx] * @return json */ $smsglobal->optOutMobileNumbers($mobileNumbers); /** * Alternatively, use the helper. */ smsglobal()->optOutMobileNumbers($mobileNumbers); /** * Validate mobile numbers for opt out * @param array $mobileNumbers * $mobileNumbers = [xxx. xxx, xxx] * @return json */ $smsglobal->validateOptOutMobileNumbers($mobileNumbers); /** * Alternatively, use the helper. */ smsglobal()->validateOptOutMobileNumbers($mobileNumbers); /** * Opt in a mobile number * @param integer $mobileNumber * $mobileNumbers = xxx * @return json */ $smsglobal->optInMobileNumber($mobileNumber); /** * Alternatively, use the helper. */ smsglobal()->optInMobileNumber($mobileNumber); /** * Opt in a mobile number * @param integer $mobileNumber * $mobileNumbers = xxx * @return json */ $smsglobal->optInMobileNumber($mobileNumber); /** * Alternatively, use the helper. */ smsglobal()->optInMobileNumber($mobileNumber); /** * View list of shared pools * @return json */ $smsglobal->getAllSharedPools(); /** * Alternatively, use the helper. */ smsglobal()->getAllSharedPools(); /** * View details of a shared pool * @param integer $id * @return json */ $smsglobal->getSharedPoolByID($id); /** * Alternatively, use the helper. */ smsglobal()->getSharedPoolByID($id); /** * View list of outgoing messages * @param array $filters * $filters = [ * "offset" => 1, * "limit" => 20, * "status" => "delivered", * ... More option https://www.smsglobal.com/rest-api/ - /v2/sms - GET * ] * @return json */ $smsglobal->getAllOutGoingMessage($filters); /** * Alternatively, use the helper. */ smsglobal()->getAllOutGoingMessage($filters); /** * View list of outgoing messages * @param array $postData * $postData = [ * "message" => "Hello", * ... More option https://www.smsglobal.com/rest-api/ - /v2/sms - POST * ] * @return json */ $smsglobal->sendMessage($postData); /** * Alternatively, use the helper. */ smsglobal()->sendMessage($postData); /** * Delete outgoing message * @param integer $id * @return json */ $smsglobal->deleteOutGoingMessage($id); /** * Alternatively, use the helper. */ smsglobal()->deleteOutGoingMessage($id); /** * View details of an outgoing message * @param integer $id * @return json */ $smsglobal->getOutGoingMessageByID($id); /** * Alternatively, use the helper. */ smsglobal()->getOutGoingMessageByID($id); /** * View list of incoming messages * @param arrray $filters' * $filters = [ * "offset" => 1, * "limit" => 20, * ... More option https://www.smsglobal.com/rest-api/ - /v2/sms-incoming - GET * ] * @return json */ $smsglobal->getAllIncomingMessage($filters); /** * Alternatively, use the helper. */ smsglobal()->getAllIncomingMessage($filters); /** * View list of incoming messages * @param arrray $filters' * $filters = [ * "offset" => 1, * "limit" => 20, * ... More option https://www.smsglobal.com/rest-api/ - /v2/sms-incoming - GET * ] * @return json */ $smsglobal->getAllIncomingMessage($filters); /** * Alternatively, use the helper. */ smsglobal()->getAllIncomingMessage($filters); /** * Delete incoming message * @param integer $id * @return json */ $smsglobal->deleteIncomingMessage($id); /** * Alternatively, use the helper. */ smsglobal()->deleteIncomingMessage($id); /** * View details of an incoming message * @param integer $id * @return json */ $smsglobal->getIncomingMessageByID($id); /** * Alternatively, use the helper. */ smsglobal()->getIncomingMessageByID($id); /** * Get the authenticated account's billing details. * @return json */ $smsglobal->getBillingDetails(); /** * Alternatively, use the helper. */ smsglobal()->getBillingDetails(); /** * Update the authenticated account's billing details. * @param array $params * See https://www.smsglobal.com/rest-api/ - /v2/user/billing-details - PUT * @return json */ $smsglobal->updateBillingDetails($params); /** * Alternatively, use the helper. */ smsglobal()->updateBillingDetails($params); /** * Get the authenticated account's contact details. * @return json */ $smsglobal->getContactDetails(); /** * Alternatively, use the helper. */ smsglobal()->getContactDetails(); /** * Get the authenticated account's billing details. * @param array $params * See https://www.smsglobal.com/rest-api/ - /v2/user/billing-details - PUT * @return json */ $smsglobal->updateContactDetails($params); /** * Alternatively, use the helper. */ smsglobal()->updateContactDetails($params); /** * View the account balance * @return json */ $smsglobal->getBalance(); /** * Alternatively, use the helper. */ smsglobal()->getBalance(); /** * Get the low balance alerts information associated to the authenticated * account. * * @return json */ $smsglobal->getLowBalanceAlert(); /** * Alternatively, use the helper. */ smsglobal()->getLowBalanceAlert(); /** * Update the authenticated account's low balance alerts information. * @param array $params * See https://www.smsglobal.com/rest-api/ - /v2/user/low-balance-alerts - PUT * * @return json */ $smsglobal->updateLowAlertBalance($params); /** * Alternatively, use the helper. */ smsglobal()->updateLowAlertBalance($params); /** * Create sub account * @param array $params * See https://www.smsglobal.com/rest-api/ - /v2/user/low-balance-alerts - POST * * @return json */ $smsglobal->createSubAccount($params); /** * Alternatively, use the helper. */ smsglobal()->createSubAccount($params); /** * Get the authenticated account's verified numbers. * @param array $params * See https://www.smsglobal.com/rest-api/ - /v2/user/verified-numbers - GET * * @return json */ $smsglobal->getVerifiedNumbers($params); /** * Alternatively, use the helper. */ smsglobal()->getVerifiedNumbers($params);
待办事项
- 添加SMPP
- 添加SOAP
- 添加MMS API
- 添加WhatsApp API
- 添加队列和跟踪发出的短信
- 添加综合测试
贡献
请随意将该包分支出来,并通过提交拉取请求来增强功能进行贡献。
如何赞赏这个包?
为什么不给github存储库加星标?我会很高兴得到关注!传播这个消息!
别忘了在推特上关注我!
许可证
© MIT许可证(MIT)请参阅许可证文件以获取更多信息。
由Joshua Chinemezu用❤️制作