Exemplo n.º 1
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.º 2
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.º 3
0
// SSL方式连接服务器 (与STARTTLS方式不同 适用于465端口)
func (this *SMTPClient) sendSSL(to []string, title, context string) (err error) {
	defer util.Catch(&err)
	host := this.Server[:strings.Index(this.Server, ":")]
	conn, err := tls.Dial("tcp", this.Server, nil)
	if err != nil {
		return err
	}
	c, err := smtp.NewClient(conn, host)
	if err != nil {
		return err
	}
	*(*bool)(unsafe.Pointer(reflect.ValueOf(c).Elem().FieldByName("tls").UnsafeAddr())) = true // set tls to true for AUTH

	if this.auth != nil {
		if ok, _ := c.Extension("AUTH"); ok {
			if err = c.Auth(this.auth); err != nil {
				return err
			}
		}
	}
	if err = c.Mail(this.User); err != nil {
		return err
	}
	for _, addr := range to {
		if err = c.Rcpt(addr); err != nil {
			return err
		}
	}

	w, err := c.Data()
	if err != nil {
		return err
	}
	body := []byte(strings.Join([]string{
		"From: " + this.User,
		"To: " + strings.Join(to, ","),
		"Subject: " + title,
		"Content-Type: text/html; charset=utf-8;",
		"",
		context,
	}, "\r\n"))
	_, err = w.Write(body)
	if err != nil {
		return err
	}

	err = w.Close()
	if err != nil {
		return err
	}

	return c.Quit()
}
Exemplo n.º 4
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.º 5
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
}