尝试使用ETSY api进行request_login但似乎没有任何工作......
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#">
答案 0 :(得分: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()
方法是Date class
的java方法。你可以看到它是如何工作的:
<cfset dateObj = createObject("java","java.util.Date") />
<cfset timeStamp = dateObj.getTime() />
<cfdump var="#timeStamp#"><cfabort>
答案 1 :(得分:1)
使用此软件包成功完成Etsy Oauth身份验证 http://oauthconsumer.riaforge.org/