Traditional Culture Encyclopedia - Weather forecast - Weather forecast interface: the method of calculating key with c# in SmartWeather API.

Weather forecast interface: the method of calculating key with c# in SmartWeather API.

String GetKey (string appid, string privateKey, string areaId, string date, string type)

{

//HMAC uses SHA 1

HMAC hmac = HMACSHA 1。 create();

var publicKey = "/data/? areaid = { 0 } & amptype = { 1 } & amp; Date = {2} & ampappid = {3} ";;

Var data = system. Text.Encoding.UTF8.GetBytes (string. Format(publicKey,areaId,type,date,appid));

//key

Var key = system. text . encoding . utf8 . getbytes(private key);

hmac。 Key = key

//signing data

var signedData = hmac。 ComputeHash (data);

Return to the transformation. to base 64 string(signed data);

}

Reference: blogs.com/aptdo2008/p/3566391.html.