Delphi 获取Java写的token接口

落幕年代 2019-01-08 02:45:26
Delphi 如何获取 Java写的token接口
...全文
863 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
落幕年代 2019-01-12
  • 打赏
  • 举报
回复
引用 2 楼 qq_15381437 的回复:
end;
如何获取每次token刷新的head头信息
minizhuxianchun 2019-01-09
  • 打赏
  • 举报
回复
procedure WxSendListThread(P: Pointer); ////13632345145 李 //13828890584 张(国爵电子) //www.38it.com qq:80012683

function GetAccessToken(http: TIdHTTP; var token: string; var jgTime: DWORD): Boolean;
var
i,index: integer;
RetStr,access_token,expires_in: string;
begin
Result:=False;
RetStr:=http.Get('https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid=wxc2f5f2ccb6eec512&corpsecret=069ErVSyom2Yp375azN4grsOfFMAiRM_sGXWP3-qCv6-3q0K96zJwfNfo_iTgZQZ');
RetStr := UTF8Decode(RetStr);
access_token:='';
index:=Pos('access_token',RetStr);
if index>0 then
begin
index:=index+Length('access_token')+3;
for i:=index to Length(RetStr) do
if RetStr[i]<>'"' then
access_token:=access_token+RetStr[i]
else
begin
token:=access_token;
Break;
end;
if access_token<>'' then
begin
expires_in:='';
index:=Pos('expires_in',RetStr);
if index>0 then
begin
index:=index+Length('expires_in')+2;
for i:=index to Length(RetStr) do
if RetStr[i] in['0'..'9'] then
expires_in:=expires_in+RetStr[i]
else
begin
if expires_in<>'' then
begin
jgTime:=StrToInt(expires_in);
Result:=True;
end;
Break;
end;
end;
end;
end;
end;

var
LastGetTokenTick: Cardinal;
token: string;
ASource: string;
jgTime: DWORD;
sndStrings: TStringList;
http: TIdHTTP;
IdSSLIOHandlerSocket: TIdSSLIOHandlerSocket;
lpNotifyWxNode: PNotifyWxNode;
begin
EnterCriticalSection(BaseSection);
Inc(ThreadCount,1);
LeaveCriticalSection(BaseSection);

sndStrings:=TStringList.Create;
http:=TIdHTTP.Create(nil);
IdSSLIOHandlerSocket:=TIdSSLIOHandlerSocket.Create(nil);
try
http.IOHandler:=IdSSLIOHandlerSocket;
http.HandleRedirects:=True;
http.ReadTimeout:=5000;
http.Request.ContentType:='application/json';
IdSSLIOHandlerSocket.SSLOptions.Method:=sslvSSLv23;
IdSSLIOHandlerSocket.SSLOptions.Mode:=sslmClient;

if not GetAccessToken(http,token,jgTime) then
begin
token:='';
jgTime:=0;
end;
LastGetTokenTick:=GetTickCount;

while not isThreadExit do
begin
lpNotifyWxNode:=nil;
try
EnterCriticalSection(NotifyWxListSection);
try
if NotifyWxList.Count>0 then
begin
lpNotifyWxNode:=NotifyWxList.Items[0];
NotifyWxList.Delete(0);
end;
finally
LeaveCriticalSection(NotifyWxListSection);
end;
if lpNotifyWxNode=nil then
Sleep(1000)
else
begin
if (token='')or(GetMilSecond(LastGetTokenTick,GetTickCount)>(jgTime*1000)) then
begin
if not GetAccessToken(http,token,jgTime) then
begin
token:='';
jgTime:=0;
end;
LastGetTokenTick:=GetTickCount;
end;

ASource:='{"touser": "","toparty": "'+lpNotifyWxNode^.AryDeptID+'","totag": "",';
ASource:=ASource+'"msgtype": "text","agentid": 1,"text": {"content": "'+UTF8Encode(lpNotifyWxNode^.Content)+'"},"safe":0}';
sndStrings.Clear;
sndStrings.Add(ASource);
Dispose(lpNotifyWxNode);
if token<>'' then
http.Post('https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token='+token,sndStrings);
end;
except

end;
end;
finally
http.Free;
IdSSLIOHandlerSocket.Free;
sndStrings.Free;

EnterCriticalSection(BaseSection);
Dec(ThreadCount,1);
LeaveCriticalSection(BaseSection);
EndThread(0);
end;
end;
清风7325 2019-01-09
  • 打赏
  • 举报
回复
function GetTokenData(CliendId, Authcode: string): string;
var
url: string;
Resstream: tstringstream;
Resstring: string;
aJson: ISuperObject;
begin
try
Resstream := tstringstream.Create('');
idhttp1.ReadTimeout := 30000;
idhttp1.Request.ContentType := 'application/json'; //'text/xml';
idhttp1.HandleRedirects := true;
idhttp1.Request.Accept := 'text/javascript';
idhttp1.Request.CharSet := 'utf-8';
idhttp1.Request.ContentEncoding := 'utf-8';
url := 'https://172.16.1.12:8443/rlsb/outer/invokeToken?clientid=' + CliendId + '&authcode=' + Authcode;
try
idhttp1.Get(url, Resstream);
Resstring := Resstream.DataString;
Resstring := UTF8Decode(Resstring);
aJson := SO(Resstring);
result := aJson['access_token'].AsString;
except
end;
finally
freeandnil(Resstream);
idhttp1.Disconnect;
end;
end;
  • 打赏
  • 举报
回复
用Delphi自带的java2op工具转换一下就可以了

5,402

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 开发及应用
社区管理员
  • VCL组件开发及应用社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