rucaptcha icon indicating copy to clipboard operation
rucaptcha copied to clipboard

提供一个captcha ID 的接口会不会更好用?

Open qbig opened this issue 5 years ago • 0 comments

先在captcha 的索引是通过rucaptcha_sesion_key_key 来存在session 里面的。但是如果是无状态的API 接口的话(移动端),就不太好用了。

像这样把captcha 在存储中的key 返回,就可以支持不用cookie 的API了


  def new_generate_rucaptcha
    res = RuCaptcha.generate()
    session_val = {
        code: res[0],
        time: Time.now.to_i
    }
    RuCaptcha.cache.write(rucaptcha_sesion_key_key, session_val, expires_in: RuCaptcha.config.expires_in)
    opts = { disposition: 'inline', type: 'image/gif', filename: rucaptcha_sesion_key_key }
    send_data  res[1], opts
  end

qbig avatar Mar 12 '19 08:03 qbig