ISAPI模式下的JOSN获取异常,Standalone下又是正常的

daigua1987 2023-07-27 16:22:18

这是调用代码

procedure TMainForm.UniFormShow(Sender: TObject);
var
  PathInfo, access_token: string;
  GetJSON: TGetJSON;
  RequestJSON, RequestJSONS: TJSONObject;
begin
  PathInfo := UniApplication.Parameters.Values['authCode'];
  if PathInfo = '' then
  begin
    UniSession.AddJS('window.location.href = "https://login.dingtalk.com/oauth2/challenge.htm?redirect_uri=http://175.16.27.83:8023&response_type=code&client_id=ding0&scope=openid&state=dddd&prompt=consent";');
    exit;
  end;
  RequestJSON := TJSONObject.Create;
  RequestJSONS := TJSONObject.Create;
  RequestJSON:=GetJSON.GetUsertoken(PathInfo);
  try
    access_token:=RequestJSON.GetValue('accessToken').Value;
  except
    UniSession.AddJS('window.location.href = "https://login.dingtalk.com/oauth2/challenge.htm?redirect_uri=http://175.16.27.83:8023&response_type=code&client_id=ding0&scope=openid&state=dddd&prompt=consent";');
    exit;
  end;
  RequestJSONS:=GetJSON.GetLoginUser(access_token);
  if RequestJSONS.GetValue('avatarUrl').Value<>'' then
  begin
   UniImage3.Url:=RequestJSONS.GetValue('avatarUrl').Value;
  end;
  UniLabel1.Caption:=RequestJSONS.GetValue('nick').Value;
  UniMenuItemAdd();
end;

这是实现代码

function TGetJSON.GetUsertoken(Auto_Code: String):TJSONObject;
var
  RequestJSON, ResponseJSON: TJSONObject;
  ResponseText, vurl, JsonString: string;
  js: TStringStream;
begin
  RequestJSON := TJSONObject.Create;
  ResponseJSON := TJSONObject.Create;
  vurl := 'https://api.dingtalk.com/v1.0/oauth2/userAccessToken';
  try
    // 构建要发送的 JSON 数据
    RequestJSON.AddPair(TJSONPair.Create('clientId', 'dingh'));
    RequestJSON.AddPair(TJSONPair.Create('clientSecret', 'xHdgoZxqVWSp'));
    RequestJSON.AddPair(TJSONPair.Create('code', Auto_Code));
    RequestJSON.AddPair(TJSONPair.Create('refreshToken', Auto_Code));
    RequestJSON.AddPair(TJSONPair.Create('grantType', 'authorization_code'));
    JsonString := RequestJSON.ToString;

    js := TStringStream.Create(JsonString);

    // 设置请求的 Content-Type 为 application/json
    MainForm.IdHTTP1.Request.ContentType := 'application/json';

    // 发送 POST 请求,并获取响应
    ResponseText := MainForm.IdHTTP1.Post(vurl, js);

    // 解析返回的 JSON 数据
    ResponseJSON := TJSONObject.ParseJSONValue(ResponseText) as TJSONObject;

    Result := ResponseJSON;
  except
    Result := nil;
  end;
end;

经过测试在一个获取JSON数据的时候报错,在RequestJSON.GetValue('accessToken').Value;获取信息的时候提示异常。在ISAPI里面需要调整那些地方

...全文
168 9 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
CSDN-Ada助手 2023-07-27
精选
  • 打赏
  • 举报
回复
您的问题已经帮您同步至问答, 链接: https://ask.csdn.net/questions/7982781, 请您保持关注, 如果回答有帮助解决此问题, 麻烦您动动小手给相关的回答点赞, Ada会在评论区为您更新结题状态
tanqth 2023-07-28
  • 打赏
  • 举报
回复

你这个,调试一下,先看看PathInfo有没有取正确。

daigua1987 2023-07-28
  • 举报
回复
@tanqth PathInfo的值是正确的,两种模式值都正确,就是POST接口 获取值 每获取到 ,哎 ISAPI模式用不了 我暂时用Standalone模式挂在哪里
daigua1987 2023-07-28
  • 举报
回复
@tanqth PathInfo的值是URL地址里面传过去的
daigua1987 2023-07-28
  • 举报
回复
@tanqth POST接口访问的时候 提示Could not load SSL library
4条回复

5,929

社区成员

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

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