Exemplo n.º 1
0
// [2]检查, 可重复
func (this *WebQQ) ptlogin_check() (codetoken, code string, err error) {
	res, err := this.getWithReferer(_PTLOGIN_URL+"check?"+(url.Values{
		"uin":     {this.id_str},
		"appid":   {_WEBQQ_APPID},
		"js_ver":  {_JS_VER},
		"js_type": {"0"}, "u1": {"http://web2.qq.com/loginproxy.html"},
		"r": {rand_r()}}).Encode(), this.sig_url)
	util.Try(err)
	bs, err := ioutil.ReadAll(res.Body)
	res.Body.Close()
	util.Try(err)
	s := string(bs)
	if s[14] == '0' { //ptui_checkVC('0','!YIZ','\x00\x00\x00\x00\x04\x82\x43\x7e');
		util.DEBUG.Log("[ptlogin_check] check ok")
		code = s[18:22]
	} else if s[14] == '1' { //ptui_checkVC('1','f5961ec58f7057466b40d950d5817b173f2400a1bca95ddc','\x00\x00\x00\x00\x2d\x16\xa2\x80');
		util.DEBUG.Log("[ptlogin_check] check need getimage")
		codetoken = s[18:66]
		code, err = this.ptlogin_getimage(codetoken)
	} else {
		err = fmt.Errorf("[ptlogin_check]失败返回值: %s", s)
	}
	util.Try(err)
	util.DEBUG.Logf("[ptlogin_check] return OK [code] %s", code)
	return
}
Exemplo n.º 2
0
// 转换到下层对象
func (this ContentModel) Encode(webqq *WebQQ) (v Content) {
	matches := contentPatten.FindAllStringSubmatch(this.Message, -1)
	if matches == nil { // 没有图片
		v = make([]json.RawMessage, 1, 2)
		b, err := json.Marshal(this.Message)
		util.Try(err)
		v[0] = json.RawMessage(b)
	} else {
		v = make([]json.RawMessage, 0, len(matches)*2+2) // 123[]1[]2[]3 = 3*2+1 = 7
		for _, v1 := range matches {
			switch v1[1] {
			case "offpic":
				b, err := json.Marshal([]interface{}{v1[1], Offpic{Success: 1, FilePath: v1[2]}})
				if err == nil {
					v = append(v, b)
				}
			case "cface":
				b, err := json.Marshal([]interface{}{v1[1], Cface{Key: webqq.cface_key, Name: v1[2], Server: DefaultServer}})
				if err == nil {
					v = append(v, json.RawMessage(b))
				}
			case "face":
				b, err := json.Marshal([]interface{}{v1[1], util.ToInt(v1[2])})
				if err == nil {
					v = append(v, json.RawMessage(b))
				}
			}
		}
	}

	b, err := json.Marshal([]interface{}{"font", this.Font})
	util.Try(err)
	v = append(v, json.RawMessage(b))
	return v
}
Exemplo n.º 3
0
// 登录 [2013.8.27]
func (this *WebQQ) Login() (err error) {
	defer util.Catch(&err)
	// [1] login_sig
	this.login_sig, err = this.ptlogin_login_sig()
	util.Try(err)
check:
	// [2] check
	_, code, err := this.ptlogin_check()
	util.Try(err)
	// [3] login
	pturl, err := this.ptlogin_login(code)
	if err != nil {
		goto check
	}
	// [4] check_sig
	err = this.ptlogin_check_sig(pturl)
	util.Try(err)
	if this.ptwebQQ = this.getCookie(util.MustParseUrl(_PTLOGIN_URL), "ptwebqq"); this.ptwebQQ == "" {
		return fmt.Errorf("[ptwebqq] Failed to read cookie.")
	}
	// [5] login2
	ret, err := this.login2()
	util.Try(err)
	if ret.Code != 0 {
		return fmt.Errorf("[channel_login2] %v : %s", ret.Code, ret.Msg)
	}
	this.vfwebqq = ret.Result.VerifyCode
	this.psessionid = ret.Result.SessionId
	this.Uin = ret.Result.Uin
	util.INFO.Log("[Login] Login success")
	return
}
Exemplo n.º 4
0
// [1]检查前获取sig, 永久 [2013-8-27]
func (this *WebQQ) ptlogin_login_sig() (login_sig string, err error) {
	res, err := this.client.Get(this.sig_url)
	util.Try(err)
	bs, err := ioutil.ReadAll(res.Body)
	util.Try(err)
	res.Body.Close()
	login_sig = regexp.MustCompile(`var g_login_sig=encodeURIComponent\("(.+?)"\);`).FindStringSubmatch(string(bs))[1]
	util.DEBUG.Logf("[ptlogin_login_sig] login_sig = %s ", login_sig)
	return
}
Exemplo n.º 5
0
//本地拨号
func (this *Dialer) DisconnectDirect() (err error) {
	defer util.Catch(&err)
	this.checkIP()
	info, err := this.dial_getinfo()
	util.Try(err)
	rst, err := this.dial_logout(info)
	util.Try(err)
	util.DEBUG.Log(rst)
	return
}
Exemplo n.º 6
0
func NewLevelDbFriendJar(filename string) (this *LevelDbFriendJar) {
	this = &LevelDbFriendJar{}
	db, err := leveldb.Open(filename, nil)
	util.Try(err)
	this.db = db
	return this
}
Exemplo n.º 7
0
// [4]用获取cookie [2013-8-27]
func (this *WebQQ) ptlogin_check_sig(urlStr string) (err error) {
	res, err := this.client.Get(urlStr)
	util.Try(err)
	res.Body.Close()
	util.DEBUG.Logf("[ptlogin_check_sig] check ok")
	return
}
Exemplo n.º 8
0
// [3]单点登录, 可重复
func (this *WebQQ) ptlogin_login(code string) (urlStr string, err error) {
	res, err := this.getWithReferer(
		_PTLOGIN_URL+"login?"+(url.Values{
			"u":            {this.id_str},
			"p":            {this.genPwd(code)},
			"verifycode":   {code},
			"webqq_type":   {_WEBQQ_TYPE},
			"action":       {_LOGIN_ACTION},
			"js_ver":       {_JS_VER},
			"aid":          {_WEBQQ_APPID},
			"remember_uin": {"1"}, "login2qq": {"1"}, "u1": {"http://web2.qq.com/loginproxy.html?login2qq=1&webqq_type=10"}, "h": {"1"}, "ptredirect": {"0"}, "ptlang": {"2052"}, "daid": {"164"}, "from_ui": {"1"}, "pttype": {"1"}, "dumy": {""}, "fp": {"loginerroralert"}, "mibao_css": {"m_webqq"}, "t": {"1"}, "g": {"1"}, "js_type": {"0"},
			"login_sig": {this.login_sig}}).Encode(), this.sig_url)
	util.Try(err)
	defer res.Body.Close()
	raw := util.MustReadAll(res.Body)
	ss := strings.Split(string(raw), "'")
	// 出错
	if ss[1] != "0" {
		err = fmt.Errorf("[ptlogin_login] fail_login %s:%s", ss[1], ss[9])
		return
	}
	//ptuiCB('0','0','http://ptlogin4.web2.qq.com/check_sig?pttype=1&uin=2735284921&service=login&nodirect=0&ptsig=MPlx81vcwwhHDYZeAsCdaFoQg3nTXyy67sQAYCewxu0_&s_url=http%3a%2f%2fweb2.qq.com%2floginproxy.html%3flogin2qq%3d1%26webqq%5ftype%3d10&f_url=&ptlang=2052&ptredirect=100&aid=1003903&daid=164&j_later=0&low_login_hour=0&regmaster=0','0','登录成功!', '菊菊菊菊菊菊');
	urlStr = ss[5]
	util.DEBUG.Logf("[ptlogin_login] return %s", ss[9])
	return
}
Exemplo n.º 9
0
func (this *Dialer) dial_getinfo() (info *loginInfo, err error) {
	defer util.Catch(&err)
	body := ioutil.NopCloser(strings.NewReader((url.Values{"wlanuserip": {this.UserIP}}).Encode()))
	req, err := http.NewRequest("POST", "http://115.239.134.163:8080/showlogin.do", body)
	util.Try(err)
	req.Header.Set("User-Agent", "China Telecom Client")
	req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
	res, err := http.DefaultClient.Do(req)
	util.Try(err)
	data, _ := ioutil.ReadAll(res.Body)
	res.Body.Close()
	info = &loginInfo{}
	xml.Unmarshal(data, &info)
	util.DEBUG.Log("[dial_getinfo] ", string(data))
	return
}
Exemplo n.º 10
0
func (this *Dialer) dial_logout(info *loginInfo) (rst *loginResult, err error) {
	defer util.Catch(&err)
	parms := url.Values{
		"uuid":   {info.Uuid},
		"userip": {info.UserIP},
	}
	body := ioutil.NopCloser(strings.NewReader(parms.Encode()))
	util.DEBUG.Log("[dial_logout] ", parms)
	req, err := http.NewRequest("POST", "http://115.239.134.163:8080/servlets/G3logoutServlet", body)
	util.Try(err)
	req.Header.Set("User-Agent", "China Telecom Client")
	req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
	res, err := http.DefaultClient.Do(req)
	util.Try(err)
	data, _ := ioutil.ReadAll(res.Body)
	res.Body.Close()
	rst = &loginResult{}
	xml.Unmarshal(data, &rst)
	util.DEBUG.Log("[dial_logout] ", string(data))
	return
}