Example #1
0
 public function collectCates()
 {
     setTimeLimit(3600);
     $ccate = FDB::fetchFirst('SELECT * FROM ' . FDB::table('goods_cate_collect') . ' LIMIT 0,1');
     if (!$ccate) {
         return false;
     }
     FDB::query('DELETE FROM ' . FDB::table('goods_cate_collect') . " WHERE id = '{$ccate['id']}'");
     global $_FANWE;
     Cache::getInstance()->loadCache('business');
     //QQ号
     define('PAIPAI_API_UIN', trim($_FANWE['cache']['business']['paipai']['uin']));
     //令牌
     define('PAIPAI_API_APPOAUTHID', trim($_FANWE['cache']['business']['paipai']['appoauthid']));
     //APP_KEY
     define('PAIPAI_API_APPOAUTHKEY', trim($_FANWE['cache']['business']['paipai']['appoauthkey']));
     define('PAIPAI_API_ACCESSTOKEN', trim($_FANWE['cache']['business']['paipai']['accesstoken']));
     define('PAIPAI_API_USERID', trim($_FANWE['cache']['business']['paipai']['userid']));
     $sdk = new PaiPaiOpenApiOauth(PAIPAI_API_APPOAUTHID, PAIPAI_API_APPOAUTHKEY, PAIPAI_API_ACCESSTOKEN, PAIPAI_API_UIN);
     $sdk->setApiPath("/attr/getNavigationChildList.xhtml");
     $sdk->setMethod("get");
     $sdk->setCharset("utf-8");
     $sdk->setFormat("json");
     $params =& $sdk->getParams();
     $params["navigationId"] = $ccate['cid'];
     //请求数据
     $json = $sdk->invoke();
     $json = preg_replace("/[\r\n]/", '', $json);
     preg_match("/getNavigationChildListSuccess\\((.+?)\\);\\}catch\\(/", $json, $list);
     $list = json_decode($list[1], true);
     $sort_file = FANWE_ROOT . '/public/records/cate.sort.php';
     $sort = (int) @file_get_contents($sort_file);
     if (isset($list['childList'])) {
         foreach ($list['childList'] as $item) {
             $cate = array();
             $cate['type'] = 'paipai';
             $cate['id'] = (int) $item['navigationId'];
             if ($cate['id'] > 0) {
                 $cate['pid'] = $ccate['cid'] == 0 ? '' : $ccate['cid'];
                 $cate['name'] = (string) $item['navigationName'];
                 $cate['pids'] = empty($ccate['pids']) ? $cate['pid'] : $ccate['pids'] . ',' . $cate['pid'];
                 $cate['sort'] = ++$sort;
                 FDB::insert('goods_cates', $cate, false, true);
                 if ((int) $item['isClass'] == 0) {
                     FDB::insert('goods_cate_collect', array('id' => 'NULL', 'cid' => $cate['id'], 'pids' => $cate['pids']));
                 }
             }
         }
         @file_put_contents($sort_file, $sort);
     }
     return true;
 }
Example #2
0
 public function collectCates()
 {
     setTimeLimit(3600);
     $ccate = FDB::fetchFirst('SELECT * FROM ' . FDB::table('goods_cate_collect') . ' LIMIT 0,1');
     if (!$ccate) {
         return false;
     }
     FDB::query('DELETE FROM ' . FDB::table('goods_cate_collect') . " WHERE id = '{$ccate['id']}'");
     global $_FANWE;
     Cache::getInstance()->loadCache('business');
     $yiqifa = new YiqifaOpen(trim($_FANWE['cache']['business']['yiqifa']['app_key']), trim($_FANWE['cache']['business']['yiqifa']['app_secret']));
     if ($ccate['cid'] == '0') {
         $list = $yiqifa->getCategoryList();
     } else {
         $list = $yiqifa->getSubCategory($ccate['cid'], 1, 10000);
     }
     $sort_file = FANWE_ROOT . '/public/records/cate.sort.php';
     $sort = (int) @file_get_contents($sort_file);
     if (isset($list['categorys'])) {
         foreach ($list['categorys'] as $item) {
             $cate = array();
             $cate['type'] = 'yiqifa';
             if ($ccate['cid'] == '0') {
                 $cate['id'] = $item['catName'];
                 $cate['name'] = $item['catName'];
             } else {
                 $cate['id'] = $item['subCatName'];
                 $cate['name'] = $item['subCatName'];
             }
             $cate['pid'] = $ccate['cid'] == '0' ? '' : $ccate['cid'];
             $cate['pids'] = empty($ccate['pids']) ? $cate['pid'] : $ccate['pids'] . ',' . $cate['pid'];
             $cate['sort'] = ++$sort;
             FDB::insert('goods_cates', $cate, false, true);
             if ($ccate['cid'] == '0') {
                 FDB::insert('goods_cate_collect', array('id' => 'NULL', 'cid' => $item['catName'], 'pids' => $cate['pids']));
             }
         }
         @file_put_contents($sort_file, $sort);
     }
     return true;
 }
 function SaveVisitorListToFile()
 {
     setTimeLimit(300);
     if ($this->CreateVisitorList) {
         createFile($this->GetFilename(true, true), $this->GetUsersHTML(), true, false);
     }
 }
