文章中縮寫的封裝替換url(html5.qq.com)方法已經(jīng)失效,最新的辦法,用PHP模擬瀏覽器請求,轉(zhuǎn)發(fā)img的src請求到一個自己寫的action,然后在action里面獲取圖片流,再將圖片寫到網(wǎng)頁上。原盜鏈的原理:官...
文章中縮寫的封裝替換url(html5.qq.com)方法已經(jīng)失效,最新的辦法,用PHP模擬瀏覽器請求,轉(zhuǎn)發(fā)img的src請求到一個自己寫的action,然后在action里面獲取圖片流,再將圖片寫到網(wǎng)頁上。
原盜鏈的原理:
官方輸出圖片的時候,判斷了來源(Referer),就是從哪個網(wǎng)站訪問這個圖片,如果是你的網(wǎng)站去加載這個圖片,那么Referer就是:你的網(wǎng)站地址;;你網(wǎng)站地址,肯定沒在官方的白名單內(nèi),所以就看不到圖片了。
我們做這個跳板的關(guān)鍵:不發(fā)送Referer,也就是沒有來源。那么官方那邊,就認(rèn)為是從瀏覽器直接訪問的,所以就能加載正常的圖片了。
將以下代碼單獨(dú)引入,或者放在封裝的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() } ); }); |
在展示圖片的網(wǎng)頁頭部加入如下代碼:
<metaname="referrer"content="never">
頁面引入uedit的js
<script src="/res/plugins/baiduedit/ueditor.all.min.js"></script>
親測,可以完美解決
附j(luò)s文件:點擊下載
來源:本文內(nèi)容搜集或轉(zhuǎn)自各大網(wǎng)絡(luò)平臺,并已注明來源、出處,如果轉(zhuǎn)載侵犯您的版權(quán)或非授權(quán)發(fā)布,請聯(lián)系小編,我們會及時審核處理。
聲明:江蘇教育黃頁對文中觀點保持中立,對所包含內(nèi)容的準(zhǔn)確性、可靠性或者完整性不提供任何明示或暗示的保證,不對文章觀點負(fù)責(zé),僅作分享之用,文章版權(quán)及插圖屬于原作者。
Copyright?2013-2024 JSedu114 All Rights Reserved. 江蘇教育信息綜合發(fā)布查詢平臺保留所有權(quán)利
蘇公網(wǎng)安備32010402000125
蘇ICP備14051488號-3技術(shù)支持:南京博盛藍(lán)睿網(wǎng)絡(luò)科技有限公司
南京思必達(dá)教育科技有限公司版權(quán)所有 百度統(tǒng)計