|
Server : Apache System : Linux iZ6xhqomji47p1Z 5.10.134-15.al8.x86_64 #1 SMP Thu Jul 20 00:44:04 CST 2023 x86_64 User : www ( 1000) PHP Version : 8.1.30 Disable Function : passthru,exec,system,putenv,chroot,chgrp,chown,shell_exec,popen,proc_open,pcntl_exec,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru,pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,imap_open,apache_setenv Directory : /www/wwwroot/fsjlkj.cn/vendor/tencentsms/ |
<?php
require_once __DIR__ . "/SmsSenderUtil.php";
/**
* 按语音文件fid发送语音通知类
*
*/
class FileVoiceSender
{
private $url;
private $appid;
private $appkey;
private $util;
/**
* 构造函数
*
* @param string $appid sdkappid
* @param string $appkey sdkappid对应的appkey
*/
public function __construct($appid, $appkey)
{
$this->url = "https://cloud.tim.qq.com/v5/tlsvoicesvr/sendfvoice";
$this->appid = $appid;
$this->appkey = $appkey;
$this->util = new SmsSenderUtil();
}
/**
*
* 按语音文件fid发送语音通知
*
* @param string $nationCode 国家码,如 86 为中国
* @param string $phoneNumber 不带国家码的手机号
* @param string $fid 语音文件fid
* @param string $playtimes 播放次数,可选,最多3次,默认2次
* @param string $ext 用户的session内容,服务端原样返回,可选字段,不需要可填空串
* @return string 应答json字符串,详细内容参见腾讯云协议文档
*/
public function send($nationCode, $phoneNumber, $fid, $playtimes = 2, $ext = "")
{
$random = $this->util->getRandom();
$curTime = time();
$wholeUrl = $this->url . "?sdkappid=" . $this->appid . "&random=" . $random;
// 按照协议组织 post 包体
$data = new \stdClass();
$tel = new \stdClass();
$tel->nationcode = "".$nationCode;
$tel->mobile = "".$phoneNumber;
$data->tel = $tel;
$data->fid = $fid;
if ($playtimes == 1) {
$data->playtimes = 1;
} else if ($playtimes == 3) {
$data->playtimes = 3;
} else {
$data->playtimes = 2;
}
// app凭证
$data->sig = $this->util->calculateSig($this->appkey, $random,
$curTime, array($phoneNumber));
// unix时间戳,请求发起时间,如果和系统时间相差超过10分钟则会返回失败
$data->time = $curTime;
$data->ext = $ext;
return $this->util->sendCurlPost($wholeUrl, $data);
}
}