function sendSMS($mobiles = array(), $content, $sendTime = '', $addSerial = '', $charset = 'UTF-8', $priority = 5) { $sms = new smsAPI(); //var_dump($mobiles); foreach ($mobiles as $mobile) { $this->db->where('phone', $mobile); $tmp = $this->db->get('sms')->result_array(); $longtime = time(); $str = 1; if (preg_match('/验证码/', $content)) { if (!empty($tmp)) { if ($longtime - $tmp[0]['created_at'] <= 60 && $tmp[0]['minute'] < 1) { $this->db->where('phone', $mobile); $this->db->update('sms', array('minute_num' => 1, 'hour_num' => $tmp[0]['hour_num'] + 1, 'day_num' => $tmp[0]['day_num'] + 1, 'content' => $content . ":" . $mobile)); $result = $sms->sendSms($mobile, $content); $str = 2; $this->db->insert('sms_log', array('phone' => $mobile, 'content' => serialize($result), 'created_at' => time())); } if ($longtime - $tmp[0]['created_at'] <= 3600 && $tmp[0]['hour_num'] < 4 && $longtime - $tmp[0]['created_at'] > 60) { $this->db->where('phone', $mobile); $this->db->update('sms', array('hour_num' => $tmp[0]['hour_num'] + 1, 'day_num' => $tmp[0]['day_num'] + 1, 'content' => $content . ":" . $mobile)); $result = $sms->sendSms($mobile, $content); $str = 3; $this->db->insert('sms_log', array('phone' => $mobile, 'content' => serialize($result), 'created_at' => time())); } if ($longtime - $tmp[0]['created_at'] <= 86400 && $tmp[0]['day_num'] < 5 && $longtime - $tmp[0]['created_at'] > 3600) { $this->db->where('phone', $mobile); $this->db->update('sms', array('day_num' => $tmp[0]['day_num'] + 1, 'content' => $content . ":" . $mobile)); $result = $sms->sendSms($mobile, $content); $str = 4; $this->db->insert('sms_log', array('phone' => $mobile, 'content' => serialize($result), 'created_at' => time())); } if ($longtime - $tmp[0]['created_at'] > 86400) { $this->db->where('phone', $mobile); $this->db->update('sms', array('day_num' => 0, 'hour_num' => 0, 'minute_num' => 0, 'created_at' => time())); $this->db->where('phone', $mobile); $this->db->update('sms', array('minute_num' => 1, 'hour_num' => $tmp[0]['hour_num'] + 1, 'day_num' => $tmp[0]['day_num'] + 1, 'content' => $content . ":" . $mobile)); $result = $sms->sendSms($mobile, $content); $str = 5; $this->db->insert('sms_log', array('phone' => $mobile, 'content' => serialize($result), 'created_at' => time())); } } else { $this->db->insert('sms', array('phone' => $mobile, 'minute_num' => 1, 'hour_num' => 1, 'day_num' => 1, 'created_at' => time())); $result = $sms->sendSms($mobile, $content); $this->db->insert('sms_log', array('phone' => $mobile, 'content' => serialize($result), 'created_at' => time())); } } else { $result = $sms->sendSms($mobile, $content); $str = 7; $this->db->insert('sms_log', array('phone' => $mobile, 'content' => serialize($result), 'created_at' => time())); } break; } //var_dump($result); return $result; }
function comment_post_sms($comment_id = null) { if ($comment_id != null) { $item_id = Params::getParam('id'); $author = Params::getParam('authorEmail'); $user = User::newInstance()->findByEmail($author); $item = Item::newInstance()->findByPrimaryKey($item_id); $author_phone = $user['s_phone_mobile']; $msg = "Someone commented on " . $item['s_title']; $_credentials = WebSMS::newInstance()->selectWebSMSData(); $token = $_credentials['pk_ws_token']; $signature = $_credentials['ws_signature']; $sa = new smsAPI(); $sa->setCredentials($token, $signature); $res = $sa->sendSms($author_phone, $msg); } }