public function view_track() { $data = TrackInquiryAct::actTrack(); $this->smarty->assign('title', "Check Result New"); $this->smarty->assign('keywords', "{$data['carrierEn']},{$data['tracknum']},Check Result"); $this->smarty->assign('description', "{$data['carrierEn']} {$data['tracknum']} Check Result"); $this->smarty->assign('carrier', $data['carrier']); $this->smarty->assign('carrierEn', $data['carrierEn']); $this->smarty->assign('tracknum', $data['tracknum']); $this->smarty->assign('carriers', $data['carriers']); $this->smarty->assign('version', C("SYSTEM_VERSION")); $this->smarty->display('trackInquiryTrackNew.htm'); }
/** * TrackInquiryAct::act_trackInfoEn() * 查询目的地跟踪信息 * @param string $carrier 运输方式名称 * @param string $tracknum 跟踪号 * @param string $tracklan 语言 * @return json string */ public function act_trackInfoEn() { $carrier = isset($_REQUEST['carrier']) ? post_check($_REQUEST['carrier']) : ''; $tracknum = isset($_REQUEST['tracknum']) ? post_check($_REQUEST['tracknum']) : ''; $tracklan = isset($_REQUEST['tracklan']) ? abs(intval($_REQUEST['tracklan'])) : 10000; $ip = getClientIP(); $ipNum = sprintf('%u', ip2long($ip)); if (in_array($carrier, array('美国邮政'))) { $tracklan = 10000; } if (empty($carrier)) { self::$errCode = 10000; self::$errMsg = "运输方式参数非法!"; @write_a_file(self::$logFile, date('Y-m-d H:i:s') . "=====" . $ip . "=====" . $carrier . "=====" . $tracknum . "=====" . $tracklan . "=====event:" . self::$errMsg . "\n"); return false; } if (empty($tracknum)) { self::$errCode = 10001; self::$errMsg = "跟踪号参数非法!"; @write_a_file(self::$logFile, date('Y-m-d H:i:s') . "=====" . $ip . "=====" . $carrier . "=====" . $tracknum . "=====" . $tracklan . "=====event:" . self::$errMsg . "\n"); return false; } //访问统计逻辑 $data = array(); $times = time(); $maxcount = C("USER_MAX_COUNT"); $exptime = C("USER_EXPIRES_TIME"); $res = TrackInquiryModel::showIpStat($ipNum); $stats = isset($res['count']) ? $res['count'] : 0; $exptimes = isset($res['expires']) ? $res['expires'] : 0; $data['trackInfoEn'] = array(); if ($stats > $maxcount && $exptimes > $times && !in_array($ip, array('183.233.230.2'), true)) { array_push($data['trackInfoEn'], array("postion" => "server", "event" => "{$ip}:Visits over", "trackTime" => date('Y-m-d H:i:s', time()), "stat" => 0)); @write_a_file(self::$logFile, date('Y-m-d H:i:s') . "=====" . $ip . "=====" . $carrier . "=====" . $tracknum . "=====" . $tracklan . "=====event:Visits over\n"); return $data; exit; } if (!$stats) { $res = TrackInquiryModel::updateStatInfo($ipNum, array("ip" => $ip, "count" => 1, "expires" => $times + $exptime, "ipNum" => $ipNum)); } else { if ($exptimes < $times) { $res = TrackInquiryModel::updateStatInfo($ipNum, array("ip" => $ip, "count" => 1, "expires" => $times + $exptime, "ipNum" => $ipNum)); } else { $res = TrackInquiryModel::updateStatInfo($ipNum, array("ip" => $ip, "count" => $stats + 1, "ipNum" => $ipNum)); } } //查询跟踪信息并memcache $cacheName = md5("track_number_info" . $carrier . "_" . $tracknum . "_" . $tracklan); $memc_obj = new Cache(C('CACHEGROUP')); $trackInfo = $memc_obj->get_extral($cacheName); $trackInfo = @unserialize($trackInfo); if (!empty($trackInfo['trackInfo'])) { @write_a_file(self::$logFile, date('Y-m-d H:i:s') . "=====" . $ip . "=====" . $carrier . "=====" . $tracknum . "=====" . $tracklan . "=====event:memcache success\n"); return $trackInfo; } else { $trackInfo = TrackInquiryModel::trackInfoEn($carrier, $tracknum, $tracklan); if (!in_array($trackInfo['trackInfoEn'][0]['event'], array('Time out', 'time out', 'No data', 'System Interface exceptions,Please try again!'))) { $isok = $memc_obj->set_extral($cacheName, serialize($trackInfo), 7200); if (!$isok) { self::$errCode = 0; self::$errMsg = 'memcache缓存出错!'; @write_a_file(self::$logFile, date('Y-m-d H:i:s') . "=====" . $ip . "=====" . $carrier . "=====" . $tracknum . "=====" . $tracklan . "=====event:" . self::$errMsg . "\n"); //return false; } } if (in_array($trackInfo['trackInfoEn'][0]['event'], array('Time out', 'time out'))) { @write_a_file(self::$logFile, date('Y-m-d H:i:s') . "=====" . $ip . "=====" . $carrier . "=====" . $tracknum . "=====" . $tracklan . "=====event:" . $trackInfo['trackInfo'][0]['event'] . "\n"); } if ($trackInfo['trackInfoEn'][0]['postion'] == 'No data') { @write_a_file(self::$logFile, date('Y-m-d H:i:s') . "=====" . $ip . "=====" . $carrier . "=====" . $tracknum . "=====" . $tracklan . "=====event:" . $trackInfo['trackInfo'][0]['event'] . "\n"); } if (empty($trackInfo['trackInfoEn'])) { @write_a_file(self::$logFile, date('Y-m-d H:i:s') . "=====" . $ip . "=====" . $carrier . "=====" . $tracknum . "=====" . $tracklan . "=====event:接口获取数据异常\n"); } @write_a_file(self::$logFile, date('Y-m-d H:i:s') . "=====" . $ip . "=====" . $carrier . "=====" . $tracknum . "=====" . $tracklan . "=====event:api interface success\n"); return $trackInfo; } }