forked from daixianceng/yii2-smser
-
Notifications
You must be signed in to change notification settings - Fork 0
/
WebchineseSmser.php
90 lines (81 loc) · 2.44 KB
/
WebchineseSmser.php
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
<?php
namespace daixianceng\smser;
use yii\base\InvalidConfigException;
/**
* 中国网建
*
* @author Cosmo <daixianceng@gmail.com>
* @property string $password write-only password
* @property string $state read-only state
* @property string $message read-only message
*/
class WebchineseSmser extends Smser
{
/**
* @inheritdoc
*/
public $url = 'http://utf8.sms.webchinese.cn/';
/**
* @inheritdoc
*/
public function send($mobile, $content)
{
if (parent::send($mobile, $content)) {
return true;
}
$data = [
'uid' => $this->username,
'key' => $this->password,
'smsMob' => $mobile,
'smsText' => $content
];
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $this->url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data));
$this->state = (string) curl_exec($ch);
curl_close($ch);
$success = false;
switch ($this->state) {
case '' :
case '-1' :
$this->message = '没有该用户账户';
break;
case '-2' :
$this->message = '接口密钥不正确';
break;
case '-21' :
$this->message = 'MD5接口密钥加密不正确';
break;
case '-3' :
$this->message = '短信数量不足';
break;
case '-11' :
$this->message = '该用户被禁用';
break;
case '-14' :
$this->message = '短信内容出现非法字符';
break;
case '-4' :
$this->message = '手机号格式不正确';
break;
case '-41' :
$this->message = '手机号码为空';
break;
case '-42' :
$this->message = '短信内容为空';
break;
case '-51' :
$this->message = '短信签名格式不正确';
break;
case '-6' :
$this->message = 'IP限制';
break;
default :
$this->message = '短信发送成功';
$success = true;
break;
}
return $success;
}
}