PHP code example of dcb9 / yii2-yunpian

1. Go to this page and download the library: Download dcb9/yii2-yunpian library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

dcb9 / yii2-yunpian example snippets


\# file app/config/main.php


return [
    'components' => [
	   'yunpian' => [
            'class' => 'dcb9\Yunpian\sdk\Yunpian',
            'apiKey' => 'your yunpian apiKey',
            // 'useFileTransport' => false, // 如果该值为 true 则不会真正的发送短信,而是把内容写到文件里面,测试环境经常需要用到!
        ],
    ],
];

$phone = '01234567890';
// $phone = ['01234567890'];   # 可以为数组
// $phone = '12345678900,01234567890';  # 还可以号码与号码之间用空格隔开
$text ='sms content';
$sms = Yii::$app->yunpian;
if($sms->sendSms($phone, $text))
{
    $responseBody = $sms->getBody();
    # ["code"=>0, "msg"=>"OK", "result" => ["count" => 1, "fee" => 1, "sid" => 3995844410]]
} elseif ($sms->hasError()) {
    $error = $sms->getLastError()
    # ["code" => 2, "msg" => "请求参数格式错误", "detail" => "参数 text 格式不正确,text短信内容头部需要加签名,如【云片网】"]
}