Jianzhou.class.php
2.6 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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
<?php
/**
* Sms.php
* 短信消息服务
*/
namespace Com\Sms;
class Jianzhou
{
/** 用户名 */
protected $_account = '';
/** 密码 */
protected $_passwd = '';
/** 发送普通短信 */
const SIMPLE_URL = 'http://www.jianzhou.sh.cn/JianzhouSMSWSServer/http/sendBatchMessage';
/**
* &instance
* 获取一个短信发送类的实例
*
* @return object
*/
public static function &instance($account = null, $password = null)
{
static $instance = null;
if (! $instance) {
$instance = new Jianzhou($account, $password);
}
return $instance;
}
/**
* __construct
*
* @param mixed $group
* @return void
*/
public function __construct($account = null, $password = null)
{
$this->_account = $account === null ? cfg('SMS_JIANZHOU.ACCOUNT') : $account;
$this->_passwd = $password === null ? cfg('SMS_JIANZHOU.PASSWORD') : $password;
}
/**
* 批量发送消息
*
* @param int $result
* 发送状态值
* @param array $mobiles
* 目标手机
* @param string $msg
* 消息
* @param string $timed
* 定时时间
*/
public function send_batch_message($result, $mobiles, $msg, $timed = '')
{
// 如果发送的用户名和密码为空
if (empty($this->_account) || empty($this->_passwd)) {
E('_err_sms_account_or_passwd_is_empty');
return false;
}
// 如果接收手机号码为空
$mobiles = (array) $mobiles;
if (empty($mobiles)) {
E('_err_sms_mobile_is_empty');
return false;
}
// 如果信息为空
if (empty($msg)) {
E('_err_sms_msg_is_empty');
return false;
}
// 使用 snoopy 进行发送
$result = '';
$data = array(
'account' => $this->_account,
'password' => $this->_passwd,
'destmobile' => implode(';', $mobiles),
'msgText' => $msg,
'sendDateTime' => $timed
);
// 消息发送
if (! rfopen($result, self::SIMPLE_URL, $data, null, 'post')) {
E('_err_sms_submit_error');
return false;
}
// 获取结果
$ret = (int) $result;
// 如果是小于等于 0 的值, 则说明出错了
if (0 >= $ret) {
E(L('_err_sms_send_error', array(
'error' => $result
)));
return false;
}
return true;
}
}