欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

新闻接口调试

程序员文章站 2023-08-25 23:53:25
HTML: JavaScript: PHP接口(版本7.1.16): ......

新闻接口调试

html:

<style  type="text/css">
    [v-cloak] {
        display: none;
    }

    a{
        color: blue;
        text-decoration: none;
        transition: 1s;
    }
    a:hover{
        color: orange;
        margin-left: 20px;
        transition: 1s;
    }
    ol{
        border: 1px solid #000;
        width: 800px;
        padding-right: 10px;
    }
    .btn,form{
        width: 851.98px;
        display: flex;
        justify-content: space-between;
        align-items: center;
    }
    .btn button{
        padding: 3px 10px;
    }
    .btn span{
        vertical-align: middle;
    }
    p{
        text-align: justify;
        display: grid;
        border-left: 6px solid #ccc;
        background-color: #eee;
        padding: 6px 12px;
    }
    form{
        margin: 0 auto 20px auto;
        justify-content: center;
        margin-bottom: 20px;
    }
    form input[type='text']{
        padding: 3px 10px;
        margin-right: 10px;
    }
    #newslist{
        width: 851.98px;
        margin: 0 auto;
    }
    h3{
        white-space: nowrap;
        text-overflow: ellipsis;
        width: 100%;
        overflow: hidden;
    }
</style>
    <form action="" onsubmit="return false;">
        <label>关键字 <input type="text" name="kw" id="kw" placeholder="请输入关键字"></label>
        <button type="submit">提交</button>
    </form>
    <div id="newslist" v-cloak>
        <div class="btn">
            <button id="prev" v-on:click="prev(kw,num -= 1)" disabled="true">上一页</button>
            <span>{{num}}</span>
            <button id="next" v-on:click="next(kw,num += 1)">下一页</button>
        </div>
        <ol>
            <li v-for="(item) in showdata.data">
                <h3><a v-bind:href="item.url" target="_blank" v-html="item.title"></a></h3>
                <div style="display: flex;justify-content: space-between;">
                    <span>来自:{{item.posterscreenname}}->{{item.posterid}}</span>  
                    <span>发布时间:{{item.publishdatestr}}</span>    
                </div>   
                <p v-if="item.content" v-html="item.content"></p>
            </li>
        </ol>
    </div>

javascript:

 

        // 默认搜索互联网
        // site参数设置网站,
        var vmshownews = new vue({
            el:"#newslist",
            data:{
                showdata:{},
                num:1,
                kw:$('#kw').val(),
                next:function(keyword,num){
                    if ($('#kw').val() == "") {
                        keyword = "互联网";
                    }else{
                        keyword = $('#kw').val();
                    }
                    $.ajax({
                        url: "news.php",
                        async:false,
                        data: {
                            kw:keyword,
                            pagetoken:num
                        },
                        type: "post",
                        datatype: "json",
                        success: function (data) {
                            if(data.retcode == "000000"){
                                if (num == 1) {
                                    $('#prev').attr('disabled',true);
                                }else{
                                    $('#prev').attr('disabled',false);
                                }
                                vmshownews.showdata = data;
                                if (data.hasnext === false) {
                                    $('#next').attr('disabled',true);
                                }
                            }else{
                                alert(data.message);
                            }
                            
                        }
                    }); 
                },
                prev:function(keyword,num){
                    if ($('#kw').val() == "") {
                        keyword = "互联网";
                    }else{
                        keyword = $('#kw').val();
                    }
                    $.ajax({
                        url: "news.php",
                        async:false,
                        data: {
                            kw:keyword,
                            pagetoken:num
                        },
                        type: "post",
                        datatype: "json",
                        success: function (data) {
                            if(data.retcode == "000000"){
                                if (num == 1) {
                                    $('#prev').attr('disabled',true);
                                }
                                vmshownews.showdata = data;
                            }else{
                                alert(data.message);
                            }
                        }
                    });
                }
            }
        })
        vmshownews.next('',1);
        $("button[type='submit']").click(function(){
            vmshownews.next($('#kw').val(),1);
        })

 

php接口(版本7.1.16):

 

<?php
$method = "get";
$url = "120.76.205.241:8000/news/qihoo?apikey=cxhbhftnwpcym2i9tckqz7qk4i6a28ag4ikiwdepvdwcemuhowdzvktj7xjeayiz&kw=" . $_post['kw'] . "&pagetoken=" . $_post['pagetoken'];
$curl = curl_init();
curl_setopt($curl, curlopt_customrequest, $method);
curl_setopt($curl, curlopt_url, $url);
curl_setopt($curl, curlopt_failonerror, false);
curl_setopt($curl, curlopt_returntransfer, true);
// curl_setopt($curl, curlopt_header, true);
curl_setopt($curl, curlopt_encoding, "gzip");
echo curl_exec($curl);
?>