Call.php
2.0 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
<?php
/**
* Created by PhpStorm.
* User: Kevin
* Date: 2022/03/22 1847
* Time: 18:47
*/
namespace app\api\controller\alibaba;
use app\common\controller\Api;
use think\Db;
use think\Request;
/**
* 阿里云语音服务
* @package app\api\controller\core
*/
class Call extends Base
{
/**
* 1. 向指定号码发起语音验证码
*/
public function singleCallByTts()
{
$param = $this->request->param();
$mobile = $param['mobile'];//手机号
if (empty($mobile)) {
$this->error("无效的手机号");
}
$from_screen = $param['from_screen'];//控制台名称
$type = $param['type'];//语音 、视频
$outId = "CALL_" . rand('1000000000', '9999999999');//发起请求时预留给调用方的自定义ID,最终会通过在回执消息中将此ID带回给调用方。字符串类型,长度为1~15个字节。
$data = [
"calledNumber" => $mobile,
"ttsCode" => "TTS_237056642",
"ttsParam" => json_encode(["name" => $from_screen, "type" => $type]),//"{\"name\":\"zhong\",\"type\":\"语音\"}",
"playTimes" => 3,
"volume" => 100,
"speed" => -200,
"outId" => $outId,
];
$res = $this->main($data);
$log_data = [
"calledNumber" => $mobile,
"name" => $from_screen,
"type" => $type,
"outId" => $outId,
"createtime" => time(),
"backcontent" => $res
];
Db::name("alibaba_call")->insert($log_data);
$result = json_decode($res, true);
if (!empty($result)) {
if ($result['Code'] == "OK") {
$this->success("电话语音通知推送成功", $result);//状态,online在线 offline离线
} else {
$this->error("电话语音通知推送失败[" . $result['Code'] . $result['Message'] . "]");
}
} else {
$this->error("语音通知推送服务器请求异常");
}
}
}