Download the PHP package mikecai/php-sms without Composer

On this page you can find all versions of the php package mikecai/php-sms. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package php-sms

PhpSms

StyleCI Build Status Latest Stable Version Total Downloads

可能是目前最聰明,優雅的PHP簡訊發送庫了。

phpsms的任務均衡調度功能由toplan/task-balancer提供。

特色

服务商

服務商 模板簡訊 内容簡訊 語音驗證碼 最低消费 最低消费單價
Every8D × × NT 8000(1萬條) NT0.8/條
亞太企業簡訊(舊) × × (不提供) (不提供)
亞太企業簡訊(新-暫不提供) × × NT 8000(1萬條) NT0.8/條

安装

开发中版本

快速上手

1. 配置

為你需要用到的簡訊服務商(即代理器)配置必要的參數。可以在config\phpsms.php中鍵為agents的數組中配置,也可以手動在程序中設置,示例如下:

可在config\phpsms.php中鍵為scheme的數組中配置。也可以手動在程序中設置,示例如下:

調度方案解析: 如果按照以上配置,那麼系統首次會嘗試使用Every8dAptgXsms發送簡訊,且它們被使用的概率分別為2/31/3。 如果使用其中一個代理器發送失敗,那麼會啟用備用代理器,按照配置可知備用代理器有SmsBaoSmsBao,那麼會依次調用直到發送成功或無備用代理器可用。 值得注意的是,如果首次嘗試的是AptgXsms,那麼備用代理器將會只使用SmsBao,也就是會排除使用過的代理器。

2. Enjoy it!

3. 在laravel和lumen中使用

生成的配置文件為config/phpsms.php,然後在該文件中按提示配置。

詳見API,示例:

API

API - 全局配置

Sms::scheme([$name[, $scheme]])

設置/獲取代理器的調度方案。

調度配置支持熱更新,即在應用系統的整個運行過程中都能隨時修改。

手動設置代理器調度方案(優先級高於配置文件),如:

通过该方法还能获取所有或指定代理器的调度方案,如:

scheme静态方法的更多使用方法见高级调度配置

Sms::config([$name[, $config][, $override]]);

设置/获取代理器的配置数据。

参数配置支持热更新,即在应用系统的整个运行過程中都能随时修改。

手动设置代理器的配置数据(优先级高于配置文件),如:

通過該方法還能獲取所有或指定代理器的配置參數,如:

Sms::beforeSend($handler[, $override]);

發送前鉤子,示例:

更多細節請查看 task-balancerbeforeRun 鉤子

Sms::beforeAgentSend($handler[, $override]);

代理器發送前鉤子,示例:

更多細節請查看 task-balancerbeforeDriverRun 鉤子

Sms::afterAgentSend($handler[, $override]);

代理器發送后鉤子,示例:

更多細節請查看 task-balancerafterDriverRun鉤子

Sms::afterSend($handler[, $override]);

發送後鉤子,示例:

更多細節請查看 task-balancerafterRun 鉤子

Sms::queue([$enable[, $handler]])

該方法可以設置是否啟用鹼性以及定義如何推進到位數。

$handler匿名函数可使用的参数:

定义如何推送到队列:

如果已經定義過如何推送到隊列,還可以繼續設置關閉/開啟隊列:

获取队列启用情况:

API - 發送相关

Sms::make()

生成發送簡訊的sms实例,并返回实例。

Sms::status()->query($batchId)->send();

查詢簡訊發送狀態

Sms::voice()

生成發送语音驗證碼的sms实例,并返回实例。

下方為大陸服務,參考就好

  • 如果你使用Luosimao语音驗證碼,还需用在配置文件中Luosimao选项中设置voiceApikey
  • 语音文件ID即是在服务商配置的语音文件的唯一编号,比如阿里大鱼语音通知voice_code
  • 模版语音是另一种语音请求方式,它是通过模版ID和模版数据进行的语音请求,比如阿里大鱼的文本转语音通知

type($type)

设置实例类型,可选值有Sms::TYPE_SMSSms::TYPE_VOICE(台灣簡訊沒支援),返回实例对象。

to($mobile)

设置發送给谁,并返回實例。

data($key, $value)

设置模板簡訊的模板数据,并返回实例对象。

通過data方法的組合除了可以實現模版簡訊的數據填充,還可以實現模版語音的數據填充。

content($text)

设置内容簡訊的内容,并返回实例对象。

一些内置的代理器(如SmsBao、YunPian、Luosimao)使用的是内容簡訊(即直接發送簡訊内容),那么就需要为它们设置簡訊内容。

params($agentName, $params)

直接设置参数到服务商提供的原生接口上,并返回实例对象。

all([$key])

获取Sms实例中的簡訊数据,不带参数时返回所有数据,其结构如下:

agent($name)

临时设置發送时使用的代理器(不会影响备用代理器的正常使用),并返回实例,$name为代理器名称。

通过该方法设置的代理器将获得绝对优先权,但只对当前簡訊实例有效。

send()

请求發送簡訊/语音驗證碼。

$result数据结构请参看task-balancer

自定义代理器

可将配置项(如果有用到)加入到config/phpsms.php中键为agents的数组里。

新建一个继承Toplan\PhpSms\Agent抽象类的代理器类,建议代理器类名为FooAgent,建议命名空间为Toplan\PhpSms

如果类名不为FooAgent或者命名空间不为Toplan\PhpSms,在使用该代理器时则需要指定代理器类,详见高级调度配置。

实现相应的接口,可选的接口有:

接口 说明
ContentSms 發送内容簡訊
TemplateSms 發送模版簡訊
VoiceCode 發送语音驗證碼
ContentVoice 發送内容语音
TemplateVoice 發送模版语音
FileVoice 發送文件语音

高级调度配置

代理器的高级调度配置可以通过配置文件(config/phpsms.php)中的scheme项目配置,也可以通过scheme静态方法设置。 值得注意的是,高级调度配置的值的数据结构是数组。

指定代理器类

如果你自定义了一个代理器,类名不为FooAgent或者命名空间不为Toplan\PhpSms, 那么你还可以在调度配置时指定你的代理器使用的类。

通过配置值中agentClass键来指定类名。

寄生代理器

如果你既不想使用內置的代理器,也不想創建文件寫自定義代理器,那麼寄生代理器或許是個好的選擇, 無需定義代理器類,只需在調度配置時定義好發送簡訊和語音驗證碼的方式即可。

可以配置的發送過程有:

發送過程 参数列表 说明
sendContentSms $agent, $to, $content 發送内容簡訊
sendTemplateSms $agent, $to, $tmpId, $tmpData 發送模版簡訊
sendVoiceCode $agent, $to, $code 發送语音驗證碼
sendContentVoice $agent, $to, $content 發送内容语音
sendTemplateVoice $agent, $to, $tmpId, $tmpData 發送模版语音
sendFileVoice $agent, $to, $fileId 發送文件语音

Todo

License

MIT


All versions of php-sms with dependencies

PHP Build Version
Package Version
Requires php Version >=5.4.0
toplan/task-balancer Version ~0.5
jeremeamia/superclosure Version ~2.2
sabre/xml Version ^1.4.2
sabre/uri Version ^1.2.1
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package mikecai/php-sms contains the following files

Loading the files please wait ....