From 33d2db03b72c795ec2d5f7456d584cc145abaa95 Mon Sep 17 00:00:00 2001 From: James Feng Cao Date: Tue, 18 Jul 2023 10:54:53 +0800 Subject: [PATCH] use redirect for bingAI --- en/searchurl/cloudflare/bing.js | 140 ++++++++++++++---- .../cloudflare/node_modules/.mf/cf.json | 1 + en/searchurl/cloudflare/pbing.js | 134 +++++++++++++++++ en/searchurl/cloudflare/redirect.js | 7 +- en/sitemap.xml | 13 -- sitemap.xml | 2 +- zh/_posts/index.xml | 11 +- zh/sitemap.xml | 17 +-- zh/tips/index.html | 14 +- 9 files changed, 272 insertions(+), 67 deletions(-) create mode 100644 en/searchurl/cloudflare/node_modules/.mf/cf.json create mode 100644 en/searchurl/cloudflare/pbing.js diff --git a/en/searchurl/cloudflare/bing.js b/en/searchurl/cloudflare/bing.js index 01a4711..a6132dc 100644 --- a/en/searchurl/cloudflare/bing.js +++ b/en/searchurl/cloudflare/bing.js @@ -1,29 +1,119 @@ +const SYDNEY_ORIGIN = 'https://sydney.bing.com'; +const KEEP_REQ_HEADERS = [ + 'accept', + 'accept-encoding', + 'accept-language', + 'connection', + 'cookie', + 'upgrade', + 'user-agent', + 'sec-websocket-extensions', + 'sec-websocket-key', + 'sec-websocket-version', + 'x-request-id', + 'content-length', + 'content-type', + 'access-control-request-headers', + 'access-control-request-method', +]; +const IP_RANGE = [ + ['3.2.50.0', '3.5.31.255'], //192,000 + ['3.12.0.0', '3.23.255.255'], //786,432 + ['3.30.0.0', '3.33.34.255'], //205,568 + ['3.40.0.0', '3.63.255.255'], //1,572,864 + ['3.80.0.0', '3.95.255.255'], //1,048,576 + ['3.100.0.0', '3.103.255.255'], //262,144 + ['3.116.0.0', '3.119.255.255'], //262,144 + ['3.128.0.0', '3.247.255.255'], //7,864,320 +]; + +/** + * 随机整数 [min,max) + * @param {number} min + * @param {number} max + * @returns + */ +const getRandomInt = (min, max) => Math.floor(Math.random() * (max - min)) + min; + +/** + * ip 转 int + * @param {string} ip + * @returns + */ +const ipToInt = (ip) => { + const ipArr = ip.split('.'); + let result = 0; + result += +ipArr[0] << 24; + result += +ipArr[1] << 16; + result += +ipArr[2] << 8; + result += +ipArr[3]; + return result; +}; + +/** + * int 转 ip + * @param {number} intIP + * @returns + */ +const intToIp = (intIP) => { + return `${(intIP >> 24) & 255}.${(intIP >> 16) & 255}.${(intIP >> 8) & 255}.${intIP & 255}`; +}; + +const getRandomIP = () => { + const randIndex = getRandomInt(0, IP_RANGE.length); + const startIp = IP_RANGE[randIndex][0]; + const endIp = IP_RANGE[randIndex][1]; + const startIPInt = ipToInt(startIp); + const endIPInt = ipToInt(endIp); + const randomInt = getRandomInt(startIPInt, endIPInt); + const randomIP = intToIp(randomInt); + return randomIP; +}; + export default { - async fetch(req, _env) { - let url = req.url; - let iSlash = url.indexOf('/',11); - let nUrl = "https://www.bing.com/"+url.substring(iSlash+1); - return goUrl(req, nUrl); - } -} + /** + * fetch + * @param {Request} request + * @param {*} env + * @param {*} ctx + * @returns + */ + async fetch(request, env, ctx) { + const currentUrl = new URL(request.url); + const targetUrl = new URL(SYDNEY_ORIGIN + currentUrl.pathname + currentUrl.search); -function goUrl(request, url) { - //构建 fetch 参数 - let fp = { - method: request.method, - headers: {} - } - //保留头部信息 - let reqHeaders = new Headers(request.headers); - let dropHeaders = ["cookie","user-agent","accept","accept-language"]; - let he = reqHeaders.entries(); - for (let h of he) { - let key = h[0], - value = h[1]; - if (dropHeaders.includes(key)) { - fp.headers[key] = value; + const newHeaders = new Headers(); + request.headers.forEach((value, key) => { + // console.log(`old : ${key} : ${value}`); + if (KEEP_REQ_HEADERS.includes(key)) { + newHeaders.set(key, value); + } + }); + newHeaders.set('host', targetUrl.host); + newHeaders.set('origin', targetUrl.origin); + newHeaders.set('referer', 'https://www.bing.com/search?q=Bing+AI'); + const randIP = getRandomIP(); + // console.log('randIP : ', randIP); + newHeaders.set('X-Forwarded-For', randIP); + const oldUA = request.headers.get('user-agent'); + const isMobile = oldUA.includes('Mobile') || oldUA.includes('Android'); + if (isMobile) { + newHeaders.set( + 'user-agent', + 'Mozilla/5.0 (iPhone; CPU iPhone OS 15_7 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/15.7 Mobile/15E148 Safari/605.1.15 BingSapphire/1.0.410427012' + ); + } else { + newHeaders.set('user-agent', 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/113.0.0.0 Safari/537.36 Edg/113.0.1774.35'); } - } - return fetch(url, fp); -} + // newHeaders.forEach((value, key) => console.log(`${key} : ${value}`)); + const newReq = new Request(targetUrl, { + method: request.method, + headers: newHeaders, + body: request.body, + }); + // console.log('request url : ', newReq.url); + const res = await fetch(newReq); + return res; + }, +}; diff --git a/en/searchurl/cloudflare/node_modules/.mf/cf.json b/en/searchurl/cloudflare/node_modules/.mf/cf.json new file mode 100644 index 0000000..1d766c1 --- /dev/null +++ b/en/searchurl/cloudflare/node_modules/.mf/cf.json @@ -0,0 +1 @@ +{"clientTcpRtt":172,"longitude":"120.60200","latitude":"31.30930","tlsCipher":"AEAD-AES256-GCM-SHA384","continent":"AS","asn":4134,"clientAcceptEncoding":"br, gzip, deflate","country":"CN","tlsClientAuth":{"certIssuerDNLegacy":"","certIssuerSKI":"","certSubjectDNRFC2253":"","certSubjectDNLegacy":"","certFingerprintSHA256":"","certNotBefore":"","certSKI":"","certSerial":"","certIssuerDN":"","certVerified":"NONE","certNotAfter":"","certSubjectDN":"","certPresented":"0","certRevoked":"0","certIssuerSerial":"","certIssuerDNRFC2253":"","certFingerprintSHA1":""},"tlsExportedAuthenticator":{"clientFinished":"b7f5ebe4898f01fbdbf9b0a444e1edc7956472268f27576d15fe6e048855ae5fe9f514231998caf937773f6a53901960","clientHandshake":"44f40162794883f93892c883c4121ca289621ad38b27615555cc0f471283da68ad39a438b0e956abc6613792f5fb81de","serverHandshake":"d3ec250200a505c5bc98a049d3f63720e3baea922338e6f94d61a28d9dfed9c1078dc8fa74e83f6719938122e6887a85","serverFinished":"710a654a0cfdd69ce712c7464801d1661f5b797ddd3cccf7f78f4abbd34564ebb7e9c00282fe7923875226284bde9b67"},"tlsVersion":"TLSv1.3","city":"Suzhou","timezone":"Asia/Shanghai","colo":"SJC","region":"Jiangsu","requestPriority":"","botManagement":{"corporateProxy":false,"verifiedBot":false,"ja3Hash":"0cce74b0d9b7f8528fb2181588d23793","staticResource":false,"detectionIds":{},"score":2},"clientTrustScore":2,"httpProtocol":"HTTP/1.1","regionCode":"JS","asOrganization":"China Telecom","edgeRequestKeepAliveStatus":1} \ No newline at end of file diff --git a/en/searchurl/cloudflare/pbing.js b/en/searchurl/cloudflare/pbing.js new file mode 100644 index 0000000..cd141ed --- /dev/null +++ b/en/searchurl/cloudflare/pbing.js @@ -0,0 +1,134 @@ +const SYDNEY_ORIGIN = 'https://sydney.bing.com'; +const KEEP_REQ_HEADERS = [ + 'accept', + 'accept-encoding', + 'accept-language', + 'connection', + 'cookie', + 'upgrade', + 'user-agent', + 'sec-websocket-extensions', + 'sec-websocket-key', + 'sec-websocket-version', + 'x-request-id', + 'content-length', + 'content-type', + 'access-control-request-headers', + 'access-control-request-method', +]; +const IP_RANGE = [ + ['3.2.50.0', '3.5.31.255'], //192,000 + ['3.12.0.0', '3.23.255.255'], //786,432 + ['3.30.0.0', '3.33.34.255'], //205,568 + ['3.40.0.0', '3.63.255.255'], //1,572,864 + ['3.80.0.0', '3.95.255.255'], //1,048,576 + ['3.100.0.0', '3.103.255.255'], //262,144 + ['3.116.0.0', '3.119.255.255'], //262,144 + ['3.128.0.0', '3.247.255.255'], //7,864,320 +]; + +/** + * 随机整数 [min,max) + * @param {number} min + * @param {number} max + * @returns + */ +const getRandomInt = (min, max) => Math.floor(Math.random() * (max - min)) + min; + +/** + * ip 转 int + * @param {string} ip + * @returns + */ +const ipToInt = (ip) => { + const ipArr = ip.split('.'); + let result = 0; + result += +ipArr[0] << 24; + result += +ipArr[1] << 16; + result += +ipArr[2] << 8; + result += +ipArr[3]; + return result; +}; + +/** + * int 转 ip + * @param {number} intIP + * @returns + */ +const intToIp = (intIP) => { + return `${(intIP >> 24) & 255}.${(intIP >> 16) & 255}.${(intIP >> 8) & 255}.${intIP & 255}`; +}; + +const getRandomIP = () => { + const randIndex = getRandomInt(0, IP_RANGE.length); + const startIp = IP_RANGE[randIndex][0]; + const endIp = IP_RANGE[randIndex][1]; + const startIPInt = ipToInt(startIp); + const endIPInt = ipToInt(endIp); + const randomInt = getRandomInt(startIPInt, endIPInt); + const randomIP = intToIp(randomInt); + return randomIP; +}; + +async function goUrl(request, url) { + let fp = { + method: request.method + }; + fp.headers = new Headers(request.headers); + for(var i = 2; i < arguments.length-1; i=i+2){ + fp.headers[arguments[i]] = arguments[i+1]; + } + return await fetch(url, fp); +} + +export default { + /** + * fetch + * @param {Request} request + * @param {*} env + * @param {*} ctx + * @returns + */ + async fetch(request, env, ctx) { + const url = request.url; + let iSlash = url.indexOf('/',11); + let nUrl = url.substring(iSlash+1); + if(!nUrl.startsWith(SYDNEY_ORIGIN)) + return await goUrl(request, nUrl); + const targetUrl = new URL(nUrl); + + const newHeaders = new Headers(); + request.headers.forEach((value, key) => { + // console.log(`old : ${key} : ${value}`); + if (KEEP_REQ_HEADERS.includes(key)) { + newHeaders.set(key, value); + } + }); + newHeaders.set('host', targetUrl.host); + newHeaders.set('origin', targetUrl.origin); + newHeaders.set('referer', 'https://www.bing.com/search?q=Bing+AI'); + const randIP = getRandomIP(); + // console.log('randIP : ', randIP); + newHeaders.set('X-Forwarded-For', randIP); + const oldUA = request.headers.get('user-agent'); + const isMobile = oldUA.includes('Mobile') || oldUA.includes('Android'); + if (isMobile) { + newHeaders.set( + 'user-agent', + 'Mozilla/5.0 (iPhone; CPU iPhone OS 15_7 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/15.7 Mobile/15E148 Safari/605.1.15 BingSapphire/1.0.410427012' + ); + } else { + newHeaders.set('user-agent', 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/113.0.0.0 Safari/537.36 Edg/113.0.1774.35'); + } + + // newHeaders.forEach((value, key) => console.log(`${key} : ${value}`)); + const newReq = new Request(targetUrl, { + method: request.method, + headers: newHeaders, + body: request.body, + }); + // console.log('request url : ', newReq.url); + const res = await fetch(newReq); + return res; + }, +}; diff --git a/en/searchurl/cloudflare/redirect.js b/en/searchurl/cloudflare/redirect.js index fc84030..f54c2fe 100644 --- a/en/searchurl/cloudflare/redirect.js +++ b/en/searchurl/cloudflare/redirect.js @@ -9,8 +9,11 @@ export default { async function goUrl(request, url) { let fp = { - method: request.method, - headers: request.headers + method: request.method }; + fp.headers = new Headers(request.headers); + for(var i = 2; i < arguments.length-1; i=i+2){ + fp.headers[arguments[i]] = arguments[i+1]; + } return await fetch(url, fp); } diff --git a/en/sitemap.xml b/en/sitemap.xml index 15189ec..4d67e6f 100644 --- a/en/sitemap.xml +++ b/en/sitemap.xml @@ -56,19 +56,6 @@ hreflang="en" href="/en/tags/" /> - - /en/ - 2023-06-26T08:17:34+08:00 - - /en/links/ 2023-06-17T15:51:12+08:00 diff --git a/sitemap.xml b/sitemap.xml index fbea88a..7e1dcfb 100644 --- a/sitemap.xml +++ b/sitemap.xml @@ -11,7 +11,7 @@ zh/sitemap.xml - 2023-07-05T09:05:41+08:00 + 2023-07-18T10:53:14+08:00 diff --git a/zh/_posts/index.xml b/zh/_posts/index.xml index e07d976..7e5bb86 100644 --- a/zh/_posts/index.xml +++ b/zh/_posts/index.xml @@ -108,9 +108,9 @@ c[cssFlag]: For example, &quot;c12&quot; will apply the third and fourth /zh/tips/ 免魔法国内直接使用系列 -newbing/chatgpt/必应写作/AI画图 使用重定向访问国外技术网址 google翻译 +newbing/chatgpt/必应写作/AI画图 目录配置及使用外部文件管理器 超微浏览器可以将配置目录或子目录符号链接至任意外部公共目录。安装有定制termux的用户也可以使用移动设备自带或第三方文件管理器管理超微内部指定目录。具体配置可见Shell command mode。 准确显示PC网页: @@ -127,7 +127,9 @@ UA为非默认时,点击PC按钮将恢复UA为默认,同时触发不保存UA 在浏览器文件管理器中长按文件名,弹出菜单中选择分享,系统会优先弹出相应的文件编辑器。 配置文件列表中直接点击文件名即可编辑。 免魔法直接使用newbing/chatgpt/必应写作/AI画图 总要求:长按底部&quot;PC&quot;按钮选择user-agent为&quot;edge&quot;。用户需登录微软网站比如cn.bing.com,帐号已经开通newbing。 -方法1: +方法0: +使用重定向访问国外技术网址,使用cloudflare workers 全局重定向代码。请帮助改良维护workers代码。 +方法1(不再维护): 点击一键安装必应AI 或者分步安装: 安装界面html, bingChat &amp; Write自带魔法直接界面 @@ -137,10 +139,7 @@ Click to append to &quot;hosts&quot;, edit the last part as magic url do 点击界面入口 可配置魔法url, 上述hosts文件作相应修改。 详情 方法2: 可以采用超级书签/直接界面+脚本+hosts。 -其中超级书签固定bingchat入口。 -脚本重定向api至魔法师. -hosts防污染。 -bingChat能够正常使用时保存为超级书签 (长按底部右箭头按钮),下次再次需要使用时恢复即可 (按设置按钮然后点击超级书签链接)。 +其中超级书签固定bingchat入口。 diff --git a/zh/sitemap.xml b/zh/sitemap.xml index b1538ca..e81adac 100644 --- a/zh/sitemap.xml +++ b/zh/sitemap.xml @@ -3,7 +3,7 @@ xmlns:xhtml="http://www.w3.org/1999/xhtml"> /zh/_posts/ - 2023-06-17T07:56:09+08:00 + 2023-07-18T10:53:14+08:00 - - /zh/ - 2023-07-05T09:05:41+08:00 - - /zh/tags/%E5%9B%BD%E5%A4%96%E7%BD%91%E5%9D%80/ 2023-06-17T07:56:09+08:00 @@ -74,7 +61,7 @@ /> /zh/tips/ - 2023-06-12T09:57:14+08:00 + 2023-07-18T10:53:14+08:00

免魔法国内直接使用系列
-newbing/chatgpt/必应写作/AI画图
使用重定向访问国外技术网址
-google翻译

+google翻译
+newbing/chatgpt/必应写作/AI画图

目录配置及使用外部文件管理器
超微浏览器可以将配置目录或子目录符号链接至任意外部公共目录。安装有定制termux的用户也可以使用移动设备自带或第三方文件管理器管理超微内部指定目录。具体配置可见Shell command mode

准确显示PC网页:
@@ -69,7 +69,11 @@ UA为非默认时,点击PC按钮将恢复UA为默认,同时触发不保存UA

总要求:长按底部"PC"按钮选择user-agent为"edge"。用户需登录微软网站比如cn.bing.com,帐号已经开通newbing。