首页 > 微信 > 详细

Delphi XE7 用indy开发微信公众平台(1)- 获取access_token、expires_in

时间:2015-02-09 21:38:15      阅读:774      评论:0      收藏:0      [点我收藏+]

获取access_token、expires_in

function GetMethod(HTTP: TIdHTTP; Url: String; Max: Integer): String;
var
  RespData: TStringStream;
begin
  RespData := TStringStream.Create(‘‘, TEncoding.UTF8);
  try
    try
      HTTP.Get(Url, RespData);
      HTTP.Request.Referer := Url;
      Result := RespData.DataString;
    except
      Dec(Max);
      if Max = 0 then
      begin
        Result := ‘‘;
        Exit;
      end;
      Result := GetMethod(Url, Max);
    end;
  finally
    FreeAndNil(RespData);
  end;
end;
const
TokenUrl = https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=%s&secret=%s;

procedure GetToken(AppID, AppSecret: String);
var
  Url: string;
  J: TJSONObject;
begin
  Url := Format(TokenUrl, [AppID, AppSecret]);
  J := TJSONObject.ParseJSONValue(GetMethod(Url, 1)) as TJSONObject;
  try
    if J.Count > 0 then
    begin
      Access_Token := J.GetValue(access_token).Value;
      Expires_IN := J.GetValue(expires_in).Value.ToInteger;
    end;
  finally
    J.Free;
  end;
end;

 

原文地址:http://www.cnblogs.com/devinlee/p/4282498.html

Delphi XE7 用indy开发微信公众平台(1)- 获取access_token、expires_in

原文:http://www.cnblogs.com/devinlee/p/4282498.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!