• 当前位置: 首 页 > 教育百科 > 其他 > 正文

    ueditor复制微信,csdn等其他网站文章图片因防盗链不显示

    :2019年08月18日
    本站

    文章中缩写的封装替换url(html5.qq.com)方法已经失效,最新的办法,用PHP模拟浏览器请求,转发img的src请求到一个自己写的action,然后在action里面获取图片流,再将图片写到网页上。原盗链的原理:官...

    文章中缩写的封装替换url(html5.qq.com)方法已经失效,最新的办法,用PHP模拟浏览器请求,转发img的src请求到一个自己写的action,然后在action里面获取图片流,再将图片写到网页上。

    原盗链的原理:
    官方输出图片的时候,判断了来源(Referer),就是从哪个网站访问这个图片,如果是你的网站去加载这个图片,那么Referer就是:你的网站地址;;你网站地址,肯定没在官方的白名单内,所以就看不到图片了。

    我们做这个跳板的关键:不发送Referer,也就是没有来源。那么官方那边,就认为是从浏览器直接访问的,所以就能加载正常的图片了。

    ueditor 复制微信文章图片因防盗链不显示

    将以下代码单独引入,或者放在封装的js里都可。

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    UE.plugin.register('wximage'function (){
    var u = baidu;
    var a = this
    , c = u.editor.ui
    , b = u.editor.dom.domUtils;
    function strip_stack_span(html) {
    var docObj = $('' + html + '');
    docObj.find('li,colgroup,a').each(function() {
    if ($.trim($(this).text()) == "" && $(this).find('img').size() == 0) {
    $(this).remove();
    }
    }
    );
    var has_secspan = false;
    do 
    {
    has_secspan = false;
    docObj.find('span:has(span)').each(function(i) {
    var innerobj = $(this).find('> span');
    if (innerobj.size() > 1) {
    $(this).find('span').each(function() {
    if ($.trim($(this).text()) == "") {
    $(this).replaceWith($(this).html());
    }
    }
    )
    return;
    else if (innerobj.size() == 0) {
    return;
    }
    if ($.trim($(this).text()) == $.trim(innerobj.text())) {
    has_secspan = true;
    var style = $(this).attr('style');
    var innserstyle = innerobj.attr('style');
    var newStyle = '';
    if (style && style != "") {
    newStyle += ';' + style;
    }
    if (innserstyle && innserstyle != "") {
    newStyle += ';' + innserstyle;
    }
    var new_html = '';
    $(this).find('> *').each(function() {
    if (this.tagName == "SPAN") {
    new_html += $(innerobj).html();
    else {
    new_html += $(this).prop('outerHTML');
    }
    }
    );
    $(this).attr('style', newStyle).html(new_html);
    }
    }
    );
    while (has_secspan);return docObj.html();
    }
    a.addListener("beforepaste"function(b, c, g) {
    b = c.html;
    "function" == typeof strip_stack_span && (b = strip_stack_span(b));
    b = $("" + b + "");
    b.find("img").each(function() {
    var a = ""
    , a = this.src && "" != this.src ? this.src : 
    $(this).attr("data-src");
    $(this).removeAttr("data-src");
    "undefined" == typeof a || "" == a ? $(this).remove() : (a = a.replace(/http:\/\/mmbiz.qpic.cn/g, "http://read.html5.qq.com/image?src=forum&q=5&r=0&imgflag=7&imageUrl=http://mmbiz.qpic.cn"),
    a = a.replace(/https:\/\/mmbiz.qpic.cn/g, "http://read.html5.qq.com/image?src=forum&q=5&r=0&imgflag=7&imageUrl=https://mmbiz.qpic.cn"),
    a = a.replace(/http:\/\/mmbiz.qlogo.cn/g, "http://read.html5.qq.com/image?src=forum&q=5&r=0&imgflag=7&imageUrl=http://mmbiz.qlogo.cn"),
    a = a.replace(/&wxfrom=\d+/g, ""),
    a = a.replace(/wxfrom=\d+/g, ""),
    a = a.replace(/&wx_lazy=\d+/g, ""),
    a = a.replace(/wx_lazy=\d+/g, ""),
    a = a.replace(/&tp=[a-z]+/g, ""),
    a = a.replace(/tp=[a-z]+/g, ""),
    a = a.replace(/\?&/g, "?"),
    $(this).attr("src", a),
    $(this).attr("_src", a))
    }
    );
    c.html = b.html()
    }
    );  
    });

    在展示图片的网页头部加入如下代码:

    <metaname="referrer"content="never">

    页面引入uedit的js

    <script src="/res/plugins/baiduedit/ueditor.all.min.js"></script>

    亲测,可以完美解决

    附js文件:点击下载

    wximg.rar

    [编辑:王振袢 &发表于江苏]
    [我要纠错]

    来源:本文内容搜集或转自各大网络平台,并已注明来源、出处,如果转载侵犯您的版权或非授权发布,请联系小编,我们会及时审核处理。
    声明:江苏教育黄页对文中观点保持中立,对所包含内容的准确性、可靠性或者完整性不提供任何明示或暗示的保证,不对文章观点负责,仅作分享之用,文章版权及插图属于原作者。

    关键词: 文章 写的 封装 替换 html5.qq.com
    有价值
    0
    无价值
    0
    猜您喜欢
    最热文章

    暂不支持手机端,请登录电脑端访问

    正在加载验证码......

    请先完成验证