function send_verify_sms($mobile, $code, $user_info, $immediately)
{
    $re = array('msg_id' => 0, 'status' => 0, 'msg' => '');
    if (app_conf("SMS_ON") == 1) {
        $tmpl = $GLOBALS['db']->getRow("select * from " . DB_PREFIX . "msg_template where name = 'TPL_SMS_VERIFY_CODE'");
        $tmpl_content = $tmpl['content'];
        $verify['mobile'] = $mobile;
        $verify['code'] = $code;
        $GLOBALS['tmpl']->assign("verify", $verify);
        $msg = $GLOBALS['tmpl']->fetch("str:" . $tmpl_content);
        $msg_data['dest'] = $mobile;
        $msg_data['send_type'] = 0;
        $msg_data['title'] = addslashes($msg);
        $msg_data['content'] = $msg_data['title'];
        $msg_data['send_time'] = 0;
        if ($immediately) {
            $msg_data['is_send'] = 1;
        } else {
            $msg_data['is_send'] = 0;
        }
        $msg_data['create_time'] = TIME_UTC;
        $msg_data['user_id'] = $user_info['id'];
        $msg_data['is_html'] = $tmpl['is_html'];
        $GLOBALS['db']->autoExecute(DB_PREFIX . "deal_msg_list", $msg_data);
        //插入
        $msg_id = $GLOBALS['db']->insert_id();
        $re['msg_id'] = $msg_id;
        if ($immediately && $msg_id > 0) {
            $result = send_sms_email($msg_data);
            $re['status'] = intval($result['status']);
            $re['msg'] = trim($result['msg']);
            //发送结束,更新当前消息状态
            $GLOBALS['db']->query("update " . DB_PREFIX . "deal_msg_list set is_success = " . intval($result['status']) . ",result='" . $result['msg'] . "',send_time='" . TIME_UTC . "' where id =" . $msg_id);
        } else {
            if ($msg_id == 0) {
                $re['status'] = 0;
            } else {
                $re['status'] = 1;
            }
        }
        return $re;
    } else {
        return $re;
    }
}
Exemple #2
0
if ($_REQUEST['act'] == 'deal_msg_list') {
    //业务队列的群发
    $GLOBALS['db']->query("update " . DB_PREFIX . "conf set `value` = 1 where name = 'DEAL_MSG_LOCK' and `value` = 0");
    $rs = $GLOBALS['db']->affected_rows();
    if ($rs) {
        //业务队列中处理返利发放
        /*$rid = $GLOBALS['db']->getOne("select id from ".DB_PREFIX."referrals where ".TIME_UTC."-create_time > ".(intval(app_conf('REFERRALS_DELAY'))*60)." and pay_time = 0");
        		if($rid)
        		pay_referrals(intval($rid));
        		*/
        $msg_item = $GLOBALS['db']->getRow("select * from " . DB_PREFIX . "deal_msg_list where is_send = 0 and (send_type = 0 or send_type = 1) order by id asc limit 1");
        if ($msg_item) {
            //优先改变发送状态,不论有没有发送成功
            $GLOBALS['db']->query("update " . DB_PREFIX . "deal_msg_list set is_send = 1 where id =" . intval($msg_item['id']));
            if ($GLOBALS['db']->affected_rows()) {
                $result = send_sms_email($msg_item);
                //发送结束,更新当前消息状态
                $GLOBALS['db']->query("update " . DB_PREFIX . "deal_msg_list set is_success = " . intval($result['status']) . ",result='" . $result['msg'] . "',send_time='" . TIME_UTC . "' where id =" . intval($msg_item['id']));
            }
        }
        header("Content-Type:text/html; charset=utf-8");
        echo json_encode(array("DEAL_MSG_COUNT" => intval($GLOBALS['db']->getOne("select count(*) from " . DB_PREFIX . "deal_msg_list where is_send = 0 and (send_type = 0 or send_type = 1)"))));
        $GLOBALS['db']->query("update " . DB_PREFIX . "conf set `value` = 0 where name = 'DEAL_MSG_LOCK'");
    } else {
        header("Content-Type:text/html; charset=utf-8");
        echo json_encode(array("DEAL_MSG_COUNT" => 0));
    }
}
if ($_REQUEST['act'] == 'promote_msg_list') {
    //推广队列的群发
    $GLOBALS['db']->query("update " . DB_PREFIX . "conf set `value` = 1 where name = 'PROMOTE_MSG_LOCK' and `value` = 0");