【问题标题】:Translating High Resolution Adobe Creative SDK from PHP to Ruby on Rails将高分辨率 Adob​​e Creative SDK 从 PHP 转换为 Ruby on Rails
【发布时间】:2016-07-14 14:30:44
【问题描述】:

我正在尝试将 Adob​​e 的 Creative SDK 实施到我的 Ruby on Rails 应用程序中。

https://creativesdk.adobe.com/docs/web/#/articles/highresolution/index.html

我拥有对高分辨率 API 的所需访问权限。

他们的例子是 PHP 和 Node.js,我正在尝试编写一个基于 PHP 的 Ruby on Rails 版本。我已经完成了所有设置,因为它正确调用了“authenticationURL”,但我收到了“无效的 authenticationURL 响应。请检查响应的格式。”

我是这个级别的编程新手,基本上是通过参考一些关于 PHP 和 Ruby 的问题以及http://www.phptoruby.com/ 等网站来解决这个问题。

这里是 PHP:

<!-- /getAuth -->

<?php
$apiKey = "apikey";
$apiSecret = "apisecret";
$salt = rand(0,1000);
$time = time();
$sig = sha1($apiKey . $apiSecret . $time . $salt);

$authObj = array(
    "apiKey" => $apiKey,
    "salt" => $salt,
    "timestamp" => $time,
    "encryptionMethod" => 'sha1',
    "signature" => $sig
);

echo json_encode($authObj);

?>

这是我目前所拥有的(我的 apikey 和 apisecret 输入正确):

require 'time'
require 'json'
require 'digest/sha1'

def get_auth
 apiKey = 'apikey'
 apiSecret = 'apisecret'
 salt = "#{0 + rand(1000)}"
 time = "#{Time.now.to_i}"
 sig = Digest::SHA1.hexdigest('apiKey' + 'apiSecret' + 'time' + 'salt')


 authObj = { :apiKey => 'apiKey',
                 :salt => 'salt',
                 :timestamp => 'time',
                 :encryptionMethod => 'sha1',
                 :signature => 'sig' }

 print 'authObj'.to_json
 render :fxb
end

我不确定在这里使用print 是否正确?或者,如果我的问题是语法问题……或者完全是其他问题。

【问题讨论】:

  • 您的问题解决了吗?我也收到与“无效的 authenticationURL 响应。请检查响应的格式。”相同的错误。我正在使用 c#,我也可以访问高分辨率 API。向adobe提出投诉,但没有人回应。 Auth 对象是在 C# 中正确创建的,我已经将 json 与 auth 对象的创意云文档测试 url 进行了比较,但仍然无法正常工作 jsbin.com/xoxaqoropu
  • 好的,我已经为我解决了问题。在调试了缩小的 aviary js 之后,我发现我的 getAuth 函数返回了正确的 json (auth),但我必须添加响应头,以便 aviary 可以将 auth json 对象解析为签名、时间戳。所以我必须在返回 json 之前在 getAuth 方法中添加以下内容。没有它,aviary 会将 auth json 读取为字符串而不是对象,并且无法解析它。响应。清除(); Response.ContentType = "application/json; charset=utf-8";

标签: javascript php ruby-on-rails adobecreativesdk


【解决方案1】:

尝试改变

 sig = Digest::SHA1.hexdigest('apiKey' + 'apiSecret' + 'time' + 'salt')

 sig = Digest::SHA1.hexdigest(apiKey + apiSecret + time + salt)

使用单引号,它将apiKey 字符串本身作为要散列的值,而不是它的值。

此外,还需要更改以下内容以删除单引号:

authObj = { :apiKey => 'apiKey',
                 :salt => 'salt',
                 :timestamp => 'time',
                 :encryptionMethod => 'sha1',
                 :signature => 'sig' }

 print 'authObj'.to_json

authObj = { :apiKey => apiKey,
                 :salt => salt,
                 :timestamp => time,
                 :encryptionMethod => sha1,
                 :signature => sig }

 print authObj.to_json

【讨论】:

  • 太棒了。不再收到该错误,但现在我收到NameError (undefined local variable or method 'sha1' for #&lt;UploadsController:0x007fdca15aaef8&gt;): app/controllers/uploads_controller.rb:28:in 'get_auth'
  • 我将:encryptionMethod =&gt; sha1 更改为:encryptionMethod =&gt; 'sha1',但我不再在日志中看到NameError,事实上,日志中的一切似乎都正常——盐、时间戳、签名和加密方法(as 'sha1') 都在那里,但现在我再次收到初始的“Invalid authenticationURL response”javascript 错误。
【解决方案2】:

将此添加为控制器操作:

  def auth_aviary
    timestamp = Time.now.to_i.to_s
    salt = rand(1000).to_s
    sig = Digest::SHA1.hexdigest(
            Conf.aviary_api_key + 
            Conf.aviary_api_secret + 
            timestamp + 
            salt
          )
    render json: {
      "apiKey" => Conf.aviary_api_key,
      "salt" => salt,
      "timestamp" => timestamp,
      "encryptionMethod" => 'sha1',
      "signature" => sig
    }
  end

【讨论】:

    【解决方案3】:

    为仍然面临问题的人回复旧帖子。该解决方案可能有效(至少对于 asp.net)。我遇到了同样的错误,一旦我将响应内容类型设置为“application/json; charset=utf-8”,它就得到了解决。没有它,aviary 会将 auth json 读取为字符串而不是对象,并且无法将其解析为时间戳、签名等

    Response.ContentType = "application/json; charset=utf-8";
    

    希望它会有所帮助。

    【讨论】:

      【解决方案4】:

      是的,我在 php 中设置了标题并且一切正常。

      header('Content-Type: application/json');

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2019-01-16
        • 1970-01-01
        • 1970-01-01
        • 2016-09-08
        • 1970-01-01
        • 1970-01-01
        • 2011-09-30
        相关资源
        最近更新 更多