360截图-25924105.jpg
控制器
<?php
namespace appindexcontroller;
/**

  • 文章控制器类
    */

class ArcComment extends Init
{
public function getqqnickname(){

   if (request()->isPost()){
       $qq = input('param.qq');
       if(!$qq || !preg_match('|^[1-9]\d{4,10}$|i',$qq)){
           return json(array('code'=>0,'msg'=>'QQ格式错误'));
       }
       $nickname = file_get_contents('http://users.qzone.qq.com/fcg-bin/cgi_get_portrait.fcg?uins='.$qq);
       $image = 'http://q.qlogo.cn/headimg_dl?dst_uin='.$qq.'&spec=100';
       if(strstr($nickname,'portraitCallBack')){
           return json(array('code'=>1,'msg'=>'成功','image'=>$image,'data'=>isset(json_decode(trim(mb_convert_encoding($nickname, "UTF-8", "GBK"),'portraitCallBack()'),true)[$qq][6])?json_decode(trim(mb_convert_encoding($nickname, "UTF-8", "GBK"),'portraitCallBack()'),true)[$qq][6]:'游客'));
       }else if(strstr($nickname,'_Callback')){
           return json(array('code'=>0,'msg'=>'获取昵称失败'));
       }
       return json(array('code'=>0,'msg'=>'获取昵称失败'));
   }

}

public function archiveSave()
{
    if (request()->isPost()){
        $data = input('post.');   //aid
        if(!$data["qq"]) return json(array('code'=>0,'msg'=>'请填写QQ'));
        if(!$data["nickname"]) return json(array('code'=>0,'msg'=>'请填写昵称'));
        if(!$data["content"]) return json(array('code'=>0,'msg'=>'请填写内容'));
        $s_data=[];
        $s_data["title"] = strip_tags($data["nickname"]);
        $s_data["content"] = strip_tags($data["content"]);
        $s_data["create_time"] = date("Y-m-d H:i:s",time());
        $s_data["member_id"] = $data["did"];
        $s_data["admin_avatar"] = $data["img"];
        $s_data["cateid"] = $data["cateid"];
        $s_data["turl"] = $data["turl"];
        if(db('feedback')->insert($s_data)){
            return json(array('code'=>1,'msg'=>'评论成功'));
        }else{
            return json(array('code'=>0,'msg'=>'评论失败'));
        }
    }
}

}
HTML
<div class="comt-title">

<div class="comt-avatar">
    <img id="img" src="http://q.qlogo.cn/headimg_dl?dst_uin=547241650&spec=100" class="avatar avatar-100" height="50" width="50" />
</div>

</div>
<form action="{:url('ArcComment/archiveSave')}" method="POST" class="ajax_submit">

<div class="comt-comterinfo" id="comment-author-info">
    <ul>
        <li class="form-inline">
            <label class="hide">请输入QQ号</label>
            <input id="qq" ajax-url="{:url('ArcComment/getQQNickName')}" type="text" name="qq" placeholder="请输入QQ号">
            <span class="text-muted">QQ号 (必填)</span>
        </li>
        <li class="form-inline"><label class="hide">昵称</label>
            <input class="ipt" type="text" name="nickname" id="nickname" value="" tabindex="3" placeholder="自动获取" readonly="readonly" />
            <span class="text-muted">昵称 (自动获取)</span>
        </li>
    </ul>
</div>
<div class="comt">
    <div class="comt-box">
        <textarea placeholder="既然来了 就评论一下吧" class="input-block-level comt-area" name="content" id="comment" cols="100%" rows="3" tabindex="1" onKeyDown="if(event.ctrlKey&amp;&amp;event.keyCode==13){document.getElementById('submit').click();return false};"></textarea>
        <div class="comt-ctrl">
            <div class="comt-tips">
                <input type="hidden" name="did" value="{$data['id']}" id="did" />
                <input type="hidden" name="cateid" value="{$data['category_id']}" id="cateid" />
                <input type="hidden" name="turl" value="{$data['url']}" id="turl" />
                <input type="hidden" name="img" value="" id="imgV"  />
            </div>
            <button type="submit" id="submit" tabindex="5"><i class="icon-ok-circle icon-white icon12"></i> 提交评论</button>
        </div>
    </div>
</div>

</form>
原文地址:https://www.usuuu.com/2-29

控制器
 赞赏   点赞 0
如果觉得我的文章对你有用,请随意赞赏


推荐文章

寻梦xunm

寻梦xunm

奇乐博客专注于Typecho开源程序模板的设计和开发。致力于不断追求设计感和代码的精简语义化只为做出更好的作品。