@@ 11-84 (lines=74) @@ | ||
8 | * @property string $smsUser |
|
9 | * @property string $smsPassword |
|
10 | */ |
|
11 | class SmsBaoAgent extends Agent |
|
12 | { |
|
13 | protected $resultArr = [ |
|
14 | '0' => '发送成功', |
|
15 | '-1' => '参数不全', |
|
16 | '-2' => '服务器空间不支持,请确认支持curl或者fsocket,联系您的空间商解决或者更换空间!', |
|
17 | '30' => '密码错误', |
|
18 | '40' => '账号不存在', |
|
19 | '41' => '余额不足', |
|
20 | '42' => '帐户已过期', |
|
21 | '43' => 'IP地址限制', |
|
22 | '50' => '内容含有敏感词', |
|
23 | '51' => '手机号码不正确', |
|
24 | ]; |
|
25 | ||
26 | public function sendSms($to, $content, $tempId, array $data) |
|
27 | { |
|
28 | $this->sendContentSms($to, $content); |
|
29 | } |
|
30 | ||
31 | /** |
|
32 | * Content SMS send process. |
|
33 | * |
|
34 | * @param $to |
|
35 | * @param $content |
|
36 | */ |
|
37 | public function sendContentSms($to, $content) |
|
38 | { |
|
39 | $url = 'http://api.smsbao.com/sms'; |
|
40 | $username = $this->smsUser; |
|
41 | $password = md5($this->smsPassword); |
|
42 | $content = urlencode($content); |
|
43 | $postString = "u=$username&p=$password&m=$to&c=$content"; |
|
44 | $response = $this->sockPost($url, $postString); |
|
45 | $this->setResult($response); |
|
46 | } |
|
47 | ||
48 | /** |
|
49 | * Template SMS send process. |
|
50 | * |
|
51 | * @param $to |
|
52 | * @param $tempId |
|
53 | * @param array $tempData |
|
54 | */ |
|
55 | public function sendTemplateSms($to, $tempId, array $tempData) |
|
56 | { |
|
57 | } |
|
58 | ||
59 | /** |
|
60 | * Voice verify send process. |
|
61 | * |
|
62 | * @param $to |
|
63 | * @param $code |
|
64 | * @param $tempId |
|
65 | * @param array $tempData |
|
66 | */ |
|
67 | public function voiceVerify($to, $code, $tempId, array $tempData) |
|
68 | { |
|
69 | $url = 'http://api.smsbao.com/voice'; |
|
70 | $username = $this->smsUser; |
|
71 | $password = md5($this->smsPassword); |
|
72 | $postString = "u=$username&p=$password&m=$to&c=$code"; |
|
73 | $response = $this->sockPost($url, $postString); |
|
74 | $this->setResult($response); |
|
75 | } |
|
76 | ||
77 | protected function setResult($result) |
|
78 | { |
|
79 | $msg = array_key_exists($result, $this->resultArr) ? $this->resultArr[$result] : '未知错误'; |
|
80 | $this->result(Agent::INFO, json_encode(['code' => $result, 'msg' => $msg])); |
|
81 | $this->result(Agent::SUCCESS, $result === '0'); |
|
82 | $this->result(Agent::CODE, $result); |
|
83 | } |
|
84 | } |
|
85 |
@@ 11-84 (lines=74) @@ | ||
8 | * @property string $smsUser |
|
9 | * @property string $smsPassword |
|
10 | */ |
|
11 | class SmsBaoAgent extends Agent |
|
12 | { |
|
13 | protected $resultArr = [ |
|
14 | '0' => '发送成功', |
|
15 | '-1' => '参数不全', |
|
16 | '-2' => '服务器空间不支持,请确认支持curl或者fsocket,联系您的空间商解决或者更换空间!', |
|
17 | '30' => '密码错误', |
|
18 | '40' => '账号不存在', |
|
19 | '41' => '余额不足', |
|
20 | '42' => '帐户已过期', |
|
21 | '43' => 'IP地址限制', |
|
22 | '50' => '内容含有敏感词', |
|
23 | '51' => '手机号码不正确', |
|
24 | ]; |
|
25 | ||
26 | public function sendSms($to, $content, $tempId, array $data) |
|
27 | { |
|
28 | $this->sendContentSms($to, $content); |
|
29 | } |
|
30 | ||
31 | /** |
|
32 | * Content SMS send process. |
|
33 | * |
|
34 | * @param $to |
|
35 | * @param $content |
|
36 | */ |
|
37 | public function sendContentSms($to, $content) |
|
38 | { |
|
39 | $url = 'http://api.smsbao.com/sms'; |
|
40 | $username = $this->smsUser; |
|
41 | $password = md5($this->smsPassword); |
|
42 | $content = urlencode($content); |
|
43 | $postString = "u=$username&p=$password&m=$to&c=$content"; |
|
44 | $response = $this->sockPost($url, $postString); |
|
45 | $this->setResult($response); |
|
46 | } |
|
47 | ||
48 | /** |
|
49 | * Template SMS send process. |
|
50 | * |
|
51 | * @param $to |
|
52 | * @param $tempId |
|
53 | * @param array $tempData |
|
54 | */ |
|
55 | public function sendTemplateSms($to, $tempId, array $tempData) |
|
56 | { |
|
57 | } |
|
58 | ||
59 | /** |
|
60 | * Voice verify send process. |
|
61 | * |
|
62 | * @param $to |
|
63 | * @param $code |
|
64 | * @param $tempId |
|
65 | * @param array $tempData |
|
66 | */ |
|
67 | public function voiceVerify($to, $code, $tempId, array $tempData) |
|
68 | { |
|
69 | $url = 'http://api.smsbao.com/voice'; |
|
70 | $username = $this->smsUser; |
|
71 | $password = md5($this->smsPassword); |
|
72 | $postString = "u=$username&p=$password&m=$to&c=$code"; |
|
73 | $response = $this->sockPost($url, $postString); |
|
74 | $this->setResult($response); |
|
75 | } |
|
76 | ||
77 | protected function setResult($result) |
|
78 | { |
|
79 | $msg = array_key_exists($result, $this->resultArr) ? $this->resultArr[$result] : '未知错误'; |
|
80 | $this->result(Agent::INFO, json_encode(['code' => $result, 'msg' => $msg])); |
|
81 | $this->result(Agent::SUCCESS, $result === '0'); |
|
82 | $this->result(Agent::CODE, $result); |
|
83 | } |
|
84 | } |
|
85 |