微信公众平台——获取access_token、expires_in
在微信公众平台接口开发中,Access Token占据着重要地位,它相当于进入各种接口的邀请,拿到这个钥匙才拥有调用其他各种特殊接口的权限。
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;
uses System.JSON;const
TokenUrl = 'https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=%s&secret=%s';procedure GetToken(AppID, AppSecret: String);
var