SCZTCA.pas 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. unit SCZTCA;
  2. interface
  3. uses
  4. CAImport, Classes, mybean.core.objects, InterfaceCA, superobject, IdHTTP, SysUtils;
  5. type
  6. /// <remarks>
  7. /// 省财政厅CA认证
  8. /// </remarks>
  9. TSTCAClient = class(TMyBeanInterfacedObject, ICAClient)
  10. public
  11. function Request: string; stdcall;
  12. end;
  13. implementation
  14. uses
  15. Forms, Dialogs, CnBase64, StrUtils;
  16. function SplitString(const Source, Ch:string): TStringList;
  17. var
  18. Temp: string;
  19. iLoop: Integer;
  20. begin
  21. Result := TStringList.Create;
  22. Temp := Source;
  23. iLoop := Pos(Ch, Source);
  24. while iLoop <> 0 do
  25. begin
  26. Result.Add(copy(temp, 0, iLoop-1));
  27. Delete(temp, 1, iLoop);
  28. iLoop := Pos(Ch, Temp);
  29. end;
  30. Result.Add(temp);
  31. end;
  32. { TSTCAClient }
  33. function TSTCAClient.Request: string;
  34. const
  35. GETUSER_URL: string = '%s/api/Structure/LoginByCA?ca=%s&account=%s';
  36. var
  37. outStr, account, ca: string;
  38. AItems: TStrings;
  39. AIdHttp: TIdHttp;
  40. AURL: string;
  41. joResult, jo: ISuperObject;
  42. begin
  43. ShowMessage(ParamStr(1));
  44. if ParamStr(1) = '' then
  45. begin
  46. ShowMessage('请通过正常的ca登录途径进行登录');
  47. Exit;
  48. end;
  49. if Base64Decode(ReplaceStr(ParamStr(1), 'wscc://sso ', ''), outStr) <> BASE64_OK then
  50. Exit;
  51. ShowMessage(outStr);
  52. AItems := SplitString(outStr, '&');
  53. if AItems.Count <> 2 then
  54. Exit;
  55. account := ReplaceStr(AItems[0], 'account=', '');
  56. ca := ReplaceStr(AItems[1], 'ca=', '');
  57. AIdHttp := TIdHttp.Create(Application);
  58. try
  59. AURL := Format(GETUSER_URL, [Utf8ToAnsi(GetCAConfig.GetURL), ca, account]);
  60. Result := Utf8ToAnsi(AIdHttp.Get(AURL));
  61. jo := SO(Result);
  62. if (jo = nil) or (not jo.B['success']) or
  63. (jo.O['data'] = nil) or (jo.O['data'].S['loginName'] = '') or
  64. (jo.O['data'].S['password'] = '')then
  65. Exit;
  66. joResult := SO();
  67. joResult.S['loginName'] := jo.O['data'].S['loginName'];
  68. joResult.S['password'] := jo.O['data'].S['password'];
  69. Result := joResult.AsString;
  70. finally
  71. FreeAndNil(AIdHttp);
  72. end;
  73. end;
  74. end.