1、将libeay32.dll、ssleay32.dll拷贝至exe目录下。
2、uses IdIOHandler, IdIOHandlerSocket, IdSSLOpenSSL,
IdBaseComponent, IdComponent, IdRawBase, IdRawClient, IdIcmpClient,
IdTCPClient, IdHTTP;
3、编写函数fucHttpAlipay。
//---------------------------------------------------------------
//支付宝请求
//add by jzh 2014-06-06
//---------------------------------------------------------------
function fucHttpAlipay(sUrl: String; slPara: TStrings): String;
var
idhttpApp: TIdHTTP;
idssl: TIdSSLIOHandlerSocket;
sValue: String;
begin
idhttpApp:= TIdHTTP.Create(nil);
idhttpApp.HandleRedirects:= True;
idhttpApp.AllowCookies:= True;
idhttpApp.HTTPOptions:= [hoForceEncodeParams];
idhttpApp.ProtocolVersion:= pv1_1;
idhttpApp.Request.ContentType:= 'application/x-www-form-urlencoded';
idhttpApp.ConnectTimeout:= 6000;
idhttpApp.ReadTimeout:= 12000;
idssl:= TIdSSLIOHandlerSocket.Create(nil);
idssl.SSLOptions.Method:= sslvSSLv3;
idhttpApp.IOHandler:= idssl;
try
sValue:= idhttpApp.Post(sUrl, slPara);
//sValue:= StringReplace(sValue, #$D#$A, '', [rfReplaceAll, rfIgnoreCase]); //rfIgnoreCase忽略大小写
sValue:= StringReplace(sValue, #$A, '', [rfReplaceAll, rfIgnoreCase]); //rfIgnoreCase忽略大小写
idhttpApp.Free;
idssl.Free;
Result:= sValue;
except
begin
idhttpApp.Free;
idssl.Free;
Result:= '-1';
end;
end;
end;