rucaptcha
rucaptcha copied to clipboard
提供一个captcha ID 的接口会不会更好用?
先在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