Gem 使用 zhima_auth 提示 ZhimaAuth::InvalidResponse

ghn645568344 · 2017年07月17日 · 最后由 alexneverpo 回复于 2017年08月03日 · 1727 次阅读

RT 今天使用了一下 gem 'zhima_auth' 按照 git 上给的例子测试了一下,报

irb(main):013:0* ZhimaAuth.certify params
ZhimaAuth::InvalidResponse: ZhimaAuth::InvalidResponse
    from /usr/local/lib/ruby/gems/2.2.0/gems/zhima_auth-0.3.0/lib/zhima_auth/validation.rb:31:in `check_initialize_response'
    from /usr/local/lib/ruby/gems/2.2.0/gems/zhima_auth-0.3.0/lib/zhima_auth/request.rb:41:in `get_biz_no'
    from /usr/local/lib/ruby/gems/2.2.0/gems/zhima_auth-0.3.0/lib/zhima_auth.rb:24:in `certify'
    from (irb):13
    from /usr/local/lib/ruby/gems/2.2.0/gems/railties-4.2.5.2/lib/rails/commands/console.rb:110:in `start'
    from /usr/local/lib/ruby/gems/2.2.0/gems/railties-4.2.5.2/lib/rails/commands/console.rb:9:in `start'
    from /usr/local/lib/ruby/gems/2.2.0/gems/railties-4.2.5.2/lib/rails/commands/commands_tasks.rb:68:in `console'
    from /usr/local/lib/ruby/gems/2.2.0/gems/railties-4.2.5.2/lib/rails/commands/commands_tasks.rb:39:in `run_command!'
    from /usr/local/lib/ruby/gems/2.2.0/gems/railties-4.2.5.2/lib/rails/commands.rb:17:in `<top (required)>'
    from /usr/local/lib/ruby/gems/2.2.0/gems/activesupport-4.2.5.2/lib/active_support/dependencies.rb:274:in `require'
    from /usr/local/lib/ruby/gems/2.2.0/gems/activesupport-4.2.5.2/lib/active_support/dependencies.rb:274:in `block in require'
    from /usr/local/lib/ruby/gems/2.2.0/gems/activesupport-4.2.5.2/lib/active_support/dependencies.rb:240:in `load_dependency'
    from /usr/local/lib/ruby/gems/2.2.0/gems/activesupport-4.2.5.2/lib/active_support/dependencies.rb:274:in `require'
    from /mnt/apix/qianbao/bin/rails:9:in `<top (required)>'
    from /usr/local/lib/ruby/gems/2.2.0/gems/activesupport-4.2.5.2/lib/active_support/dependencies.rb:268:in `load'
    from /usr/local/lib/ruby/gems/2.2.0/gems/activesupport-4.2.5.2/lib/active_support/dependencies.rb:268:in `block in load'
    from /usr/local/lib/ruby/gems/2.2.0/gems/activesupport-4.2.5.2/lib/active_support/dependencies.rb:240:in `load_dependency'
    from /usr/local/lib/ruby/gems/2.2.0/gems/activesupport-4.2.5.2/lib/active_support/dependencies.rb:268:in `load'
    from /usr/local/lib/ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require'
    from /usr/local/lib/ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require'
    from -e:1:in `<main>'irb(main):014:0> 

报错提示太少了,没有思路,就看了下提示的 /usr/local/lib/ruby/gems/2.2.0/gems/zhima_auth-0.3.0/lib/zhima_auth/validation.rb:31:in `check_initialize_response' 的源码, 发现报错信息不一样,感觉比较差异,是我的排错方式不对吗?

def check_initialize_response response
  raise ZhimaAuth::InvalidResponse, "Initialize request failed" unless (response.is_a? Hash) && response["zhima_customer_certification_initialize_response"]
  response_code = response["zhima_customer_certification_initialize_response"]["code"]
  if response_code != "10000"
    response_msg = response["zhima_customer_certification_initialize_response"]["sub_msg"]
    raise ZhimaAuth::InvalidResponse, "#{response_code}#{response_msg}"
  end
  true
end

请教各位大神啦

ghn645568344 芝麻认证 on Rails 提及了此话题。 07月17日 15:31

@ghn645568344 params 可以发过来看一下吗?

😅 现在还没有功能比较全的 gem 可以用,建议自己实现,可以随时扩展和填坑。(多问问技术客服😂 )

需要 登录 后方可回复, 如果你还没有账号请 注册新账号