GeoIp2\Exception\AddressNotFoundException

bug问题 · xhqwyz · 于 3年前 发布 · 1287 次阅读

fa统计链接打开报错

共收到 4 条回复
Fecmall#13年前 0 个赞

已收到,晚上测试一下。

Fecmall#23年前 0 个赞

1.把报错信息全部贴上去,把报错信息全部贴上去,把报错信息全部贴上去!!!!

能用文字就不要用截图,截图无法搜索!!!

2.你这个IP, 172.22.0.1是内网IP?查不到抛出异常!

3.重新处理了一下,你打开文件 ./addons/fecmall/fecfa/services/Fa.php ,覆盖一下内容试试

<?php

/*
 * FecShop file.
 *
 * @link http://www.fecshop.com/
 * @copyright Copyright (c) 2016 FecShop Software LLC
 * @license http://www.fecshop.com/license/
 */

namespace fecfa\services;

use fecshop\services\Service;
use GeoIp2\Database\Reader;
use Yii;
/**
 * FA service.
 * @author Terry Zhao <2358269014@qq.com>
 * @since 1.0
 */
class Fa extends Service
{
    /**
     * @param $ipStr | string, ip字符串,譬如:111.21.3.4
     * @return array, 根据ip地址,得到对应的国家,省,市 信息数组
     */
    public function getCountryCityByIp($ipStr)
    {
        $geoIpDataMmdb = Yii::getAlias('@common/lib/GeoLite2-City/GeoLite2-City.mmdb');
        if (!file_exists($geoIpDataMmdb)) {
            
            return null;
        }
        
        try {
            $reader = new Reader($geoIpDataMmdb);
            $record = $reader->city($ipStr);
            $countryCode = $record->country->isoCode ; // 'US'
            $countryName = $record->country->name ; // 'United States'
            $countryCnName = $record->country->names['zh-CN']; // '美国'
            $stateName = $record->mostSpecificSubdivision->name;
            $stateCnName = $record->mostSpecificSubdivision->names['zh-CN'];
            $cityName = $record->city->name;
            $cityCnName = $record->city->names['zh-CN'];
            
            return [
                'country' => [
                    'code' => $countryCode,
                    'name' => $countryName,
                    'cn_name' => $countryCnName ,
                ] ,
                'state' => [
                    'name' => $stateName,
                    'cn_name' => $stateCnName,
                ],
                'city' => [
                    'name' => $cityName,
                    'cn_name' => $cityCnName,
                ],
            ];
        } catch (\Exception $e) {
            $errors = $e->getMessage();
            Yii::$service->helper->errors->add($errors);
            
            return [
                'country' => [
                    
                ] ,
                'state' => [
                    
                ],
                'city' => [
                    
                ],
            ];
        }
    }
    /**
     * 连续创建几天的db库表索引,供未来使用,
     */
    protected $initAfterDays = 5;
    /**
     * 初始化mongo db index
     * 
     */ 
    public function initDBIndexes()
    {
        $websites = Yii::$service->fa->website->getAllActiveWebsite();
        //var_dump($websites);
        if (!is_array($websites) || empty($websites)) {
            
            return true;
        }
        
        foreach ($websites as $website) {
            $websiteId = $website['website_id'];
            for ($i=0;$i<=$this->initAfterDays;$i++) {
                $dateStr = date('Y-m-d',strtotime('+ '.$i.' days'));
                
                $this->createInitDbIndexes($dateStr, $websiteId);
            }
        }
        
    }
    /**
     * @param $dateStr | string ,时间字符串,譬如: 2020-10-11
     * @param $websiteId | string,website Id,
     * 创建trace和customer 的coll索引。
     */
    public function createInitDbIndexes($dateStr, $websiteId)
    {
        // trace 系列表,加索引
        $traceDbName = Yii::$service->fa->mdb->getTraceDbNameByDate($dateStr);
        $traceCollName = Yii::$service->fa->mdb->getTraceDataCollName($websiteId);
        
        $traceIndexes = [
            ['key' => ['order.invoice'], 'background' => true],
            ['key' => ['uuid', '_id'], 'background' => true],
            ['key' => ['ip'], 'background' => true],
            ['key' => ['customer_id'], 'background' => true],
            ['key' => ['uuid', 'service_timestamp'], 'background' => true],
            
        ];
        Yii::$service->fa->mdb->createIndexes($traceDbName, $traceCollName, $traceIndexes);
        
        // customer表加索引
        $customerDbName = Yii::$service->fa->mdb->getCustomerDbName();
        $customerCollName = Yii::$service->fa->mdb->getCustomerCollName($websiteId);
        $customerIndexes = [
            ['key' => ['customer_id'], 'background' => true],
            ['key' => ['uuids'], 'background' => true],
            ['key' => ['emails'], 'background' => true],
        ];
        Yii::$service->fa->mdb->createIndexes($customerDbName, $customerCollName, $customerIndexes);
        
    }
    
    
    
    
    
    
    
    
    
    
    
    
    
}

xhqwyz#33年前 0 个赞

覆盖了 还是报错

Fecmall#43年前 0 个赞

1.把你的报错全部贴上来,贴这么点没啥用

2.本地无法重现你的问题

3.你这个ip是个什么鬼IP?根本就不是个ip,数据库查不到抛出异常 但是,重新处理的代码里面已经用try catch处理异常了,怎么还会报错?

你自己尝试debug一下,本人这里无法复现问题

出来问题,自己先尝试解决一下,别等着别人说一句,你操作一句,你自己debug一下试试,问题的解决靠你自己,本人只能给你提供一些辅助信息。

添加回复 (需要登录)
需要 登录 后方可回复, 如果你还没有账号请点击这里 注册
Your Site Analytics