跳转到内容
View in the app

A better way to browse. Learn more.

彼岸论坛

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.
欢迎抵达彼岸 彼岸花开 此处谁在 -彼岸论坛

[V2EX] V2ex 客户端模拟登录,一直提示「验证码错误」?

发表于

最近在做一款 V2EX Android App ,正在实现登录功能。

已经有不少优秀的 V2EX 客户端开源项目,我经常参考的如:

Android: https://github.com/v2er-app/Android

iOS: https://github.com/Finb/V2ex-Swift

通过查看他们源码得知,模拟登录的步骤如下:

  1. 发送一个 get 请求到 /signin 。通过解析网页结果,获取到用户名,密码,以及验证码的 form key ,以及一个字符串 once 。
  2. 通过拼接 /_captcha?once=$once ,得到验证码的图片 url ,加载该 url ,让用户查看和输入验证码
  3. 发送 post 请求到 /signin, 这是一个表单请求,结合第一步的 form key 和 once 以及用户输入的验证码拼装表单数据。
  4. 通过第 3 步返回的 response code 和数据判断是否登录成功。

现在卡在第 3 步,现象是:即使我十分确定验证码正确的情况下,还是会得到提示「验证码错误」的情况。

经过反复对比实现方式,我比较确定自己的代码的实现是没问题的,有一些细节比如添加一些额外的 header 之类的我也做了,但是还是出现这个问题。我自己的一些猜测的可能:

  1. IP 和账号问题。(通过使用别的客户端,发现可以正常登录,排除。)
  2. 验证码 url 被加载了多次,导致界面上看到的不是最新的验证码。(通过手动加载验证码并确保只加载一次,还是有问题。)
  3. 加载验证码 url 的请求的 header 必须和请求 /signin 时保持一致。(通过修改代码确保一致,无果。)

折腾一两天,现在有点黔驴技穷的感觉,另外登录次数多了还会导致 IP 被风控,导致调试都是谨小慎微。

不知道 v 友有没啥好的想法?

Featured Replies

No posts to show

创建帐户或登录来提出意见

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.