我想在php中生成oath_signature但是实验文档是用.net编写的。我试着询问表格实验开发人员,但他反应不好。我使用以下代码来开发oath_signature:
$ timestamp = 1461944620; //时间戳
$ nonce = 3774707; // nuncio
$ consumerKey =“e172b7b1-056f-48be-aeca-a641a60c88ea”; //消费者密钥 - 由experian dev提供。
$ consumerSecret =“1c339256-2e1c-48bb-82c2-8e33abe550fd”; //消费者秘密 - 由experian dev提供。
$ url =“https://demo.backgroundchecking.com/API/Service/ProductCodes”; //网址 - 由experian dev提供。
$ httpMethod =“GET”;
$ params =“oauth_consumer_key =”。$ consumerKey。“&oauth_nonce =”。$ nonce。“&oauth_signature_method = HMAC-SHA1&oauth_timestamp =”。$ timestamp。“&oauth_version = 1.0”;
$ urlEncoded = urlencode($ url); //网址编码
$ paramsEncoded = urlencode($ params); //网址编码
$ signature Base = $ httpMethod。“&”。$ urlEncoded。“&”。$ param Encoded; //签名库 - 根据您的文档生成
$ key = urlencode($ consumerSecret)。“&”; // mysecretkey& - url编码秘密凯,然后是&符号
$ signatureBytes = hash_hmac(“sha1”,$ signatureBase,$ key); //转换为sha1
$ signature = base64_encode($ signature Bytes); // base64加密
$ signatureEncoded = urlencode($ signature); //签名网址编码。这是最终签名,与我在之前的电子邮件中描述您的签名不符。
我已经去了“NjdhNTUyMDU2Y2M2MDcyMTQ2ZDNkZWFjYjUxODVlOGQ3MGZlZWM1Mg%3D%3D”签名,但是开发人员说,使用上面的细节它必须生成“Z6VSBWzGByFG096stRhejXD%2b7FI%3d”誓言签名。
以下是生成oath_signature的文档:
手动生成签名1.我们需要按字母顺序对查询参数进行排序,并添加一些参数,然后将它们组合成一个字符串。此字符串看起来像标准查询字符串,但您实际上并不打算将其发送到服务器。 oauth_consumer_key = myconsumerkey&oauth_nonce = 123456&oauth_signature_method = HMAC-SHA1&oauth_timestamp = 999999&oauth_version = 1.0重要的是,字符串看起来与此完全相同,只有斜体字的三个值被您的值替换。
假设您正在发布“以上提供网址(demo.backgroundchecking.com/API/Service/ProductCodes)”,那么签名库将如下所示(换行符只是为了可读性,这应该都是一行):3。POST& 4. https%3A%2F%2Fuat.backgroundchecking.com%2FAPI%2FData%2FRequestData&5。oauth_consumer_key%3Dmyconsumerkey%26oauth_nonce%3D123456%26oauth_signature_method%3DHMAC-SHA1%26oauth_timestamp%3D999999%26oauth_version%3D1.0
如您所见,Signature Base字符串由三个单独的元素组成,HTTP方法,URL和步骤1中的参数,所有元素都以&分隔。在将这三个部分中的每个部分组合到签名库字符串之前对它们进行URL编码是很重要的,否则分离&也将被编码,您的请求将失败。还要注意,十六进制值必须为大写,即%2F而不是%2f。请注意此示例中的uat.backgroundchecking.com当然需要更改为您正在使用的系统的相应URL。
再举一个例子,如果你是从demo.backgroundchecking.com/API/Service/ProductCodes获取,那么Signature Base字符串看起来就像这样(方法和URL不同):GET&https%3A%2F%2Fuat.backgroundchecking .com%2FAPI%2FService%2FProductCodes&oauth_consumer_key%3Dmyconsumerkey%26oauth_nonce%3D123456%26oauth_signature_method%3DHMAC-SHA1%26oauth_timestamp%3D999999%26oauth_version%3D1.0
示例是:1。[int] $ timestamp =((Get-Date).ToUniversalTime() - (Get-Date -Date“1970-01-01 00:00:00Z”)。ToUniversalTime())。TotalSeconds
$timestamp = time();
$nonce = 5678765;
$consumerKey = "consumerkey";
$consumerSecret = "secret";
$url = "demo.backgroundchecking.com/API/Service/ProductCodes";
$httpMethod = "GET";
$params = "oauth_consumer_key=".$consumerKey."&oauth_nonce=".$nonce."&oauth_signature_method=HMAC-SHA1&oauth_timestamp=".$timestamp."&oauth_version=1.0";
$urlEncoded = urlencode($url);
$paramsEncoded = urlencode($params);
$signatureBase = $httpMethod."&".$urlEncoded."&".$paramsEncoded;
$key = urlencode($consumerSecret)."&";
$signature = urlencode(base64_encode(hash_hmac('sha1', $signatureBase, $key, true)));