chocoboxxf / yii2-yunpian-sdk
YunPian API for Yii 2.0
Installs: 39
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 2
Forks: 1
Open Issues: 0
Type:yii2-extension
Requires
- php: >=5.4.0
- guzzlehttp/guzzle: ~5.0
- yiisoft/yii2: *
Requires (Dev)
- phpunit/phpunit: >=4.0
This package is not auto-updated.
Last update: 2024-11-09 19:50:59 UTC
README
基于Yii2实现的云片(YunPian)短信API SDK(目前开发中)
环境条件
-
= PHP 5.4
-
= Yii 2.0
-
= GuzzleHttp 5.0
安装
添加下列代码在composer.json
文件中并执行composer update --no-dev
操作
{ "require": { "chocoboxxf/yii2-yunpian-sdk": "dev-master" } }
设置方法
// 全局使用 // 在config/main.php配置文件中定义component配置信息 'components' => [ ..... 'sms' => [ 'class' => 'chocoboxxf\YunPian\YunPianSms', 'apiKey' => '云片网络的APIKEY', ] .... ] // 代码中调用 $result = Yii::$app->sms->send('手机号', '短信内容'); ....
// 局部调用 $sms = Yii::createObject([ 'class' => 'chocoboxxf\YunPian\YunPianSms', 'apiKey' => '云片网络的APIKEY', ]); $result = $sms->send('手机号', '短信内容'); ....
使用示例
发送短信
try { $result = Yii::$app->Sms->send('手机号', '短信内容'); } catch (\chocoboxxf\YunPian\YunPianException $ex) { $code = $ex->getCode(); // 错误码 $message = $ex->getMessage(); // 错误信息 $detail = $ex->getDetail(); // 错误详细信息 }