ghasedak/php
Composer 安装命令:
composer require ghasedak/php
包简介
ghasedak sms gateway package for PHP
README 文档
README
Ghasedak PHP SDK
Easy-to-use SDK for implementing Ghasedak SMS API in your PHP projects.
Explore the docs »
Web Service Documents
·
REST API
.
Report Bug
·
Request Feature
English Document | مستندات فارسی
Table of Contents
Install
The easiest way to install is by using Composer:
composer require ghasedak/php
Composer is a dependency manager for PHP which allows you to declare the libraries your project depends on, and it will manage (install/update) them for you. If you are not familiar with Composer, you can read its documentations and download it via getcomposer.org.
Alternatively you can download Ghasedak SDK from here and extract it in your project and follow the rest of the instructions below. Also there is an Example folder inside the package which you can use to understand the procedure.
usage
To use the API, you need an API key. To get that you should have a Ghasedak account. Register and get your API key.
Then require the file autoload.php to get all classes and dependencies loaded.
require __DIR__ . '/vendor/autoload.php';
Create an instance from Ghasedak class with your API key:
$api = new \Ghasedak\GhasedakApi( 'your_api_key');
Don't forget to change your_api_key with the key you have got from your Ghasedak account.
Send a sms:
$api->SendSimple( "09xxxxxxxxx", // receptor "Hello World!", // message "3000xxxxx" // choose a line number from your account );
Parameters
| Parameter | Required | Description | Type | Example |
|---|---|---|---|---|
| message | Yes | Text to be sent | string | Hello, World! |
| receptor | Yes | The number of the recipient(s) of the message (seperated by comma ,). |
string | 09111111111 |
| linenumber | No | The number of the sender of the message, which, if not specified, will be selected from your dedicated lines with a higher priority.(If you do not have a dedicated line, you must specify the linenumber) |
string | 5000222 |
| senddate | No | The exact date and time of sending the message based on Unix time, if not specified, the message will be sent instantly. | string | 1508144471 |
| checkid | No | It is used to set a unique number for each SMS, and after sending the SMS, all the information of the sent message can be received with the status method. |
string | 2071 |
Example
Here is a sample code for sending SMS. Please note that you must specify linenumber if you don't have a dedicated line.
require __DIR__ . '/vendor/autoload.php'; try{ $message = "Hello, World!"; $lineNumber = null; // If you do not have a dedicated line, you must specify the line number $receptor = "09xxxxxxxxx"; $api = new \Ghasedak\GhasedakApi('api_key'); $api->SendSimple($receptor,$message,$lineNumber); } catch(\Ghasedak\Exceptions\ApiException $e){ echo $e->errorMessage(); } catch(\Ghasedak\Exceptions\HttpException $e){ echo $e->errorMessage(); }
One-Time Passwords (OTP)
The One-Time-Password (OTP) Interface is used to perform a mobile authentication or to implement Two-Factor-Authentication (2FA).
You can pass up to 10 param to Verify method;
$api->setVerifyType(GhasedakApi::VERIFY_TEXT_TYPE)->Verify( "09xxxxxxxxx", // receptor "my-template", // name of the template which you've created in you account "param1", // parameters (supporting up to 10 parameters) "param2", "param3");
Parameters
| Parameter | Required | Description | Type | Example |
|---|---|---|---|---|
| receptor | Yes | The number of the recipient of the message. | string | 09111111111 |
| type | Yes | Set 1 to send text message and 2 to send voice message. |
int | Hello, World! |
| template | Yes | The title of the template you created in your panel. | string | my-template |
| checkid | No | It is used to set a unique number for each SMS, and after sending the SMS, all the information of the sent message can be received with the status method. |
string | 2071 |
| param1 | Yes | The values you enter (You must enter at least one parameter). | string | abcdef |
| param2 | No | The values you enter. | string | abcdef |
| param3 | No | The values you enter. | string | abcdef |
| param4 | No | The values you enter. | string | abcdef |
| param5 | No | The values you enter. | string | abcdef |
| param6 | No | The values you enter. | string | abcdef |
| param7 | No | The values you enter. | string | abcdef |
| param8 | No | The values you enter. | string | abcdef |
| param9 | No | The values you enter. | string | abcdef |
| param10 | No | The values you enter. | string | abcdef |
Example
require __DIR__ . '/vendor/autoload.php'; try{ $receptor = "09xxxxxxxxx"; $type = 1; $template = "my-template"; $param1 = '123456'; $api = new \Ghasedak\GhasedakApi('api_key'); $api->Verify($receptor, $type, $template, $param1); } catch(\Ghasedak\Exceptions\ApiException $e){ echo $e->errorMessage(); } catch(\Ghasedak\Exceptions\HttpException $e){ echo $e->errorMessage(); }
:)
License
Freely distributable under the terms of the MIT license.
فهرست مطالب
نصب
سادهترین راه برای نصب این پکیج استفاده از Composer است:
composer require ghasedak/php
Composer سامانهای برای مدیریت بستههای زبان PHP است که به شما امکان مدیریت (نصب / به روزرسانی) پکیجهای نوشته شده در این زبان را میدهد. اگر با کامپوزر آشنایی ندارید، میتوانید از طریق سایت getcomposer.org مستندات آن را مطالعه و اقدام به بارگیری و نصب آن کنید.
در صورت عدم تمایل به استفاده از کامپوزر، میتوانید پکیج Ghasedak PHP را از اینجا دانلود کرده و محتویات فایل زیپ را درون پروژهی خود استفاده کنید. همچنین پوشهای با نام Example درون پکیج وجود دارد که میتوانید از آن برای یادگیری استفادهی صحیح از پکیج استفاده کنید.
نحوه استفاده
برای استفاده از این پکیج میبایست API key داشته باشید. جهت دریافت ابتدا در سایت قاصدک ثبتنام کنید و از پنل کاربریتان API key دریافت کنید.
سپس باید فایل autoload را به پروژهی خود اضافه کنید:
require __DIR__ . '/vendor/autoload.php';
یک instance از کلاس Ghasedak با API key خود بسازید:
$api = new \Ghasedak\GhasedakApi( 'your_api_key');
به خاطر داشته باشید که your_api_key را با کلید دریافتی از حساب قاصدک خود جایگزین کنید.
پیامک دلخواهتان را ارسال کنید:
$api->SendSimple( "09xxxxxxxxx", // receptor "Hello World!", // message "3000xxxxx" // choose a line number from your account );
پارامترها
| پارامتر | اجباری | توضیحات | نوع | مثال |
|---|---|---|---|---|
| message | بله | متنی که باید ارسال شود. | string | سلام دنیا! |
| receptor | بله | شماره گیرنده پیام می باشد. | string | 09111111111 |
| linenumber | خیر | شماره فرستنده پیام می باشد، که اگر قید نشود از بین خطوط اختصاصی شما خط با اولویت بالاتر انتخاب می شود.( در صورت نداشتن خط اختصاصی باید linenumber را مشخص نمایید ) |
string | 5000222 |
| senddate | خیر | تاریخ و زمان دقیق ارسال پیام بر اساس Unixtime می باشد که اگر قید نشود در همان لحظه پیام ارسال می شود. | string | 1508144471 |
| checkid | خیر | برای تعیین شماره ای یکتا از طرف کاربر برای هر پیامک به کار می رود و پس از ارسال پیامک می توان با متد status کلیه اطلاعات پیام ارسال شده را دریافت کرد. |
string | 2071 |
نمونه کد
کد زیر نمونهای از متد ارسال تکی پیامک میباشد. لطفا توجه کنید که در صورت نداشتن خط اختصاصی میبایست حتما linenumber را وارد کنید.
require __DIR__ . '/vendor/autoload.php'; try{ $message = "Hello, World!"; $lineNumber = null; // If you do not have a dedicated line, you must specify the line number $receptor = "09xxxxxxxxx"; $api = new \Ghasedak\GhasedakApi('api_key'); $api->SendSimple($receptor,$message,$lineNumber); } catch(\Ghasedak\Exceptions\ApiException $e){ echo $e->errorMessage(); } catch(\Ghasedak\Exceptions\HttpException $e){ echo $e->errorMessage(); }
رمز عبور یکبار مصرف (OTP)
رمز عبور یکبار مصرف برای اعتبارسنجی از طریق تلفن همراه و یا برای ورود دو مرحلهای (2FA) استفاده میشود.
با استفاده از متد Verify میتوانید تا سقف 10 param را ارسال کنید:
$api->setVerifyType(GhasedakApi::VERIFY_TEXT_TYPE)->Verify( "09xxxxxxxxx", // receptor "my-template", // name of the template which you've created in you account "param1", // parameters (supporting up to 10 parameters) "param2", "param3");
پارامترها
| پارامتر | اجباری | توضیحات | نوع | مثال |
|---|---|---|---|---|
| receptor | بله | شماره گیرنده پیام که با ( , ) از هم جدا می شوند. | string | 09111111111 |
| type | بله | برای ارسال پیام متنی عدد 1 و برای ارسال پیام صوتی عدد 2 را وارد کنید. |
int | Hello, World! |
| template | بله | عنوان قالبی که در پنل خود ایجاد کرده اید. | string | my-template |
| checkid | خیر | برای تعیین شماره ای یکتا از طرف کاربر برای هر پیامک به کار می رود و پس از ارسال پیامک می توان با متد status کلیه اطلاعات پیام ارسال شده را دریافت کرد |
string | 2071 |
| param1 | بله | مقادیری که از سمت شما وارد می شود (وارد کردن حداقل 1 مورد اجباری است). | string | abcdef |
| param2 | خیر | مقادیری که از سمت شما وارد می شود. | string | abcdef |
| param3 | خیر | مقادیری که از سمت شما وارد می شود. | string | abcdef |
| param4 | خیر | مقادیری که از سمت شما وارد می شود. | string | abcdef |
| param5 | خیر | مقادیری که از سمت شما وارد می شود. | string | abcdef |
| param6 | خیر | مقادیری که از سمت شما وارد می شود. | string | abcdef |
| param7 | خیر | مقادیری که از سمت شما وارد می شود. | string | abcdef |
| param8 | خیر | مقادیری که از سمت شما وارد می شود. | string | abcdef |
| param9 | خیر | مقادیری که از سمت شما وارد می شود. | string | abcdef |
| param10 | خیر | مقادیری که از سمت شما وارد می شود. | string | abcdef |
نمونه کد
require __DIR__ . '/vendor/autoload.php'; try{ $receptor = "09xxxxxxxxx"; $type = 1; $template = "my-template"; $param1 = '123456'; $api = new \Ghasedak\GhasedakApi('api_key'); $api->Verify($receptor, $type, $template, $param1); } catch(\Ghasedak\Exceptions\ApiException $e){ echo $e->errorMessage(); } catch(\Ghasedak\Exceptions\HttpException $e){ echo $e->errorMessage(); }
مجوز
این پکیج تحت مجوز MIT منتشر شده است.
ghasedak/php 适用场景与选型建议
ghasedak/php 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 45.21k 次下载、GitHub Stars 达 20, 最近一次更新时间为 2019 年 04 月 20 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「api」 「sms」 「notification」 「sms-gateway」 「Ghasedak」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 ghasedak/php 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 ghasedak/php 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 ghasedak/php 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
This package makes it easy to send notifications via AfricasTalking with Laravel
Apple Push Notification & Feedback Provider
A PSR-7 compatible library for making CRUD API endpoints
Throttle notifications on a per-channel basis
SDK for payment gateway PlatbaMobilom.sk for PHP7.0
Extensible library for building notifications and sending them via different delivery channels.
统计信息
- 总下载量: 45.21k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 20
- 点击次数: 33
- 依赖项目数: 8
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2019-04-20