andileong/aliyun-sms

该软件包最新版本(dev-main)没有可用的许可证信息。

阿里云的发送短信包

dev-main 2021-11-05 03:00 UTC

This package is auto-updated.

Last update: 2024-09-05 09:11:21 UTC


README

一个与阿里云短信API通信以触发发送短信功能的包,使用phpunit进行TDD,底层使用guzzle作为HTTP客户端。

安装

composer require andileong/aliyun-sms

用法

###发送短信

use Andileong\AliyunSms\SendSms;


$accessKeyId = 'your aliyun access key id';
$accessKeySecret = 'your aliyun access key secret';

$sms= new SendSms($accessKeyId,$accessKeySecret);

$signature = 'your aliyun signature';
$template_code = 'your aliyun template_code';
$data = ['code' => 444578 , 'product' => 'aaaaaa'];
$phoneNumber = '111111111111';
$res = $sms->setData($signature, $template_code ,$data)
->send($phoneNumber)
->isSuccess();
           

上述调用将返回布尔值,如果返回false,您将收到如下错误消息

$sms->getErrorMsg();
// @see https://help.aliyun.com/document_detail/101414.html for more return data

获取特定日期上某个手机号的短信发送历史记录

use Andileong\AliyunSms\History;

$accessKeyId = 'your aliyun access key id';
$accessKeySecret = 'your aliyun access key secret';
$phoneNumber = '111111111111';

    $data = (new History($accessKeyId,$accessKeySecret))
        ->yesterday()
        ->onPage(1) //on which page 
        ->perPage(11) //on each page should contains page size max:50 
        ->fetch($phoneNumber);
    
    //you can get yesterday or today for specific phone number
    //using yesterday() or today()
    //if you want other than those 2 you can use setDate() like below
    
    $date = '20000101';
    $data = (new History($accessKeyId,$accessKeySecret))
        ->setDate($date)
        ->onPage(1) //on which page 
        ->perPage(11) //on each page should contains page size max:50 
        ->fetch($phoneNumber);
    
    //$date passed on above setDate() method must follow YYYYmmdd format
    
    //you can pass an optional biz argument for fetch method
    // it will check that one sms transaction
    // you can get that from bizid from sendsms api
    
    $data = (new History($accessKeyId,$accessKeySecret))
        ->yesterday()
        ->onPage(1) //on which page 
        ->perPage(11) //on each page should contains page size max:50 
        ->fetch($phoneNumber,'mybizid');
        
        // see https://help.aliyun.com/document_detail/102352.html for more return data
           

如果成功,您将获得阿里云返回的所有数据;如果失败,您也将收到阿里云的状态码

检查签名有效性

use Andileong\AliyunSms\CheckSignature;

$accessKeyId = 'your aliyun access key id';
$accessKeySecret = 'your aliyun access key secret';
$signature = '111111111111';

    $data = (new CheckSignature($this->accessKeyId,$this->accessKeySecret))
        ->check($signature);

    //it will check if you signature is valid or not 
    // see https://help.aliyun.com/document_detail/121210.html for more return data