|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Toplan\PhpSms; |
|
4
|
|
|
|
|
5
|
|
|
/** |
|
6
|
|
|
* Class JuHeAgent |
|
7
|
|
|
* |
|
8
|
|
|
* @property string $key |
|
9
|
|
|
* @property string $times |
|
10
|
|
|
*/ |
|
11
|
|
|
class JuHeAgent extends Agent |
|
12
|
|
|
{ |
|
13
|
|
|
public function sendSms($to, $content, $tempId, array $data) |
|
14
|
|
|
{ |
|
15
|
|
|
$this->sendTemplateSms($to, $tempId, $data); |
|
16
|
|
|
} |
|
17
|
|
|
|
|
18
|
|
|
public function sendTemplateSms($to, $tempId, array $data) |
|
19
|
|
|
{ |
|
20
|
|
|
$sendUrl = 'http://v.juhe.cn/sms/send'; |
|
21
|
|
|
$tplValue = ''; |
|
22
|
|
|
foreach ($data as $key => $value) { |
|
23
|
|
|
if (preg_match('/[#&=]/', $value)) { |
|
24
|
|
|
$value = urlencode($value); |
|
25
|
|
|
} |
|
26
|
|
|
$split = !$tplValue ? '' : '&'; |
|
27
|
|
|
$tplValue .= "$split#$key#=$value"; |
|
28
|
|
|
} |
|
29
|
|
|
$tplValue = !$tplValue ?: urlencode($tplValue); |
|
30
|
|
|
$smsConf = [ |
|
31
|
|
|
'key' => $this->key, |
|
32
|
|
|
'mobile' => $to, |
|
33
|
|
|
'tpl_id' => $tempId, |
|
34
|
|
|
'tpl_value' => $tplValue, |
|
35
|
|
|
]; |
|
36
|
|
|
$result = $this->curl($sendUrl, $smsConf, true); |
|
37
|
|
|
$this->setResult($result); |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
public function voiceVerify($to, $code, $tempId, array $data) |
|
41
|
|
|
{ |
|
42
|
|
|
$url = 'http://op.juhe.cn/yuntongxun/voice'; |
|
43
|
|
|
$params = [ |
|
44
|
|
|
'valicode' => $code, |
|
45
|
|
|
'to' => $to, |
|
46
|
|
|
'playtimes' => $this->times ?: 3, |
|
47
|
|
|
'key' => $this->key, |
|
48
|
|
|
]; |
|
49
|
|
|
$result = $this->curl($url, $params); |
|
50
|
|
|
$this->setResult($result); |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
protected function setResult($result) |
|
54
|
|
|
{ |
|
55
|
|
|
if ($result['request']) { |
|
56
|
|
|
$result = json_decode($result['response'], true); |
|
57
|
|
|
if ($result['error_code'] === 0) { |
|
58
|
|
|
$this->result(Agent::SUCCESS, true); |
|
59
|
|
|
} |
|
60
|
|
|
$this->result(Agent::INFO, json_encode($result)); |
|
61
|
|
|
$this->result(Agent::CODE, $result['error_code']); |
|
62
|
|
|
} else { |
|
63
|
|
|
$this->result(Agent::INFO, '请求失败'); |
|
64
|
|
|
} |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
public function sendContentSms($to, $content) |
|
68
|
|
|
{ |
|
69
|
|
|
} |
|
70
|
|
|
} |
|
71
|
|
|
|