Example #4
0
    public function collectReport($time, $page)
    {
        setTimeLimit(3600);
        global $_FANWE;
        if ($page <= 1) {
            FDB::query('TRUNCATE TABLE ' . FDB::table('taobaoke_report_temp'));
        }
        include_once FANWE_ROOT . 'sdks/taobao/TopClient.php';
        include_once FANWE_ROOT . 'sdks/taobao/request/TaobaokeReportGetRequest.php';
        Cache::getInstance()->loadCache('business');
        $client = new TopClient();
        $client->appkey = trim($_FANWE['cache']['business']['taobao']['app_key']);
        $client->secretKey = trim($_FANWE['cache']['business']['taobao']['app_secret']);
        $req = new TaobaokeReportGetRequest();
        $req->setFields("num_iid,outer_code,commission_rate,real_pay_fee,app_key,outer_code,pay_time,pay_price,commission,item_title,item_num,trade_id");
        $page_size = 100;
        $time = fToDate($time, 'Ymd');
        $req->setDate($time);
        $req->setPageNo($page);
        $req->setPageSize($page_size);
        $resp = (array) $client->execute($req, trim($_FANWE["cache"]["business"]["taobao"]["session_key"]));
        $is_complete = false;
        $total_results = 0;
        if (isset($resp['taobaoke_report'])) {
            $count = 0;
            $taobaoke_report = (array) $resp['taobaoke_report'];
            $total_results = (int) $taobaoke_report['total_results'];
            if ($total_results > 0) {
                $taobaoke_report_members = $taobaoke_report['taobaoke_report_members'];
                foreach ($taobaoke_report_members->taobaoke_report_member as $item) {
                    $item = (array) $item;
                    $item['pay_time'] = str2Time($item['pay_time']);
                    $item['outer_code'] = isset($item['outer_code']) ? $item['outer_code'] : '';
                    $pay_day = fToDate($item['pay_time'], 'Y-m-d 00:00:00');
                    $item['pay_day'] = str2Time($pay_day);
                    $item['commission_rate'] = $item['commission_rate'] * 100;
                    $item['item_title'] = addslashes($item['item_title']);
                    if (!empty($item['outer_code']) && preg_match("/^o\\d+\$/", $item['outer_code'])) {
                        $order_id = (double) substr($item['outer_code'], 1);
                        if ($order_id == 0) {
                            continue;
                        }
                        $bln = (int) FDB::resultFirst('SELECT COUNT(id) FROM ' . FDB::table('taobaoke_report') . " \n\t\t\t\t\t\t\tWHERE outer_code = '" . addslashes($item['outer_code']) . "' \n\t\t\t\t\t\t\t\tAND num_iid = '" . addslashes($item['num_iid']) . "' \n\t\t\t\t\t\t\t\tAND pay_time = '" . addslashes($item['pay_time']) . "'");
                        if ($bln > 0) {
                            continue;
                        }
                        $is_insert = false;
                        $res = FDB::query('SELECT * FROM ' . FDB::table('goods_order') . ' 
							WHERE order_id = ' . $order_id . ' AND keyid = \'taobao_' . $item['num_iid'] . '\' AND status = 0');
                        while ($order = FDB::fetch($res)) {
                            $commission = (double) $item['commission'] * ((double) $order['commission_rate'] / 100);
                            if ($_FANWE['setting']['goods_buy_score_type'] > 0 && $_FANWE['setting']['goods_buy_score_rate'] > 0) {
                                $score = 0;
                                $rate = (double) $_FANWE['setting']['goods_buy_score_rate'];
                                if ($_FANWE['setting']['goods_buy_score_type'] == 1) {
                                    $score = (double) $item['real_pay_fee'] * $rate;
                                } else {
                                    $score = (double) $item['commission'] * $rate;
                                }
                                $score = round($score);
                                if ($score > 0) {
                                    FS('User')->updateUserScore((int) $order['uid'], 'goods', 'commission', '成功购买商品 ' . $item['item_title'] . ' 获得积分', $order_id, $score);
                                }
                            }
                            FDB::query('UPDATE ' . FDB::table('goods_order') . ' SET status = 1,settlement_time = ' . TIME_UTC . ',commission = ' . $commission . ' WHERE order_id = ' . $order_id . ' AND uid = ' . (int) $order['uid']);
                            $is_insert = true;
                        }
                        if ($is_insert) {
                            FDB::insert('taobaoke_report_temp', $item);
                        }
                    }
                }
                if ($page * $page_size >= $total_results) {
                    FDB::query('INSERT INTO ' . FDB::table('taobaoke_report') . '(id,trade_id,num_iid,item_title,item_num,pay_price,real_pay_fee,commission_rate,commission,outer_code,app_key,pay_time,pay_day) SELECT NULL AS id,trade_id,num_iid,item_title,item_num,pay_price,real_pay_fee,commission_rate,commission,outer_code,app_key,pay_time,pay_day FROM ' . FDB::table('taobaoke_report_temp') . ' ORDER BY pay_time ASC,trade_id ASC');
                    return 1;
                } else {
                    return 0;
                }
            } else {
                return 1;
            }
        }
        return -1;
    }
