예제 #1
0
<?php

/*header("Content-Type: text/event-stream");
header("Cache-Control: no-cache");
header("Connection: keep-alive");*/
require_once 'libraries/TMSE/TMSE.php';
$lastId = $_SERVER["HTTP_LAST_EVENT_ID"];
if (isset($lastId) && !empty($lastId) && is_numeric($lastId)) {
    $lastId = intval($lastId);
    $lastId++;
}
while (true) {
    $time = time();
    $data = "Hi";
    if ($data) {
        checkMessage($time, $lastId);
        $lastId++;
    }
    sleep(2);
}
function checkMessage($time, $userID)
{
    $Db = new Database();
    $Db->connect('localhost', 'mvc', 'root', 'joakim1');
    $Db->txtChat();
    if ($Db->checkChat($time, $userID) >= 1) {
        // show updates
        echo "id: {$userID}\n";
        echo "data: Update\n\n";
    } else {
        echo "Hi";
예제 #2
0
 public function doMasssend()
 {
     $id = intval($_POST['id']);
     $sms_content = M('sms_content')->alias("t")->field("t.id,t.sms_content")->where(array("id" => $id))->find();
     $allreceivers = M('sms_receiver')->alias("t")->field("distinct t.phone_number")->where(array("t.sms_log_id" => $id, "t.sms_status" => "0"))->limit($this->smsLimit)->select();
     foreach ($allreceivers as $k => $v) {
         $receivers[] = $v["phone_number"];
     }
     $content = $sms_content["sms_content"];
     $len = cnstrlen($content);
     if ($len == 0) {
         $this->error("短信内容不能为空");
     }
     if ($len > 240) {
         $this->error("短信内容为不能超过240个汉字、字符、数字组成的字符串");
     }
     if (checkMessage($sms_content['sms_content']) != null) {
         $this->assign('waitSecond', '-1');
         $this->error(checkMessage($sms_content['sms_content']));
     }
     $sms_log_id = $sms_content["id"];
     if (empty($receivers)) {
         $this->error("发送失败,接受者为空");
     }
     $rcount = count($receivers);
     if (C('SMS_TYPE') == "REAL") {
         //每次发送100条
         $perCount = 100;
         $pageCount = ceil($rcount / $perCount);
         $errmsg = "";
         $allsuccess = 0;
         $allfail = 0;
         $allerrid = "";
         $allerr = "";
         for ($i = 1; $i <= $pageCount; ++$i) {
             $curreceivers = array_slice($receivers, ($i - 1) * $perCount, $perCount);
             $data = array();
             if ($len <= 70) {
                 //发送正常短信
                 $data = masssendsms(implode(",", $curreceivers), $content, '', false, true);
             } else {
                 //发送超过70个汉字的短信
                 $data = masssendsms(implode(",", $curreceivers), $content, '', true, true);
             }
             if (is_array($data)) {
                 $success = array();
                 $faile = array();
                 if (!empty($data["success"])) {
                     $success = explode(",", $data["success"]);
                 }
                 if (!empty($data["faile"])) {
                     $faile = explode(",", $data["faile"]);
                 }
                 if (!empty($data["num"])) {
                     $allsuccess = $allsuccess + intval($data["num"]);
                 }
                 if (!empty($data["errid"])) {
                     $allerrid .= $data["errid"];
                 }
                 if (!empty($data["err"])) {
                     $allerr .= $data["err"];
                 }
                 if (count($success) > 0) {
                     M('sms_receiver')->where(array("phone_number" => array("in", $success), "sms_log_id" => $sms_log_id))->save(array("sms_status" => 1, "error_code" => $data["errid"], "error_info" => $data["err"]));
                 }
                 if (count($faile) > 0) {
                     $allfail = $allfail + count($faile);
                     M('sms_receiver')->where(array("phone_number" => array("in", $faile), "sms_log_id" => $sms_log_id))->save(array("sms_status" => 2, "error_code" => $data["errid"], "error_info" => $data["err"]));
                 }
             } else {
                 $errmsg .= $data;
             }
         }
         M('sms_content')->where(array("id" => $id))->save(array("deal_flag" => 1, "deal_user" => $this->admin_id, "deal_time" => date('Y-m-d H:i:s', time())));
         if (!empty($errmsg)) {
             $this->assign('waitSecond', '-1');
             $this->error("发送失败,失败原因:" . $errmsg);
         }
         $this->assign('waitSecond', '5');
         $this->success("发送结果:<br>发送成功{$allsuccess}条,<br>发送失败[" . $allfail . "]条,<br>(错误)编码[{$allerrid}],<br>(错误)原因[{$allerr}]");
     } else {
         //模拟发送
         M('sms_receiver')->where(array("sms_log_id" => $sms_log_id, "phone_number" => array("in", $receivers)))->save(array("sms_status" => 1, "error_info" => "模拟群发成功"));
         M('sms_content')->where(array("id" => $id))->save(array("deal_flag" => 1, "deal_user" => $this->admin_id, "deal_time" => date('Y-m-d H:i:s', time())));
         $this->assign('waitSecond', '3');
         $this->success("发送结果:<br>模拟发送成功{$rcount}条,<br>");
     }
 }