IT博客汇
  • 首页
  • 精华
  • 技术
  • 设计
  • 资讯
  • 扯淡
  • 权利声明
  • 登录 注册

    HTTPS站引用腾讯公益404

    s5s5发表于 2016-04-20 08:35:56
    love 0

    腾讯公益404 并不支持 HTTPS 站点的引用,为了公益事业研究了下,发现只要拉到 http://qzone.qq.com/gy/404/data.js 数据即可,但 HTTPS 站是不能直接拉非安全协议内容,所以还要在自己网站上用一个 PHP 做中转,如下:

    <?php
    header('Content-type: text/javascript');
    $filename = 'data.js';
    clearstatcache();
    $lastTime = filemtime($filename);
    $nowTime = time();
    if ($nowTime - $lastTime > 604800) {
        $url = 'http://qzone.qq.com/gy/404/data.js';
        $html = file_get_contents($url);
        echo $html;
        $file = fopen($filename, "w");
        fwrite($file, $html);
        fclose($file);
    } else {
        readfile($filename);
    }
    

    然后就是,用 JS 读数据显示了,不多说,我的代码如下:

    jQuery.getScript("/gy/404data.php", function () {
      var max = jsondata.data.length;
      var randomUrl = "https://www.random.org/integers/?num=1&min=0&base=10&col=1&format=plain&rnd=new&max=" + max
      jQuery.get(randomUrl, function (data) {
        var num = parseInt(data);
        // console.log(jsondata.data[num]);
        // var picUrl = jsondata.data[num].child_pic.replace(/http:/gi,'https:');
        var picUrl = jsondata.data[num].child_pic;
        var moreUrl = jsondata.data[num].url;
        var more = ' <a href="' + moreUrl + '" target="_blank">查看详情</a>';
        var name = '<strong>' + jsondata.data[num].name + '</strong>';
        var sex = '(' + jsondata.data[num].sex + ")" + ',';
        var birthTime = '出生日期:' + jsondata.data[num].birth_time + ',';
        var lostTime = '失踪时间:' + jsondata.data[num].lost_time + ',';
        var lostPlace = '失踪地点:' + jsondata.data[num].lost_place + ',';
        var childFeature = '失踪人特征描述:' + jsondata.data[num].child_feature;
    
        $('h2').text("你访问的页面找不回来了,但是我们可以一起寻找失踪宝贝");
        $('.img-responsive').attr("src", picUrl);
        $('p.text-muted').addClass('text-left').html(name + sex + birthTime + lostTime + lostPlace + childFeature + more);
      });
    });
    

    效果:https://s5s5.me/gongyi404

    扫码关注米随随



沪ICP备19023445号-2号
友情链接