//抓取服务器 的TIdHTTPServer初始化和侦听函;
procedure TMainForm.SetServerHostAndPort;
var
Binding : TIdSocketHandle;
begin
idhtpsrvr1.Bindings.Clear;
//1.绑定IP地址和端口
idhtpsrvr1.DefaultPort := 80; //若有固定绑定端口参数,一定要写这个
Binding := idhtpsrvr1.Bindings.Add;
Binding.IP := sIP; //本服务的IP
Binding.Port := sPort; //本服务的端口
end;
//guoqiang.xu 开启http监听
try
SetServerHostAndPort;
idhtpsrvr1.Active := True;
if idhtpsrvr1.Active then
LogInfo('监听服务器启动成功!', true)
else
LogInfo('监听服务器启动失败!', true);
except on E : Exception do
begin
LogInfo('监听服务器启动失败!'+ E.Message, true);
end;
end;
//
LogInfo('初始化成功', True);
初始化
procedure TMainForm.idhtpsrvr1CommandGet(AContext: TIdContext;
ARequestInfo: TIdHTTPRequestInfo; AResponseInfo: TIdHTTPResponseInfo);
var
sReqContext : string;
begin
try
//Post方式获取请求内容
if ARequestInfo.Command = 'POST' then
begin
//获取请求串
sReqContext := ARequestInfo.FormParams;
// 请求串为空,退出
if Trim(sReqContext) = '' then
Exit;
//解析请求串
//ParseRequest(sReqContext);
//处理请求
//GetReply(sReqContext);
end
else
begin
//获取请求串
sReqContext := ARequestInfo.QueryParams;
// 请求串为空,退出
if Trim(sReqContext) = '' then Exit;
//处理请求
GetReply(sReqContext);
Exit;
end;
except on E: Exception do
begin
LogInfo('【TOMis客户端手动请求获取竞彩对阵异常!】,异常原因:' + e.Message, True);
Exit;
end;
end;
end;
侦听函数
function TMainForm.GetReply(ARequest: string): Integer;
var
WholeParams: TStringList;
Msg_UserName, Msg_Code, Msg_Sign : string;
sReqStr,sTemp : string;
begin
Result := 0;
WholeParams := TStringList.Create;
try
Pub_GetMatch.Enter;
try
Msg_UserName := 'ReqUser';
Msg_Code := 'ReqCode';
Msg_Sign := 'aSign';
WholeParams.Delimiter := '&';
WholeParams.DelimitedText := ARequest;
sReqUserName := Trim(WholeParams.Values[Msg_UserName]);
sReqCode := Trim(WholeParams.Values[Msg_Code]);
sReqSign := Trim(WholeParams.Values[Msg_Sign]);
//
sReqStr := Trim(sReqUserName) + Trim(sReqCode) + 'aicai123456!'; // 公共密钥
sTemp := MD5String2(sReqStr);
if sTemp = sReqSign then
begin
case StrToInt(sReqCode) of
//竞足对阵(停赛对阵) 竞篮对阵
7,4 :
begin
try
Hand_JCMatchThd := TJCMatchThd.Create(StrToInt(sReqCode),0);
finally
end;
end;
//竞足竞篮赛果
70,45 :
begin
begin
try
Hand_JCResultThd := TJCResultThd.Create(StrToInt(sReqCode),0);
finally
end;
end;
end;
//北单对阵
3 :
begin
try
Hand_BDMatchThd := TBDMatchThd.Create(3,0);
finally
end;
end;
//北单赛果 300 为获取全部
30,31,32,33,34,300 :
begin
try
Hand_BDResultThd := TBDResultThd.create(DoNavigator,DoParse,StrToInt(sReqCode),0);
finally
end;
end;
//北单胜负对阵
35 :
begin
try
Hand_BDSFMatchThd := TBDSFMatchThd.Create(35,0);
finally
end;
end;
//北单胜负赛果
350 :
begin
try
Hand_BDSFResultThd := TBDSFResultThd.Create(350,0);
finally
end;
end;
else
Exit;
end;
end
else
begin
LogInfo('【手动请求获取竞彩对阵或赛果,校验签名不一样,终止请求!】' + sReqSign, True);
Exit;
end;
except on Ex: Exception do
begin
LogInfo('【手动请求获取竞彩对阵或赛果,请求参数异常!】,异常原因:' + Ex.Message, True);
Exit;
end;
end;
finally
WholeParams.Free;
Pub_GetMatch.Leave;
end;
end;
处理侦听
procedure TFrm010515.btnGetBDSFMatchClick(Sender: TObject);
var
ReqUrl, sReqSign, sReqKey : string;
Param : TStringList;
RStream : TStringStream;
sMsg : string;
idhtp1: TIdHTTP;
begin
Param:=TStringList.Create;
RStream:=TStringStream.Create('');
idhtp1 := TIdHTTP.Create(nil);
try
try
sReqCode := '35'; //2014-09-25 liping.chen 暂时定义为35 待抓取服务器相应修改
sMsg := '【北单胜负对阵】';
//生成签名
sReqSign := MD5String2(Pub_UserAccount + sReqCode + PubReqKey);
// http://127.0.0.1:2234/ReqUser=Pub_UserAccount#ReqCode=type#asign=sReqSign/
// ReqUrl := 'http://' + Pub_ReqHost + ':' + IntToStr(Pub_Port) + '/' + 'ReqUser=' + Pub_UserAccount + '&ReqCode=' + sReqCode + '&aSign=' + sReqSign ;
//sRes := idhtp1.Get(ReqUrl);
//ReqUrl := 'HTTP://' + Pub_ReqHost + ':' + IntToStr(Pub_Port) + '/?' ;
ReqUrl := 'HTTP://' + Pub_ReqHost + ':' + IntToStr(Pub_Port) + '/getMatch?' ;
Param.Add('ReqUser=' + Pub_UserAccount);
Param.Add('ReqCode=' + sReqCode);
Param.Add('aSign=' + sReqSign);
//idhtp1.Post(Trim(ReqUrl), Param, RStream);
ReqUrl := ReqUrl + 'ReqUser=' + Pub_UserAccount + '&' + 'ReqCode=' + sReqCode + '&' + 'aSign=' + sReqSign;
idhtp1.Get(Trim(ReqUrl));
//sMsn := RStream.DataString;
MessageboxCE(sMsg + '抓取指令发送成功,请过几分钟后查看赛程!', mtInformation, btOK);
except on e:Exception do
begin
MessageboxCE(sMsg + '抓取指令发送异常!原因为:' + e.Message + ReqUrl, mtInformation, btOK);
Exit;
end;
end;
finally
Param.Free;
RStream.Free;
idhtp1.Free;
end;
end;
procedure TFrm010515.btnGetBDSFResultClick(Sender: TObject);
var
ReqUrl,sReqSign: string;
sMsg : string;
idhtp1: TIdHTTP;
begin
idhtp1 := TIdHTTP.Create(nil);
try
try
sReqCode := '350'; //2014-09-25 liping.chen 暂时定义为350 待抓取服务器相应修改
sMsg := '【北单胜负赛果】';
//生成签名
sReqSign := MD5String2(Pub_UserAccount + sReqCode + pubReqKey);
ReqUrl := 'HTTP://' + Pub_ReqHost + ':' + IntToStr(Pub_Port) + '/getMatch?' ;
ReqUrl := ReqUrl + 'ReqUser=' + Pub_UserAccount + '&' + 'ReqCode=' + sReqCode + '&' + 'aSign=' + sReqSign;
idhtp1.Get(Trim(ReqUrl));
MessageboxCE(sMsg + '抓取指令发送成功,请过几分钟后查看赛程!', mtInformation, btOK);
except on e:Exception do
begin
MessageboxCE(sMsg + '抓取指令发送异常!原因为:' + e.Message + ReqUrl, mtInformation, btOK);
Exit;
end;
end;
finally
idhtp1.Free;
end;
end;
请求
浙公网安备 33010602011771号