function MakeSign(const AParams: TStringList; const AppSecret: string;var sortQueryStringTmp :String): string; var I: Integer; sortedQueryString :string; stringToSign: string; sSign :string; outs: TStringList; pn,pv:string; skey:Tbytes; begin outs:= TStringList.Create; SortString( AParams,outs); // 参数拼接 sortQueryStringTmp := ''; for I := 0 to outs.Count - 1 do begin pn:=specialUrlEncode(outs.Names[I]); pv:=specialUrlEncode(outs.Values[outs.Names[I]]); sortQueryStringTmp := sortQueryStringTmp +pn + '='+ pv+'&'; end; setlength(sortQueryStringTmp,length(sortQueryStringTmp)-1); sortedQueryString:=sortQueryStringTmp; stringToSign :='GET&%2F&' + specialUrlEncode(sortedQueryString); memo3.Lines.Text:=stringToSign; skey:=THashSHA1.GetHMACAsBytes(Tencoding.UTF8.GetBytes(stringToSign), Tencoding.UTF8.GetBytes(AppSecret+'&')); sSign := TBase64Encoding.Create.EncodeBytesToString(skey); Result :=specialUrlEncode(sSign); end;
xalion写的,不是我!