1

尝试使用 ETSY api 请求登录,但似乎没有任何效果....

https://openapi.etsy.com/v2/oauth/request_token?oauth_consumer_key=a93ays32uckifw3k0lrsfy2n&oauth_nonce=82asXUrVrwV&oauth_signature_method=HMAC-SHA1&oauth_timestamp=1416562333&oauth_version=1.0&oauth_signature=mBVh

oauth_consumer_key = a93ays32uckifw3k0lrsfy2n
oauth_nonce = 82asXUrVrwV
oauth_signature_method = HMAC-SHA1
oauth_timestamp = 1416562333
oauth_version = 1.0
oauth_signature = mBhVKblbSBes1f3AkvaJmjJSJ24=

请建议如何进行

我试过下面的代码

<cfset tc = CreateObject("java", "java.util.Date").getTime()>
<cfset otimeStamp = Int(tc / 1000)>

<cfset iMin = 0>
<cfset iMax = CreateObject("java","java.lang.Integer").MAX_VALUE>
<cfset sToEncode = otimeStamp & RandRange(iMin, iMax)>
<cfset onounce =  Hash(sToEncode, "SHA")/>

<cffunction name="hmacEncrypt" returntype="binary" access="public" output="false">
    <cfargument name="signKey" type="string" required="true" />
    <cfargument name="signMessage" type="string" required="true" />
    <cfset var jMsg = JavaCast("string",arguments.signMessage).getBytes("iso-8859-1") />
    <cfset var jKey = JavaCast("string",arguments.signKey).getBytes("iso-8859-1") />
    <cfset var key = createObject("java","javax.crypto.spec.SecretKeySpec") />
    <cfset var mac = createObject("java","javax.crypto.Mac") />
    <cfset key = key.init(jKey,"HmacSHA1") />
    <cfset mac = mac.getInstance(key.getAlgorithm()) />
    <cfset mac.init(key) />
    <cfset mac.update(jMsg) />
    <cfreturn mac.doFinal() />
</cffunction>

<cfset result = hmacEncrypt("a93ays32uckifw3k0lrsfy2n", "GET&https%3A%2F%2Fopenapi.etsy.com%2Fv2%2Foauth%2Frequest_token&oauth_consumer_key%3Da93ays32uckifw3k0lrsfy2n%26oauth_nonce%3D#onounce#%26oauth_signature_method%3DHMAC-SHA1%26oauth_timestamp%3D#otimeStamp#%26oauth_version%3D1.0")>
<cfset osign = toString(tobase64(result))>

<cfhttp url="https://openapi.etsy.com/v2/oauth/request_token?oauth_consumer_key=a93ays32uckifw3k0lrsfy2n&oauth_nonce=#onounce#&oauth_signature_method=HMAC-SHA1&oauth_timestamp=#otimeStamp#&oauth_version=1.0&oauth_signature=#osign#">
        <cfhttpparam type="header" name="shop_id" value="cfdevshop">
        <cfhttpparam type="header" name="GData-Version" value="3">
</cfhttp>
<cfdump var="#cfhttp#">
4

2 回答 2

1

你的问题在于时间戳。您传递的时间戳不正确。您应该以秒为单位传递时间戳值。您可以按如下方式计算时间戳:

<cfset dateObj = now() />
<cfset timestamp = dateObj.getTime() />
<cfset timestampInSeconds = timestamp/1000 />
<cfdump var="#timestampInSeconds#"><cfabort>

时间戳应该是您系统当前时间戳的 +/- 5 分钟。
我在我的代码中使用了您在此处提供的所有参数,如下所示:

<cfhttp url="https://openapi.etsy.com/v2/oauth/request_token">
    <cfhttpparam type="header" name="GData-Version" value="3">
    <cfhttpparam type="url" name="oauth_signature" value="mBhVKblbSBes1f3AkvaJmjJSJ24=" >
    <cfhttpparam type="url" name="oauth_version" value="1.0" >
    <cfhttpparam type="url" name="oauth_timestamp" value="#timestampInSeconds#" >
    <cfhttpparam type="url" name="oauth_signature_method" value="HMAC-SHA1" >
    <cfhttpparam type="url" name="oauth_nonce" value="8225XUrVrwV" >
    <cfhttpparam type="url" name="oauth_consumer_key" value="a93ays32uckifw3k0lrsfy2n" >
</cfhttp>
<cfdump var="#cfhttp#"><cfabort>

我猜你提供了虚拟值(这是一件好事)。您可以在屏幕截图中看到我收到不同的错误(无效的 oauth 签名错误)。如果您提供正确的值,我认为您很高兴。
在此处输入图像描述

getTime()方法是一个java方法Date class。你可以看看它是如何工作的:

<cfset dateObj = createObject("java","java.util.Date") />
<cfset timeStamp = dateObj.getTime() />
<cfdump var="#timeStamp#"><cfabort>
于 2014-11-21T15:33:29.167 回答
1

使用此包成功完成 Etsy Oauth 身份验证 http://oauthconsumer.riaforge.org/

于 2014-11-26T10:01:01.753 回答