1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace zacksleo\PhpSms; |
4
|
|
|
|
5
|
|
|
use Toplan\PhpSms\Agent; |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* Class 互亿无线短信接口 |
9
|
|
|
* @package Toplan\PhpSms |
10
|
|
|
* @property string $sendUrl |
11
|
|
|
* @property string $apiKey |
12
|
|
|
* @property string $secretKey |
13
|
|
|
* @property string $smsFreeSignName |
14
|
|
|
* @property string $calledShowNum |
15
|
|
|
*/ |
16
|
|
|
class IhuyiAgent extends Agent |
17
|
|
|
{ |
18
|
|
|
public function sendSms($to, $content, $tempId, array $tempData) |
19
|
|
|
{ |
20
|
|
|
$this->sendContentSms($to, $content); |
21
|
|
|
} |
22
|
|
|
|
23
|
|
|
public function voiceVerify($to, $code, $tempId, array $tempData) |
|
|
|
|
24
|
|
|
{ |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
public function sendTemplateSms($to, $tempId, array $tempData) |
|
|
|
|
28
|
|
|
{ |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
public function sendContentSms($to, $content) |
32
|
|
|
{ |
33
|
|
|
$to = ltrim($to, '+'); |
34
|
|
|
//如果是中国的手机号,去掉86,并使用国内短信网关 |
35
|
|
|
if (preg_match('/^86\s[1][34578][0-9]{9}$/', $to)) { |
36
|
|
|
$to = substr($to, -11, 11); |
37
|
|
|
} elseif (preg_match('/^[1][34578][0-9]{9}$/', $to)) { |
38
|
|
|
$this->sendUrl = 'http://106.ihuyi.cn/webservice/sms.php?method=Submit'; |
39
|
|
|
} else { |
40
|
|
|
$this->sendUrl = 'http://api.isms.ihuyi.com/webservice/isms.php?method=Submit'; |
41
|
|
|
} |
42
|
|
|
$params = [ |
43
|
|
|
'mobile' => $to, |
44
|
|
|
'content' => $content, |
45
|
|
|
]; |
46
|
|
|
$this->request($params); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
protected function request(array $params) |
50
|
|
|
{ |
51
|
|
|
$sendUrl = $this->sendUrl ?: 'http://106.ihuyi.cn/webservice/sms.php?method=Submit'; |
52
|
|
|
$params = $this->createParams($params); |
53
|
|
|
$result = $this->curl($sendUrl, $params, true); |
|
|
|
|
54
|
|
|
$this->setResult($result); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
protected function createParams(array $params) |
58
|
|
|
{ |
59
|
|
|
$params = array_merge([ |
60
|
|
|
'account' => $this->apiKey, |
61
|
|
|
'password' => $this->secretKey, |
62
|
|
|
], $params); |
63
|
|
|
return $params; |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
protected function setResult($result) |
67
|
|
|
{ |
68
|
|
|
if (!$result['request']) { |
69
|
|
|
$this->result(Agent::SUCCESS, false); |
70
|
|
|
} else { |
71
|
|
|
$return = @simplexml_load_string($result['response']); |
72
|
|
|
$this->result(Agent::SUCCESS, $return->code == 2); |
73
|
|
|
$this->result(Agent::CODE, $return->code); |
74
|
|
|
$this->result(Agent::INFO, $return->msg); |
75
|
|
|
} |
76
|
|
|
} |
77
|
|
|
} |
78
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.