Exemplo n.º 1
0
function process_message($msg)
{
    $dbalive = mysql_ping();
    if ($dbalive !== TRUE) {
        //数据库连接失效 重连
        echo "reconnecting DB ! \n";
    }
    global $remsg_obj, $msg_obj, $rm_obj, $remsgque_obj, $dbConn;
    $message_body = json_decode($msg->body, TRUE);
    if ($message_body == FALSE || !is_array($message_body) || !isset($message_body['id'])) {
        echo 'invalid message ! --- ' . $msg->body . "\n";
        return;
    }
    $id = $message_body['id'];
    $sql = "select * from msg_replyqueue where id={$id}  limit 1";
    $row = $dbConn->fetch_first($sql);
    if (empty($row)) {
        //没找到信息 直接return
        $msg->delivery_info['channel']->basic_ack($msg->delivery_info['delivery_tag']);
        //删除队列信息
        return;
    }
    $infor = unserialize($row['parameter']);
    // 反序列化其他扩展信息
    /*----- 根据账号来加载账号信息 -----*/
    $ebayaccount = $row['account'];
    //所属账号
    $token_file = WEB_PATH . "lib/ebaylibrary/keys/keys_" . $ebayaccount . ".php";
    if (!file_exists($token_file)) {
        echo formatetime() . '---' . $token_file . " does not exists!!! at code line--" . __LINE__ . "\n";
        // 密码文件不存在
        $remsgque_obj->delAQueueRecords($row['id']);
        //数据不对直接删除
        $msg_obj->updateMessageStatus(array($row['messageid']), 0);
        //重置message为0的状态
        $msg->delivery_info['channel']->basic_ack($msg->delivery_info['delivery_tag']);
        //删除队列信息
        return;
        // 退出
    }
    include '' . $token_file;
    /*----- 导出为全局变量 ugly code -----*/
    $GLOBALS['siteID'] = $siteID;
    $GLOBALS['production'] = $production;
    $GLOBALS['compatabilityLevel'] = $compatabilityLevel;
    $GLOBALS['devID'] = $devID;
    $GLOBALS['appID'] = $appID;
    $GLOBALS['certID'] = $certID;
    $GLOBALS['serverUrl'] = $serverUrl;
    $GLOBALS['userToken'] = $userToken;
    /*----- 根据账号来加载账号信息 -----*/
    $msgid = $row['messageid'];
    //对应的message表的主键id
    if ($row['replytype'] == 1) {
        //带有回复内容的message回复
        $content = $row['retext'];
        //回复内容
        $copytosender = $infor['iscopy'];
        // 是否抄送 改值只能为0、1
        /*----- 推送回复到线上 -----*/
        $result = $rm_obj->replyMessage($msgid, $content, $copytosender);
        //回复 并返回结果
        if ($result == TRUE) {
            //执行成功则标记为已经读取
            $result = $rm_obj->markAsRead($msgid, 'Read');
            if (!$result) {
                echo ReplyMessageModel::$errMsg . " --- 回邮件发送成功, 标记已读失败!\n";
            }
        }
    } else {
        //只标及为回复状态 没有回复内容的
        /*----- 发送请求 -----*/
        $result = $rm_obj->markAsRead($msgid, 'Read');
    }
    if ($result == TRUE) {
        // 发送成功 删除该回复队列记录
        $remsgque_obj->delAQueueRecords($row['id']);
        $status = 2;
        // 默认为正常回复
        if ($row['replytype'] == 2) {
            //为标记回复
            $status = 3;
        }
        $msg_obj->updateMessageStatus(array($msgid), $status);
        //将message状态改为回复成功
        echo 'success!  ' . date('Y:m:d H:i:s', time()) . "\n";
    } else {
        // 发送失败
        echo date('Y-m-d H:i:s', time()) . '---' . __LINE__ . '---' . __FILE__ . '---' . ReplyMessageModel::$errMsg . "\n";
        $errcontent = ReplyMessageModel::$sendMsg;
        if (ReplyMessageModel::$sender != NULL) {
            $usrmod_obj = new GetLoacalUserModel();
            $userinfo = $usrmod_obj->getUserInfoBySysId(ReplyMessageModel::$sender);
            if (!empty($userinfo)) {
                /*发送邮件*/
                $result_sys = getOpenSysApi('notice.send.message', array('content' => $errcontent, 'from' => 'tuxinglong', 'to' => $userinfo['global_user_login_name'], 'type' => 'email'));
            }
        }
        $remsgque_obj->plusCountById($row['id']);
        // 将失败次数加一
    }
    //确认收到
    $msg->delivery_info['channel']->basic_ack($msg->delivery_info['delivery_tag']);
    //确认收到
    // Send a message with the string "quit" to cancel the consumer.
    if ($msg->body === 'quit') {
        $msg->delivery_info['channel']->basic_cancel($msg->delivery_info['consumer_tag']);
    }
}
Exemplo n.º 2
0
        echo 'success!' . "\n";
        commitQuery();
    } else {
        // 发送失败
        //echo 8;exit;
        echo formatetime() . '---' . __LINE__ . '---' . __FILE__ . '---' . ReplyMessageModel::$errMsg . "\n";
        $remsgque_obj->plusCountById($row['id']);
        // 将失败次数加一
        if ($row['trytimes'] == 19) {
            $msg_obj->updateMessageStatus(array($msgid), 4);
            //将message状态改为回复失败
        }
        commitQuery();
        if ($retype === 1) {
            //表示当前处理的是$trytimes大于0的记录 则需睡眠10 分钟
            echo formatetime() . "sleep 10 mins at code line--" . __LINE__ . "\n";
            sleep(600);
        }
    }
}
/*
 * 提交查询
 */
function commitQuery()
{
    global $dbConn;
    $dbConn->commit();
    //提交事务
    $dbConn->query('SET AUTOCOMMIT=1');
    //改回自动提交sql
}