Skip to content
This repository has been archived by the owner on Nov 8, 2023. It is now read-only.

Commit

Permalink
Merge pull request #81 from jianjianai/dev
Browse files Browse the repository at this point in the history
修改UA为Edge浏览器
  • Loading branch information
jianjianai authored May 29, 2023
2 parents fbf68d6 + 1fd4eae commit e32a6be
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 30 deletions.
25 changes: 15 additions & 10 deletions cloudflareWorker.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ async function handleRequest(request) {

if (path === '/sydney/ChatHub') { //魔法聊天
let h = {
"sec-fetch-site": "same-origin",
"referer": "https://www.bing.com/search?q=bingAI"
"Host":"sydney.bing.com",
"Origin":"https://www.bing.com"
}
let randomAddress = url.searchParams.get("randomAddress");
if(randomAddress){
Expand All @@ -88,36 +88,39 @@ async function handleRequest(request) {
return goUrl(request,"https://sydney.bing.com/sydney/ChatHub",h);
}
if (path === "/turing/conversation/create") { //创建聊天
return goUrl(request, "https://www.bing.com/turing/conversation/create");
return goUrl(request, "https://www.bing.com/turing/conversation/create",{
"referer":"https://www.bing.com/search?q=Bing+AI"
});
}

if(path==="/edgesvc/turing/captcha/create"){//请求验证码图片
return goUrl(request,"https://edgeservices.bing.com/edgesvc/turing/captcha/create");
return goUrl(request,"https://edgeservices.bing.com/edgesvc/turing/captcha/create",{
"referer":"https://edgeservices.bing.com/edgesvc/chat?udsframed=1&form=SHORUN&clientscopes=chat,noheader,channelstable,&shellsig=709707142d65bbf48ac1671757ee0fd1996e2943&setlang=zh-CN&lightschemeovr=1"
});
}
if(path==="/edgesvc/turing/captcha/verify"){//提交验证码
return goUrl(request,"https://edgeservices.bing.com/edgesvc/turing/captcha/verify?"+ url.search);
return goUrl(request,"https://edgeservices.bing.com/edgesvc/turing/captcha/verify?"+ url.search,{
"referer":"https://edgeservices.bing.com/edgesvc/chat?udsframed=1&form=SHORUN&clientscopes=chat,noheader,channelstable,&shellsig=709707142d65bbf48ac1671757ee0fd1996e2943&setlang=zh-CN&lightschemeovr=1"
});
}

if (path.startsWith('/msrewards/api/v1/enroll')) { //加入候补
return goUrl(request, "https://www.bing.com/msrewards/api/v1/enroll" + url.search);
}
if (path === '/images/create') { //AI画图
return goUrl(request, "https://www.bing.com/images/create" + url.search, {
"sec-fetch-site": "same-origin",
"referer": "https://www.bing.com/search?q=bingAI"
});
}
if (path.startsWith('/images/create/async/results')) { //请求AI画图图片
url.hostname = "www.bing.com";
return goUrl(request, url.toString(), {
"sec-fetch-site": "same-origin",
"referer": "https://www.bing.com/images/create?partner=sydney&showselective=1&sude=1&kseed=7000"
});
}
if (path.startsWith('/rp')) { //显示AI画图错误提示图片
url.hostname = "www.bing.com";
return goUrl(request, url.toString(), {
"sec-fetch-site": "same-origin",
"referer": "https://www.bing.com/search?q=bingAI"
});
}
Expand Down Expand Up @@ -190,13 +193,15 @@ async function goUrl(request, url, addHeaders) {
}
//保留头部信息
let reqHeaders = request.headers;
let dropHeaders = ["user-agent", "accept", "accept-language","Connection","Upgrade"];
let dropHeaders = ["accept", "accept-language","accept-encoding","Connection","Upgrade"];
for (let h of dropHeaders) {
if (reqHeaders.has(h)) {
fp.headers[h] = reqHeaders.get(h);
}
}

fp.headers["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.57"

//客户端指定的随机地址
let randomAddress = reqHeaders.get("randomAddress");
if(!randomAddress){
Expand Down Expand Up @@ -235,7 +240,7 @@ async function goUrl(request, url, addHeaders) {

let res = await fetch(url, fp);
let newRes = new Response(res.body,res);
newRes.headers.set("cookieID",cookieID);
newRes.headers.set("cookieID",`${cookieID}`);
return newRes;
}

Expand Down
46 changes: 26 additions & 20 deletions src/main/java/cn/jja8/newbinggogo/NewBingGoGoServer.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,26 +57,31 @@ public Response serveHttp(IHTTPSession session) {
}
if(url.equals("/turing/conversation/create")){//创建聊天
System.out.println(ip+":请求创建聊天");
return goUrl(session,"https://www.bing.com/turing/conversation/create");
return goUrl(session,"https://www.bing.com/turing/conversation/create",Map.of(
"referer","https://www.bing.com/search?q=Bing+AI"
));
}
if(url.equals("/edgesvc/turing/captcha/create")){//请求验证码图片
System.out.println(ip+":请求验证码图片");
return goUrl(session,"https://edgeservices.bing.com/edgesvc/turing/captcha/create");
return goUrl(session,"https://edgeservices.bing.com/edgesvc/turing/captcha/create",Map.of(
"referer","https://edgeservices.bing.com/edgesvc/chat?udsframed=1&form=SHORUN&clientscopes=chat,noheader,channelstable,&shellsig=709707142d65bbf48ac1671757ee0fd1996e2943&setlang=zh-CN&lightschemeovr=1"
));
}
if(url.equals("/edgesvc/turing/captcha/verify")){//提交验证码
System.out.println(ip+":提交验证码");
return goUrl(session,"https://edgeservices.bing.com/edgesvc/turing/captcha/verify?"+session.getQueryParameterString());
return goUrl(session,"https://edgeservices.bing.com/edgesvc/turing/captcha/verify?"+session.getQueryParameterString(),Map.of(
"referer","https://edgeservices.bing.com/edgesvc/chat?udsframed=1&form=SHORUN&clientscopes=chat,noheader,channelstable,&shellsig=709707142d65bbf48ac1671757ee0fd1996e2943&setlang=zh-CN&lightschemeovr=1"
));
}
if(url.equals("/msrewards/api/v1/enroll")){//加入候补
System.out.println(ip+":请求加入候补");
return goUrl(session,"https://www.bing.com/msrewards/api/v1/enroll?"+session.getQueryParameterString());
}
if(url.equals("/images/create")){
System.out.println(ip+":请求AI画图");
HashMap<String,String> he = new HashMap<>();
he.put("sec-fetch-site","same-origin");
he.put("referer","https://www.bing.com/search?q=bingAI");
Response re = goUrl(session,"https://www.bing.com/images/create?"+session.getQueryParameterString(),he);
Response re = goUrl(session,"https://www.bing.com/images/create?"+session.getQueryParameterString(),Map.of(
"referer","https://www.bing.com/search?q=bingAI"
));
re.setMimeType("text/html");
return re;
}
Expand All @@ -85,20 +90,18 @@ public Response serveHttp(IHTTPSession session) {
String gogoUrl = url.replace("/images/create/async/results","https://www.bing.com/images/create/async/results");
gogoUrl = gogoUrl+"?"+session.getQueryParameterString();
// /641f0e9c318346378e94e495ab61a703?q=a+dog&partner=sydney&showselective=1
HashMap<String,String> he = new HashMap<>();
he.put("sec-fetch-site","same-origin");
he.put("referer","https://www.bing.com/images/create?partner=sydney&showselective=1&sude=1&kseed=7000");
return goUrl(session, gogoUrl,he);
return goUrl(session, gogoUrl,Map.of(
"referer","https://www.bing.com/images/create?partner=sydney&showselective=1&sude=1&kseed=7000"
));
}

if(url.startsWith("/rp")){
System.out.println(ip+":请求AI画图错误图片");
String gogoUrl = url.replace("/rp","https://www.bing.com/rp");
gogoUrl = gogoUrl+"?"+session.getQueryParameterString();
HashMap<String,String> he = new HashMap<>();
he.put("sec-fetch-site","same-origin");
he.put("referer","https://www.bing.com/search?q=bingAI");
return goUrl(session, gogoUrl,he);
return goUrl(session, gogoUrl,Map.of(
"referer","https://www.bing.com/search?q=bingAI"
));
}

//用于测试
Expand Down Expand Up @@ -129,15 +132,15 @@ protected WebSocket openWebSocket(IHTTPSession handshake) {
if(url.equals("/sydney/ChatHub")){
System.out.println(ip+":创建魔法聊天连接");
Map<String,String> httpHeaders = new HashMap<>();
String[] b = {"user-agent","accept","accept-language"};//保留请求头
String[] b = {"Accept-Language","Accept-Encoding"};//保留请求头
Map<String, String> header = handshake.getHeaders();
for (String s : b) {
String v = header.get(s);
String v = header.get(s.toLowerCase());
httpHeaders.put(s,v);
}
httpHeaders.put("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.57");
httpHeaders.put("Host","sydney.bing.com");
httpHeaders.put("Origin","https://www.bing.com");
httpHeaders.put("Cache-Control","no-cache");
List<String> ls = handshake.getParameters().get("randomAddress");
String add = null;
if(ls!=null){
Expand Down Expand Up @@ -211,11 +214,14 @@ public static Response goUrl(IHTTPSession session, String stringUrl, Map<String,

//拷贝头信息
Map<String,String> header = session.getHeaders();
String[] b = {"user-agent","accept","accept-language"};
String[] b = {"accept", "accept-language","accept-encoding"};
for (String s : b) {
String v = header.get(s);
String v = header.get(s.toLowerCase());
urlConnection.addRequestProperty(s,v);
}

urlConnection.addRequestProperty("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.57");

//添加指定的头部信息
addHeaders.forEach(urlConnection::addRequestProperty);

Expand Down

0 comments on commit e32a6be

Please sign in to comment.