| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091 |
- unit SCZTCA;
- interface
- uses
- CAImport, Classes, mybean.core.objects, InterfaceCA, superobject, IdHTTP, SysUtils;
- type
- /// <remarks>
- /// 省财政厅CA认证
- /// </remarks>
- TSTCAClient = class(TMyBeanInterfacedObject, ICAClient)
- public
- function Request: string; stdcall;
- end;
- implementation
- uses
- Forms, Dialogs, CnBase64, StrUtils;
- function SplitString(const Source, Ch:string): TStringList;
- var
- Temp: string;
- iLoop: Integer;
- begin
- Result := TStringList.Create;
- Temp := Source;
- iLoop := Pos(Ch, Source);
- while iLoop <> 0 do
- begin
- Result.Add(copy(temp, 0, iLoop-1));
- Delete(temp, 1, iLoop);
- iLoop := Pos(Ch, Temp);
- end;
- Result.Add(temp);
- end;
- { TSTCAClient }
- function TSTCAClient.Request: string;
- const
- GETUSER_URL: string = '%s/api/Structure/LoginByCA?ca=%s&account=%s';
- var
- outStr, account, ca: string;
- AItems: TStrings;
- AIdHttp: TIdHttp;
- AURL: string;
- joResult, jo: ISuperObject;
- begin
- ShowMessage(ParamStr(1));
- if ParamStr(1) = '' then
- begin
- ShowMessage('请通过正常的ca登录途径进行登录');
- Exit;
- end;
-
- if Base64Decode(ReplaceStr(ParamStr(1), 'wscc://sso ', ''), outStr) <> BASE64_OK then
- Exit;
- ShowMessage(outStr);
- AItems := SplitString(outStr, '&');
- if AItems.Count <> 2 then
- Exit;
- account := ReplaceStr(AItems[0], 'account=', '');
- ca := ReplaceStr(AItems[1], 'ca=', '');
- AIdHttp := TIdHttp.Create(Application);
- try
- AURL := Format(GETUSER_URL, [Utf8ToAnsi(GetCAConfig.GetURL), ca, account]);
- Result := Utf8ToAnsi(AIdHttp.Get(AURL));
- jo := SO(Result);
- if (jo = nil) or (not jo.B['success']) or
- (jo.O['data'] = nil) or (jo.O['data'].S['loginName'] = '') or
- (jo.O['data'].S['password'] = '')then
- Exit;
- joResult := SO();
- joResult.S['loginName'] := jo.O['data'].S['loginName'];
- joResult.S['password'] := jo.O['data'].S['password'];
- Result := joResult.AsString;
- finally
- FreeAndNil(AIdHttp);
- end;
- end;
- end.
|