-1
私はC#PHPのhash_hmac - にWebResponse "NONCE_NOT_PROVIDED"
ハッシュ・用PHP
$apikey='xxx';
$apisecretkey='yyy';
$nonce=time();
$uri='https://website.com/api/getsomething?apikey='.$apikey.'&nonce='.$nonce;
$sign=hash_hmac('sha512',$uri,$apisecretkey);
$resource = curl_init($uri);
curl_setopt($resource, CURLOPT_HTTPHEADER, array('apisign:'.$sign));
$execResult = curl_exec($resource);
$obj = ($execResult);
、ここで私のC#
WebRequest _WebRequest;
WebResponse _WebResponse;
string apikey = "xxx";
string apisecret = "yyy";
string nonce = ((int)(DateTime.UtcNow - new DateTime(1970,1,1)).TotalSeconds).ToString();
string uri = $"https://website.com/api/getsomething?apikey={apikey}nonce={nonce}";
string _Hash_hmac = Hash_hmac(uri, apisecret);
_WebRequest = WebRequest.Create(uri);
_WebRequest.Headers["apisign"] = _Hash_hmac;
_WebResponse = _WebRequest.GetResponse();
コードにPHPのコードを変換しようhmac私はこれを使用しますC# equivalent to hash_hmac in PHP
Webresponseは常に"NONC E_NOT_PROVIDED "
私はhash_hmacからの結果をphpの結果とチェックしました - それらは同じです。 また、ToUpperとToLowerという文字列を試してみてください。
私は間違っていますか?
この行に**文字列uri = $ "https://website.com/api/getsomething?apikey={apikey}nonce={nonce}"; **を置き換えます** string uri = $ "https ://website.com/api/getsomething?apikey = {apikey}&nonce = {nonce} "; ** –
私は '&'と思ったのは、PHP構文の一部でした。今それは良く見える。ただ "INVALID_SIGNATURE"を取得してください –
これは、渡しているパラメータが原因である可能性があります。あなたは、あなたがc#で渡している日付値が異なる形式であるので、コード(両方のPHP **と** C#**)をデバッグする必要があります。 –