Skip to content

Commit

Permalink
http接口增加cookie参数
Browse files Browse the repository at this point in the history
  • Loading branch information
chenxuuu committed Feb 14, 2019
1 parent 7522f84 commit 28a1b6d
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,23 +26,16 @@ public static string Lottery(string qq, IMahuaApi _mahuaApi,string group)
Random ran = new Random(System.DateTime.Now.Millisecond);
int RandKey = ran.Next(1, 22);
int RandKey2 = ran.Next(0, 10);
if (RandKey > 19)
if (RandKey > 21)
{
result += Tools.At(qq) + "\r\n[CQ:emoji,id=127881]恭喜你!什么也没有抽中!";
}
else if (RandKey == 1 && RandKey2 != 0)
{
if (Tools.GetXmlNumber("gift", qq) < 10)
{
need_add += 10;
TimeSpan span = new TimeSpan(0, 10, 0, 0);
_mahuaApi.BanGroupMember(group, qq, span);
result += Tools.At(qq) + "\r\n[CQ:emoji,id=127882]恭喜你抽中了超豪华禁言套餐,并附赠10张禁言卡!奖励已发放!";
}
else
{
result += Tools.At(qq) + "\r\n是超豪华禁言套餐呢。。。这次套餐我请客吧ww";
}
need_add += 10;
TimeSpan span = new TimeSpan(0, 10, 0, 0);
_mahuaApi.BanGroupMember(group, qq, span);
result += Tools.At(qq) + "\r\n[CQ:emoji,id=127882]恭喜你抽中了超豪华禁言套餐,并附赠10张禁言卡!奖励已发放!";
}
else if (RandKey == 1 && RandKey2 == 0)
{
Expand All @@ -58,7 +51,7 @@ public static string Lottery(string qq, IMahuaApi _mahuaApi,string group)
result += Tools.At(qq) + "\r\n是顶级豪华月卡禁言套餐呢。。。这次套餐我请客吧ww";
}
}
else if (RandKey < 11 - Tools.GetXmlNumber("gift", qq) / 10)
else if (RandKey < 11 - Tools.GetXmlNumber("gift", qq) / 5)
{
TimeSpan span = new TimeSpan(0, RandKey, 0, 0);
_mahuaApi.BanGroupMember(group, qq, span);
Expand Down Expand Up @@ -231,7 +224,7 @@ public static string ReceiveGift(string qq)
extra += "\r\n[CQ:emoji,id=127748]每日抽奖次数+1了哦~";
if(gift == 10)
extra += "\r\n[CQ:emoji,id=128157]以后的大禁言套餐都由我请客~";
if (gift % 10 == 0 && gift < 110)
if (gift % 5 == 0 && gift < 110)
extra += "\r\n[CQ:emoji,id=9878]禁言概率降低了哦~";
if (gift % 10 == 0 )
extra += "\r\n[CQ:emoji,id=127881]每次抽中禁言卡数量上限+1~";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -277,28 +277,20 @@ lua 加 代码 直接运行
}
else if (msg.IndexOf("lua") == 0 && msg.Length > 4)
{
result += Tools.At(fromqq) + "\r\n" + Tools.RunLua(HttpUtility.HtmlDecode(msg.Substring(4)),
string.Format("fromqq=\"{0}\"\r\nfromgroup=\"{1}\"\r\n", fromqq, fromgroup));
if (XmlSolve.AdminCheck(fromqq) >= 1)//管理员才能用
{
result += Tools.At(fromqq) + "\r\n" + Tools.RunLua(HttpUtility.HtmlDecode(msg.Substring(4)),
string.Format("fromqq=\"{0}\"\r\nfromgroup=\"{1}\"\r\n", fromqq, fromgroup));
}
else
{
result += prem;
}
}
else if (fromgroup == "241464054") //糖拌群
result += MinecraftSolve.SolvePlayer(fromqq, msg, _mahuaApi);
else if (fromgroup == "567145439") //分赃群
result += MinecraftSolve.SolveAdmin(fromqq, msg, _mahuaApi);
else if (fromgroup == "543632048") //基岩版
{
if (msg.IndexOf("领铁轨") == 0)
{
if (msg.Length <= 3)
return Tools.At(fromqq) + "请用格式“领铁轨”加上id,领取铁轨";
else
{
Tools.HttpGet("http://localhost:2333/give " + msg.Replace("领铁轨", "") + " rail 64", "");
Tools.HttpGet("http://localhost:2333/give " + msg.Replace("领铁轨", "") + " golden_rail 64", "");
Tools.HttpGet("http://localhost:2333/give " + msg.Replace("领铁轨", "") + " redstone_torch 10", "");
return Tools.At(fromqq) + "已发放,请查收";
}
}
}
if(result == "")
result += XmlSolve.ReplayGroupStatic(fromgroup, msg, fromqq);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,8 @@ public static string execCMD(string command)
/// <summary>
/// GET 请求与获取结果
/// </summary>
public static string HttpGet(string Url, string postDataStr = "", int timeout = 5000)
public static string HttpGet(string Url, string postDataStr = "", int timeout = 5000,
string cookie = "")
{
try
{
Expand All @@ -281,6 +282,8 @@ public static string HttpGet(string Url, string postDataStr = "", int timeout =
request.ContentType = "text/html;charset=UTF-8";
request.Timeout = timeout;
request.UserAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.98 Safari/537.36 Vivaldi/2.2.1388.37";
if(cookie!="")
request.Headers.Add("cookie", cookie);

HttpWebResponse response = (HttpWebResponse)request.GetResponse();
string encoding = response.ContentEncoding;
Expand All @@ -304,7 +307,8 @@ public static string HttpGet(string Url, string postDataStr = "", int timeout =
/// <summary>
/// POST请求与获取结果
/// </summary>
public static string HttpPost(string Url, string postDataStr, int timeout = 5000)
public static string HttpPost(string Url, string postDataStr, int timeout = 5000,
string cookie = "")
{
try
{
Expand All @@ -325,6 +329,8 @@ public static string HttpPost(string Url, string postDataStr, int timeout = 5000
request.ContentType = "application/x-www-form-urlencoded; charset=UTF-8";
request.ContentLength = postDataStr.Length;
request.UserAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.98 Safari/537.36 Vivaldi/2.2.1388.37";
if (cookie != "")
request.Headers.Add("cookie", cookie);

StreamWriter writer = new StreamWriter(request.GetRequestStream(), Encoding.ASCII);
writer.Write(postDataStr);
Expand Down
6 changes: 4 additions & 2 deletions Newbe.Mahua.Receiver.Meow/head.lua
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,19 @@ function at(qq)
end

--httpGet获取
function httpGet(url,para,timeout)
function httpGet(url,para,timeout,cookie)
if not para then para = "" end
if not timeout then timeout = 5000 end
if not cookie then cookie = "" end
local result = httpGet_row(url,para,timeout)
if result ~= "" then return result end
end

--httpPost获取
function httpPost(url,para,timeout)
function httpPost(url,para,timeout,cookie)
if not para then para = "" end
if not timeout then timeout = 5000 end
if not cookie then cookie = "" end
local result = httpPost_row(url,para,timeout)
if result ~= "" then return result end
end
Expand Down
2 changes: 2 additions & 0 deletions lua.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,12 +89,14 @@ print(at("123456"))
- `url`网址,string
- `para`参数,string,默认空,可留空
- `timeout`网址,number,默认5000,可留空
- `cookie`cookie,string,默认空,可留空

举例:

```lua
print(httpGet("https://www.baidu.com"):sub(1,300))
httpGet("https://www.abc.com","aa=123&bb=233&c="..string.urlEncode("中文参数"))
httpGet("https://qq.com","aa=123&bb=233&c=",5000,"uid=xxxxx;aaa=vvvvv")
```

### httpPost(url,para,timeout) 发起一个http post请求
Expand Down

0 comments on commit 28a1b6d

Please sign in to comment.