分类 cms 下的文章

cms使用过程中,会遇到父栏目直接链接到第一个子栏目的情况,最方便的方法就行栏目设置填写外链,即直接填写/xxx.html,这样生成的网站地图中的这个栏目链接也就变成/xxx.html了,不会自带域名,下面是修复办法
1.indexController.php加入以下函数

//生成完整链接函数
function completeUrl($url, $siteDomain) {
    if (preg_match('~^https?://~i', $url)) {
        return $url;
    }
    $domain = rtrim($siteDomain, '/');
    $path = ltrim($url, '/');
    return $domain . '/' . $path;
}

2.在文件下面找到网站地图生成函数,在栏目逻辑这里应用函数

 if($v=='classtype'){
    foreach($list as $s){
      if($this->classtypedata[$s['id']]['url']){
         if($cachedata){
             echo $this->completeUrl($this->classtypedata[$s['id']]['url'], $www).'<br>';
          }
          if($filetype=='xml'){
              $l_pc.='<url>
        <loc>'.$this->completeUrl($this->classtypedata[$s['id']]['url'], $www).'</loc>
            <lastmod>'.date('Y-m-d').'T08:00:00+00:00</lastmod>
            <changefreq>'.$freq[$k].'</changefreq>
            <priority>'.$priority[$k].'</priority>
             </url>';

 // 获取access_token
    private function getAccessToken($url, $header)
    {
        $curl = curl_init();
        curl_setopt($curl, CURLOPT_URL, $url);
        curl_setopt($curl, CURLOPT_HEADER, 0);
        curl_setopt($curl, CURLOPT_TIMEOUT, 1);
        curl_setopt($curl, CURLOPT_HTTPHEADER, $header);
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
        curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
        return curl_exec($curl);
    } 
  // 微信授权登录
 function wxAuthLogin()
    {
       // $param = $this->request->param();
        $code = $this->frparam('code',1,'','POST');
        $appid = 'appid';
        $secret = 'appSecrect';
        $url = "https://api.weixin.qq.com/cgi-bin/token?appid=$appid&secret=$secret&grant_type=client_credential";
        try {
            $header = array('Accept: application/json',);
            // 获取access_token
            $wx_access_token = json_decode($this->getAccessToken($url, $header), true);
 
            $url = "https://api.weixin.qq.com/wxa/business/getuserphonenumber?access_token=" . $wx_access_token['access_token'];
            $data = array('code' => $code); // 请确保$code变量已经定义
            $options = array(
                'http' => array(
                    'header' => "Content-Type: application/json\r\n",
                    'method' => 'POST',
                    'content' => json_encode($data)
                )
            );
            $context = stream_context_create($options);
            $response = file_get_contents($url, false, $context);
            $result = json_decode($response, true);
            if ($result['errcode'] != 0) {
                JsonReturn(["code" => 1, "msg" => '登录失败']);
            }else{
               $tel = $result['phone_info']['phoneNumber'];
               $m = M('member')->find(['tel'=>$w['tel']]);
              if($m){
                  //走登录流程
                  $update['logintime'] = time();
                   M('member')->update(array('id'=>$m['id']),$update);
                   
                   $payload = [
                        'userId' => $m['id'], 
                        'exp' => time() + 60,     // 1小时后过期
                        'tel' => $tel          // 自定义数据
                        ];
                   $userInfo['name']=$m['username'];
                   $userInfo['id']=$m['id'];
                   $userInfo['litpic']=$m['litpic'];
                   $token =TokenManager::generateToken($payload);
                  
                   JsonReturn(['code'=>0,'msg'=>'登录成功!','token'=>$token,userInfo=>$userInfo]);
               }else{
                   //新增用户
                     //$w['username'] = getRandChar(6);
                     $w['username'] = '微信用户';
                    $w['tel'] = $tel;
                    $w['gid'] = 1;
                    $w['litpic'] = 'https://thirdwx.qlogo.cn/mmopen/vi_32/POgEwh4mIHO4nibH0KlMECNjjGxQUq24ZEaGT4poC6icRiccVGKSyXwibcPq4BWmiaIGuG1icwxaQX6grC9VemZoJ8rg/132';
                    $w['regtime']=time();
                    $r = M('member')->add($w);  
                    if($r){
                        //走登录流程
                       $payload = [
                            'userId' => $r['id'], 
                            'exp' => time() + 60,     // 1小时后过期
                            'tel' => $tel          // 自定义数据
                            ];
                       $userInfo['name']=$w['username'];
                       $userInfo['id']=$r['id'];
                       $userInfo['litpic']=$w['litpic'];
                       $token =TokenManager::generateToken($payload);
                       JsonReturn(['code'=>0,'msg'=>'登录成功!','token'=>$token,userInfo=>$userInfo]); 
                            
                        
                    }
               }

              
            }
           

        } catch (Exception $exception) {
            return json(["code" => 0, "msg" => $exception->getMessage()]);
        }
    }

function view(){
    if($_POST){
         $id = $this->frparam('tid',1);
         if($id){
             $view_time = time();
             $view_key = getRandChar(8);
             $res = M('classtype')->update(['id'=>$id],['view_key'=>$view_key,'view_time'=>$view_time]);
             if($res){
                 JsonReturn(['code'=>0,'msg'=>'链接生成!','url'=>'http://u.upic.top/case.html?key='.$view_key]); 
             }else{
                 JsonReturn(['code'=>1,'msg'=>'链接生成失败!']); 
             } 
         }
         
          else{
          JsonReturn(['code'=>1,'msg'=>'参数错误!']); 
          }
    }    
}

<input type="text" id="keyword"><button id="so">搜索</button>
<ul id="data"></ul>
<button class="ajaxMore" style="display: none">加载更多</button>
<script type="text/javascript">
let curpage = 1;
let limit=15;
let sum =0;
let _fields='id,tid,title,keywords,description,litpic,body,htmlurl,target,addtime';
let _serUrl ="/GetData/getDataSearch.html";
let _model='article';
let _key='232323';
let _word = '';
let _title = 'title';
$("#so").click(function(){
    _word = $("#keyword").val();
    let  html='';
    $.ajax({
     url:_serUrl,
     dataType:"json",
     async:true,
     data:{model:_model,key:_key,search:_title,word:_word,fields:_fields,limit:limit,page:curpage},
     type:"POST",
     success:function(r){
         console.log(r);
            sum = r.sum;
             if(sum>=1&&sum<=limit){
                 $(".ajaxMore").show().html('没有更多了!');
            }else if(sum>limit){
                  $(".ajaxMore").show();
            }else{
                $(".ajaxMore").show().html('无相关数据');
            }
            $("#data").html('');
                for(const item of r.data){
                  html+=`<li><h4>${item.title}</h4></li>`;
                }
           $("#data").html(html);    
    },
     error:function(){

    }
    })

})
    
$(".ajaxMore").click(function(){
        curpage++;    
        let html = '';
        $.ajax({
             url:_serUrl,
             dataType:"json",
             async:true,
             data:{model:_model,key:_key,search:_title,word:_word,fields:_fields,limit:limit,page:curpage},
             type:"POST",
             success:function(r){
                 if(r.data.length>0){
                     let allpage = r.allpage;
                    if(curpage<=allpage){
                        if(r.data.length<limit){
                           $(".ajaxMore").text('没有更多了!');
                         };
                        for(const item of r.data){
                              html+=`<li><h4>${item.title}</h4></li>`
                         }
                        $("#data").append(html);
                         

                       }
               }

             }
        })


})


</script>