Пример #1
0
// unimpl
func (this *User) Register() (err error) {
	var verify = ""
ret:
	res, err := this.post("/register/ajax", url.Values{
		"username": {this.Username},
		"password": {this.Password},
		"email":    {this.QQ + "@qq.com"}, // 新版可以用任意邮箱注册
		"verify":   {verify},
	})
	if err != nil {
		return
	}
	rst, _ := ioutil.ReadAll(res.Body)
	res.Body.Close()
	var obj map[string]string
	json.Unmarshal(rst, &obj)
	status := obj["status"]
	if status == "error" {
		res, err = this.getCapture()
		ascgen.ShowFile(os.Stdout, res.Body, ascgen.Console{6, 14, 120}, true, true)
		res.Body.Close()
		fmt.Print("Enter code: ")
		bf := bufio.NewReader(os.Stdin)
		verify, _ = bf.ReadString('\n')
		if len(verify) > 4 {
			verify = verify[:4]
		}
		goto ret
	}
	return errors.New(obj["message"])
}
Пример #2
0
// 获取验证码
func (this *WebQQ) ptlogin_getimage(vc_type string) (code string, err error) {
	res, err := this.client.Get(_CAPTCHA_URL + "getimage?" + (url.Values{
		"uin":     {this.id_str},
		"aid":     {_WEBQQ_APPID},
		"r":       {rand_r()},
		"vc_type": {vc_type}}).Encode())
	if err != nil {
		return
	}
	defer res.Body.Close()
	rw, err := os.Create("vc.jpg")
	if err != nil {
		return
	}
	io.Copy(rw, res.Body)
	rw.Seek(0, 0)
	asc.ShowFile(os.Stdout, rw, asc.Console{6, 14, 120}, false, false) // TODO: 缺乏配置
	rw.Close()
	fmt.Println()
	fmt.Print("Enter Verify Code: ")
	fmt.Scanf("%s\n", &code)
	return
}