function downloadFromMailbox(&$_reload, $_type, $_server, $_port, $_password, $_account, $_secure, $_delete, $_test = false)
{
    global $CONFIG;
    $starttime = time();
    $executiontime = setTimeLimit(CALLER_TIMEOUT - 10);
    loadLibrary("ZEND", "Zend_Mail");
    $list = array();
    $config = array('host' => $_server, 'auth' => 'login', 'user' => $_account, 'password' => $_password, 'port' => $_port);
    if (!empty($_secure)) {
        $config['ssl'] = $_secure == 1 ? 'SSL' : 'TLS';
    }
    try {
        if ($_type == "IMAP") {
            loadLibrary("ZEND", "Zend_Mail_Storage_Imap");
            $mail = new Zend_Mail_Storage_Imap($config);
        } else {
            loadLibrary("ZEND", "Zend_Mail_Storage_Pop3");
            $mail = new Zend_Mail_Storage_Pop3($config);
        }
    } catch (Exception $e) {
        if ($_test) {
            throw $e;
        } else {
            handleError("111", $_server . " " . $_type . " mailbox connection error: " . $e->getMessage(), "functions.global.inc.php", 0);
        }
        return $list;
    }
    $message = null;
    $delete = array();
    $subject = "";
    try {
        $counter = 0;
        foreach ($mail as $mnum => $message) {
            if ($_test) {
                return count($mail);
            }
            try {
                $temail = new TicketEmail();
                if ($message->headerExists("subject")) {
                    $subject = $temail->Subject = mimeHeaderDecode($message->Subject);
                }
                if ($message->headerExists("message-id")) {
                    $temail->Id = str_replace(array("<", ">"), "", $message->MessageId);
                }
                if (empty($temail->Id)) {
                    $temail->Id = getId(32);
                }
                if ($_delete) {
                    $delete[$mnum] = $temail->Id;
                }
                if (strpos($message->From, "<") !== false) {
                    $fromparts = explode("<", str_replace(">", "", $message->From));
                    if (!empty($fromparts[0])) {
                        $temail->Name = str_replace(array("\""), "", mimeHeaderDecode(trim($fromparts[0])));
                    }
                    $temail->Email = trim($fromparts[1]);
                } else {
                    $temail->Email = trim($message->From);
                }
                if (strpos($message->To, "<") !== false) {
                    $toparts = explode("<", str_replace(">", "", $message->To));
                    $temail->ReceiverEmail = trim($toparts[1]);
                } else {
                    $temail->ReceiverEmail = trim($message->To);
                }
                if ($message->headerExists("reply-to")) {
                    if (strpos($message->ReplyTo, "<") !== false) {
                        $rtoparts = explode("<", str_replace(">", "", $message->ReplyTo));
                        $temail->ReplyTo = trim($rtoparts[1]);
                    } else {
                        $temail->ReplyTo = trim($message->ReplyTo);
                    }
                }
                $parts = array();
                if ($message->isMultipart()) {
                    foreach (new RecursiveIteratorIterator($message) as $part) {
                        $parts[] = $part;
                    }
                } else {
                    $parts[] = $message;
                }
                foreach ($parts as $part) {
                    try {
                        if ($part->headerExists("content-type")) {
                            $ctype = $part->contentType;
                        } else {
                            $ctype = 'text/html';
                        }
                        if ($part->headerExists("content-disposition")) {
                            $ctype .= "; " . $part->contentDisposition;
                        }
                        $charset = "";
                        $hparts = explode(";", str_replace(" ", "", $ctype));
                        foreach ($hparts as $hpart) {
                            if (strpos(strtolower($hpart), "charset=") === 0) {
                                $charset = trim(str_replace(array("charset=", "'", "\""), "", strtolower($hpart)));
                            }
                        }
                        $isatt = strpos(strtolower($ctype), "name=") !== false || strpos(strtolower($ctype), "filename=") !== false;
                        if (DEBUG_MODE) {
                            logit(" PROCESSING EMAIL / charset:" . $ctype . " - " . $charset . " - " . $subject . " - " . $isatt);
                        }
                        if (!$isatt && (($html = strpos(strtolower($ctype), 'text/html') !== false) || strpos(strtolower($ctype), 'text/plain') !== false)) {
                            $content = $part->getContent();
                            foreach ($part->getHeaders() as $name => $value) {
                                if (strpos(strtolower($name), 'content-transfer-encoding') !== false && strpos(strtolower($value), 'quoted-printable') !== false) {
                                    $content = quoted_printable_decode($content);
                                } else {
                                    if (strpos(strtolower($name), 'content-transfer-encoding') !== false && strpos(strtolower($value), 'base64') !== false) {
                                        $content = base64_decode($content);
                                    }
                                }
                            }
                            if ($html) {
                                if (!empty($CONFIG["gl_avhe"])) {
                                    $temail->BodyHTML = max($temail->BodyHTML, $content);
                                }
                                @set_error_handler("ignoreError");
                                try {
                                    require_once LIVEZILLA_PATH . "_lib/trdp/html2text.php";
                                    $content = convert_html_to_text($content);
                                } catch (Exception $e) {
                                    $content = preg_replace("/<style\\b[^>]*>(.*?)<\\/style>/s", "", $content);
                                    $content = trim(html_entity_decode(strip_tags($content), ENT_COMPAT, "UTF-8"));
                                    $content = preg_replace('/[\\s\\s\\s\\s\\s\\s]+/', " ", $content);
                                }
                                @set_error_handler("handleError");
                            }
                            if ((!$html || empty($temail->Body)) && !empty($content)) {
                                if (strpos(strtolower($charset), 'utf-8') === false && !empty($charset)) {
                                    if (DEBUG_MODE) {
                                        logit(" PROCESSING EMAIL / iconv | " . strtoupper($charset) . " | " . 'UTF-8' . " | " . $subject);
                                    }
                                    $temail->Body = @iconv(strtoupper($charset), 'UTF-8', $content);
                                } else {
                                    if ($html && empty($charset)) {
                                        $temail->Body = utf8_encode($content);
                                    } else {
                                        $temail->Body = $content;
                                    }
                                }
                            }
                        } else {
                            $filename = "";
                            $fileid = getId(32);
                            $unknown = getId(32);
                            $filesid = $CONFIG["gl_lzid"] . "_" . $fileid;
                            foreach ($hparts as $hpart) {
                                $hpart = mimeHeaderDecode($hpart);
                                if (strpos(strtolower(trim($hpart)), "name=") === 0 || strpos(strtolower(trim($hpart)), "filename=") === 0) {
                                    $filename = trim(str_replace(array("filename=", "name=", "'", "\""), "", strtolower($hpart)));
                                } else {
                                    if ($part->headerExists("content-id") && empty($filename)) {
                                        $filename = trim(str_replace(array("<", ">", "'", "\""), "", strtolower($part->contentId)));
                                    } else {
                                        if (strpos(strtolower($ctype), 'message/rfc822') !== false && $part->headerExists("subject") && empty($filename)) {
                                            $filename = trim($part->Subject) . ".eml";
                                        } else {
                                            if (strpos(strtolower($ctype), 'message/rfc822') !== false) {
                                                $unknown = "unknown.eml";
                                            }
                                        }
                                    }
                                }
                            }
                            $base64dec = !(strpos(strtolower($ctype), 'message/rfc822') !== false || strpos(strtolower($ctype), 'text/plain') !== false);
                            foreach ($part->getHeaders() as $name => $value) {
                                if (strpos(strtolower($name), 'content-transfer-encoding') !== false && strpos(strtolower($value), 'base64') !== false) {
                                    $base64dec = true;
                                }
                            }
                            $filename = empty($filename) ? $unknown : str_replace(array("\\", ":", "?", "*", "<", ">", "|", "/", "\""), "", $filename);
                            $content = !$base64dec ? $part->getContent() : base64_decode($part->getContent());
                            $temail->Attachments[$fileid] = array($filesid, $filename, $content);
                            if (DEBUG_MODE) {
                                logit("ADD ATT: " . $filesid . " - " . $filename . " - " . $ctype);
                            }
                        }
                    } catch (Exception $e) {
                        handleError("112", $_server . " imap Email Part Error: " . $e->getMessage() . ", email: " . $subject, "functions.global.inc.php", 0);
                    }
                }
                $temail->Created = strtotime($message->Date);
                if ((!is_numeric($temail->Created) || empty($temail->Created)) && $message->headerExists("delivery-date")) {
                    $temail->Created = strtotime($message->DeliveryDate);
                }
                if (!is_numeric($temail->Created) || empty($temail->Created)) {
                    $temail->Created = time();
                }
                $list[] = $temail;
                if (time() - $starttime >= $executiontime / 2 || $counter++ > DATA_ITEM_LOADS) {
                    $_reload = true;
                    break;
                }
            } catch (Exception $e) {
                if ($_test) {
                    throw $e;
                } else {
                    handleError("115", $_type . " Email Error: " . $e->getMessage() . ", email: " . $subject, "functions.global.inc.php", 0);
                }
            }
        }
        try {
            krsort($delete);
            foreach ($delete as $num => $id) {
                $mail->removeMessage($num);
            }
        } catch (Exception $e) {
            if ($_test) {
                throw $e;
            } else {
                handleError("114", $_type . " Email delete error: " . $e->getMessage() . ", email: " . $subject, "functions.global.inc.php", 0);
            }
        }
    } catch (Exception $e) {
        if ($_test) {
            throw $e;
        } else {
            handleError("113", $_type . " Email Error: " . $e->getMessage() . ", email: " . $subject, "functions.global.inc.php", 0);
        }
    }
    return $list;
}
Example #6
0
$DBA = 0;
$RESPONSE = new Response();
if (!isset($_POST[POST_INTERN_ADMINISTRATE]) && isset($_POST["p_request"]) && $_POST["p_request"] == CALLER_TYPE_INTERNAL) {
    header("Content-Type: text/xml; charset=UTF-8");
    if (getIdle()) {
        $RESPONSE->SetValidationError(LOGIN_REPLY_IDLE);
        exit($RESPONSE->GetXML());
    }
    if (!getAvailability() && $_POST[POST_INTERN_SERVER_ACTION] == INTERN_ACTION_LOGIN && !isset($_POST[POST_INTERN_ACCESSTEST])) {
        $RESPONSE->SetValidationError(LOGIN_REPLY_DEACTIVATED);
        exit($RESPONSE->GetXML());
    }
}
require LIVEZILLA_PATH . "_definitions/definitions.dynamic.inc.php";
initDataProvider();
setTimeLimit($CONFIG["timeout_clients"]);
@ini_set('session.use_cookies', '0');
if (DEBUG_MODE) {
    @ini_set('display_errors', '1');
}
@set_error_handler("handleError");
header("Access-Control-Allow-Origin: *");
if (isset($_POST["p_request"]) || isset($_GET[GET_SERVER_REQUEST_TYPE])) {
    if (DB_CONNECTION && STATS_ACTIVE) {
        initStatisticProvider();
    }
    if (DB_CONNECTION && (isset($_POST["p_request"]) && $_POST["p_request"] == CALLER_TYPE_TRACK || isset($_GET[GET_SERVER_REQUEST_TYPE]) && $_GET[GET_SERVER_REQUEST_TYPE] == CALLER_TYPE_TRACK)) {
        define("CALLER_TYPE", CALLER_TYPE_TRACK);
        define("CALLER_TIMEOUT", $CONFIG["timeout_track"]);
        header("Keep-Alive: timeout=5, max=100");
        header("Content-Type: text/javascript; charset=UTF-8");