代码之家  ›  专栏  ›  技术社区  ›  Shiv Deepak

谷歌AppEngine验证码

  •  1
  • Shiv Deepak  · 技术社区  · 15 年前

    我有一个网站 i want to put a custom made captcha ,由于布局需要,无法使用联机验证码服务。它运行在google appengine上。 appengine API是否有用于在给定图像上写入字符的东西?

    appengine Python Image API 但这似乎没有多大帮助。

    有什么建议可以在google appengine基础设施上生成验证码吗?

    5 回复  |  直到 15 年前
        1
  •  2
  •   Drew Sears    15 年前

    一般来说,你不能。

    图像API是为转换现有的图像而设计的,而不是生成新的图像。

    理论上,如果您找到一个纯Python图像创建库,它将在App Engine上运行,但速度会很慢。

        2
  •  8
  •   Adam Crossland    15 年前

    A quick google search 将为您提供大量指南,帮助您将captch服务与AppEngine应用程序集成。 Here's one 使用reCaptcha。

        3
  •  1
  •   Alois Cochard    15 年前
        4
  •  1
  •   Jaime Ivan Cervantes    13 年前

    我建议使用第三方服务,比如reCaptcha,但是如果您真的需要提供自己的实现,可以使用最近引入的Matplotlib for GAE+Python来生成自己的图像。

    Matplotlib是Python的一个绘图库,最近在2012年12月作为GAE的一部分引入。可以使用Matplotlib呈现文本,如 this example . 如果对验证码有美学限制,可以使用Matplotlib呈现非常花哨的文本和数字。看看 this example .

        5
  •  0
  •   user1788142    13 年前

    您可以使用以下代码创建验证码,请注意,您必须在类路径中添加commons-lang-2.5.jar。

            String secutiryCode = RandomStringUtils.random(5, new char[]{'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z','0','1','2','3','4','5','6','7','8','9'});
            req.getSession().setAttribute("secutiryCode", secutiryCode);
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            URL url = new URL("http://util.krispot.com/util/SecurityImage.jpg?secutiryCode=" + secutiryCode);
            HttpURLConnection connection = (HttpURLConnection) url.openConnection();
            connection.setDoOutput(true);
            connection.setDoInput(true);
                BufferedInputStream bis = new BufferedInputStream(connection.getInputStream());
                for(int i = bis.read(); i > -1;i = bis.read()) {
                    baos.write(i);
                }
            BufferedOutputStream bos = new BufferedOutputStream(resp.getOutputStream());
            bos.write(baos.toByteArray());
            bos.close();
    

    谢谢您,