kavenegar/laravel
Composer 安装命令:
composer require kavenegar/laravel
包简介
laravel 4 and 5 kavenegar integration
关键字:
README 文档
README
First of all you will ned an API Key . You can get one Here.
Supported Laravel Versions:
- V.4
- V.5
- V.6
- V.7
- V.8
- V.9
- V.10
We highly recomment you to always use the latest version of laravel
Installation
Step 1 - Install the package
- Method 1: You can install kavenegar/laravel with Composer directly in your project:
composer require kavenegar/laravel
- Method 2: Add this line to Composer.json file in your project
"kavenegar/php": "*"
Then run following command to download extension using composer
$ composer update
Step 2
Head to config/app.php and add this line to the end of providers Array:
Kavenegar\Laravel\ServiceProvider::class,
So that array must me something like this:
'providers' => [ /* * Laravel Framework Service Providers... */ . . . Kavenegar\Laravel\ServiceProvider::class ]
Then in the config/app.php and add this line to the end of aliases Array:
'Kavenegar' => Kavenegar\Laravel\Facade::class,
Step 3 - Publish
Run this command in your project dirctory:
php artisan vendor:publish
In the message appear, find the number of Kavenegar, enter the related number then hit Enter. for Example in the below case you must enter 9 then enter:
Which provider or tag files would you like to publish?: [0 ] Publish files from all providers and tags listed below [1 ] Provider: Facade\Ignition\IgnitionServiceProvider [2 ] Provider: Fideloper\Proxy\TrustedProxyServiceProvider [3 ] Provider: Fruitcake\Cors\CorsServiceProvider [4 ] Provider: Illuminate\Foundation\Providers\FoundationServiceProvider [5 ] Provider: Illuminate\Mail\MailServiceProvider [6 ] Provider: Illuminate\Notifications\NotificationServiceProvider [7 ] Provider: Illuminate\Pagination\PaginationServiceProvider **_ [8 ] Provider: Kavenegar\Laravel\ServiceProviderLaravel9_** . . .
Step 4 - Api-Key
Now you must define your API Key to project. for this head to config/kavenegar.php then put your API KEY in the code:
<?php
return [
'apikey' => ' ',
];
All Set
Usage
You can use the package where ever you want.
- First use the class:
use Kavenegar;
Then use this pattern to send SMS:
try{ $sender = "10004346"; //This is the Sender number $message = "خدمات پیام کوتاه کاوه نگار"; //The body of SMS $receptor = array("09361234567","09191234567"); //Receptors numbers $result = Kavenegar::Send($sender,$receptor,$message); if($result){ foreach($result as $r){ echo "messageid = $r->messageid"; echo "message = $r->message"; echo "status = $r->status"; echo "statustext = $r->statustext"; echo "sender = $r->sender"; echo "receptor = $r->receptor"; echo "date = $r->date"; echo "cost = $r->cost"; } } } catch(\Kavenegar\Exceptions\ApiException $e){ // در صورتی که خروجی وب سرویس 200 نباشد این خطا رخ می دهد echo $e->errorMessage(); } catch(\Kavenegar\Exceptions\HttpException $e){ // در زمانی که مشکلی در برقرای ارتباط با وب سرویس وجود داشته باشد این خطا رخ می دهد echo $e->errorMessage(); }catch(\Exceptions $ex){ // در صورت بروز خطایی دیگر echo $ex->getMessage() }
Use this pattern to send VerifyLookup SMS:
try{ $receptor = "09123456789"; $token = "123"; $token2 = "456"; $token3 = "789"; $template="verify"; //Send null for tokens not defined in the template //Pass token10 and token20 as parameter 6th and 7th $result = Kavenegar::VerifyLookup($receptor, $token, $token2, $token3, $template, $type = null); if($result){ foreach($result as $r){ echo "messageid = $r->messageid"; echo "message = $r->message"; echo "status = $r->status"; echo "statustext = $r->statustext"; echo "sender = $r->sender"; echo "receptor = $r->receptor"; echo "date = $r->date"; echo "cost = $r->cost"; } } } catch(\Kavenegar\Exceptions\ApiException $e){ // در صورتی که خروجی وب سرویس 200 نباشد این خطا رخ می دهد echo $e->errorMessage(); } catch(\Kavenegar\Exceptions\HttpException $e){ // در زمانی که مشکلی در برقرای ارتباط با وب سرویس وجود داشته باشد این خطا رخ می دهد echo $e->errorMessage(); }
You can find all the Error handlings and API parameters and Usage methods in the KaveNegar website.
Usage in Notifications
Also you can use KavengarChannel for your notification:
create your notification:
php artisan make:notification InvoicePaid
extend your notification from KavenegarBaseNotification:
class InvoicePaid extends KavenegarBaseNotification { }
overide the toKavengar function:
class InvoicePaid extends KavenegarBaseNotification { public function __construct(Invoice $invoice) { $this->invoice = $invoice; } public function toKavenegar($notifiable) { return (new KavenegarMessage("فاکتور شما به شماره $invoice->id پرداخت شد."))->from('10004346'); } }
you should add Notifiable trait and routeNotificationForKavenegar method in your model
class User extends Authenticatable { use Notifiable; public function routeNotificationForKavenegar($driver, $notification = null) { return $this->mobile; } }
** Notice: IF you DO NOT add routeNotificationForKavenegar in your notifiable model then you should set your receiver in your notification : **
class InvoicePaid extends KavenegarBaseNotification { public function toKavenegar($notifiable) { return (new KavenegarMessage('فاکتور شما به شماره ۱۲۳۴ پرداخت شد.'))->from('10004346')->to('092100000'); } }
for send verify lookup message you should use verifyLookup method for set method name and tokens:
class InvoicePaid extends KavenegarBaseNotification { public function toKavenegar($notifiable) { return (new KavenegarMessage()) ->verifyLookup('verify_first',['token1','token2']); } }
Contribution
Bug fixes, docs, and enhancements welcome! Please let us know support@kavenegar.com
## راهنمامعرفی سرویس کاوه نگار
کاوه نگار یک وب سرویس ارسال و دریافت پیامک و تماس صوتی است که به راحتی میتوانید از آن استفاده نمایید.
ساخت حساب کاربری
اگر در وب سرویس کاوه نگار عضو نیستید میتوانید از لینک عضویت ثبت نام و اکانت آزمایشی برای تست API دریافت نمایید.
مستندات
برای مشاهده اطلاعات کامل مستندات وب سرویس پیامک به صفحه مستندات وب سرویس مراجعه نمایید.
راهنمای فارسی
در صورتی که مایل هستید راهنمای فارسی کیت توسعه کاوه نگار را مطالعه کنید به صفحه کد ارسال پیامک مراجعه نمایید.
اطالاعات بیشتر
برای مطالعه بیشتر به صفحه معرفی وب سرویس اس ام اس کاوه نگار مراجعه نمایید .
اگر در استفاده از کیت های سرویس کاوه نگار مشکلی یا پیشنهادی داشتید ما را با یک Pull Request یا ارسال ایمیل به support@kavenegar.com خوشحال کنید.
kavenegar/laravel 适用场景与选型建议
kavenegar/laravel 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 346.63k 次下载、GitHub Stars 达 85, 最近一次更新时间为 2016 年 10 月 18 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「api」 「sms」 「laravel」 「kavenegar」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 kavenegar/laravel 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 kavenegar/laravel 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 kavenegar/laravel 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A PSR-7 compatible library for making CRUD API endpoints
SDK for payment gateway PlatbaMobilom.sk for PHP7.0
Extensible library for building notifications and sending them via different delivery channels.
yii2-sms expand
Alfabank REST API integration
A fork of simplesoftwareio/simple-sms with Verimor driver.
统计信息
- 总下载量: 346.63k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 87
- 点击次数: 13
- 依赖项目数: 11
- 推荐数: 1
其他信息
- 授权协议: MIT
- 更新时间: 2016-10-18