Ejemplo n.º 1
0
func (qq *Client) GetId(uin string, b ...*BuddyInfo) (str string, err error) {
	defer func() {
		if e := recover(); e != nil {
			err = e.(error)
		}
	}()
	if len(b) > 1 {
		return ``, fmt.Errorf(`too many buddyinfo objects`)
	}
	re, err := qq.get(`http://s.web2.qq.com/api/get_friend_uin2?tuin=` +
		uin + `&verifysession=` + qq.verifysession + `&type=1&code=&vfwebqq=` +
		qq.vfwebqq +
		`&t=` + qq.timeStamp())

	if err != nil {
		panic(err)
	}
	defer re.Body.Close()
	j, err := simplejson.NewJson(ReadByte(re.Body))
	if err != nil {
		panic(err)
	}
	acc, err := j.Get(`result`).Get(`account`).Int()
	if err != nil {
		panic(err)
	}
	str = fmt.Sprintf("%d", acc)
	if len(b) == 1 {
		b[0].Id = str
	}
	return
}
Ejemplo n.º 2
0
func (this *PollMessage) IsSessMessage() (ret *SessMessage, is bool) {
	if this.retCode != 0 || this.pollType != PT_SessMessage {
		return nil, false
	}
	js, _ := simplejson.NewJson(this.value)
	ret = new(SessMessage)
	ret.MessageId = int64(js.Get("msg_id").MustFloat64())
	ret.MessageId2 = int64(js.Get("msg_id2").MustFloat64())
	ret.ToUin = fmt.Sprint(int64(js.Get("to_uin").MustFloat64()))
	ret.FromUin = fmt.Sprint(int64(js.Get("from_uin").MustFloat64()))
	ret.MessageType = int64(js.Get("msg_type").MustFloat64())
	ret.ReplyIp = int64(js.Get("admin_uin").MustFloat64())
	ret.Time = time.Unix(int64(js.Get("time").MustFloat64()), 0)
	ret.Id = fmt.Sprint(int64(js.Get("id").MustFloat64()))
	ret.Ruin = fmt.Sprint(int64(js.Get("ruin").MustFloat64()))
	ret.ServiceType = int64(js.Get("service_type").MustFloat64())

	ret.Flags.Text, _ = strconv.ParseBool(fmt.Sprint(js.Get("flags").Get("text").MustInt(1)))
	ret.Flags.Audio, _ = strconv.ParseBool(fmt.Sprint(js.Get("flags").Get("audio").MustInt(1)))
	ret.Flags.File, _ = strconv.ParseBool(fmt.Sprint(js.Get("flags").Get("file").MustInt(1)))
	ret.Flags.Pic, _ = strconv.ParseBool(fmt.Sprint(js.Get("flags").Get("pic").MustInt(1)))
	ret.Flags.Video, _ = strconv.ParseBool(fmt.Sprint(js.Get("flags").Get("video").MustInt(1)))

	ret.Font.Size = js.Get("content").GetIndex(0).GetIndex(1).Get("size").MustInt(15)

	ret.Font.Color = js.Get("content").GetIndex(0).GetIndex(1).Get("color").MustString("000000")
	ret.Font.Name = js.Get("content").GetIndex(0).GetIndex(1).Get("name").MustString("宋体")
	for i := 1; i < len(js.Get("content").MustArray([]interface{}{})); i++ {
		ret.Content = append(ret.Content, fmt.Sprint(js.Get("content").GetIndex(i)))
	}
	return
}
Ejemplo n.º 3
0
func (qq *Client) SendGroupMsg(uin string, msg_id int64, msg, fontname, fontsize, fontcolor string, fontstyle [3]int) (err error) {
	defer func() {
		if e := recover(); e != nil {
			err = e.(error)
		}
		qq.msgid++
	}()
	fmt.Println(qq.msgid)
	v := qq.groupMsgStructer(uin, qq.msgid, msg, fontname, fontsize, fontcolor, fontstyle)
	re, err := qq.postForm(`http://d.web2.qq.com/channel/send_qun_msg2`, v)

	if err != nil {
		panic(err)
	}
	ret, err := simplejson.NewJson(ReadByte(re.Body))
	if err != nil {
		panic(err)
	}
	if i := ret.Get(`retcode`).MustInt(); i == 0 {
		return nil
	} else {
		panic(fmt.Errorf("发送群消息:%v 失败,错误代码:%v", msg, i))
	}
	return
}
Ejemplo n.º 4
0
func (this *PollMessage) IsGroupMessage() (*GroupMessage, bool) {

	if this.retCode != 0 || this.pollType != PT_GroupMessage {
		return nil, false
	}

	js, err := simplejson.NewJson(this.value)
	if err != nil {
		return nil, false
	}
	fromUin := strconv.FormatInt(int64(js.Get(`from_uin`).MustFloat64()), 10)
	toUin := strconv.FormatInt(int64(js.Get(`to_uin`).MustFloat64()), 10)
	msgId := int64(js.Get("msg_id").MustFloat64())
	msgId2 := int64(js.Get("msg_id2").MustFloat64())
	msgType := int64(js.Get("msg_type").MustFloat64())
	replyIp := int64(js.Get("reply_ip").MustFloat64())
	groupCode := strconv.FormatInt(int64(js.Get("group_code").MustFloat64()), 10)
	sendUin := strconv.FormatInt(int64(js.Get("send_uin").MustFloat64()), 10)
	seq := int64(js.Get("seq").MustFloat64())
	infoSeq := int64(js.Get("info_seq").MustFloat64())
	t := time.Unix(int64(js.Get("time").MustFloat64()), 0)
	contentjs := js.Get("content")
	fontjs := contentjs.GetIndex(0).GetIndex(1)
	fontSize := int(fontjs.Get("size").MustFloat64())
	color := fontjs.Get("color").MustString("000000")
	fontName := fontjs.Get("name").MustString("")
	content := []string{}
	for i := 1; i < len(contentjs.MustArray([]interface{}{})); i++ {
		content = append(content, fmt.Sprint(contentjs.GetIndex(i).MustString("不支持文字以外的消息")))

	}

	ret := new(GroupMessage)
	ret.FromUin = fromUin
	ret.ToUin = toUin
	ret.MessageId = msgId
	ret.MessageId2 = msgId2
	ret.MessageType = msgType
	ret.ReplyIp = replyIp
	ret.InfoSeq = infoSeq
	ret.Seq = seq
	ret.SendUin = sendUin
	ret.GroupCode = groupCode
	ret.Time = t
	ret.PollType, _ = this.PollType()
	ret.Font.Color = color
	ret.Font.Name = fontName
	ret.Font.Size = fontSize
	ret.Font.Style = [3]int{0, 0, 0}
	ret.Content = content
	return ret, true

}
Ejemplo n.º 5
0
func (this *PollMessage) IsBuddyStatusChange() (ret *BuddyStatusChange, is bool) {

	if this.retCode != 0 || this.pollType != PT_BuddiesStatusChange {
		return nil, false
	}
	js, err := simplejson.NewJson([]byte(this.value))
	if err != nil {
		return nil, false
	}
	uin := strconv.FormatInt(int64(js.Get(`uin`).MustFloat64()), 10)
	status := js.Get("status").MustString("offline")
	clientType := int(js.Get("client_type").MustFloat64())

	ret = new(BuddyStatusChange)
	ret.Uin = uin
	ret.Status = status
	ret.ClientType = clientType
	return ret, true
}
Ejemplo n.º 6
0
func friendListParser(in []byte) (f *FriendList, err error) {
	js, err := simplejson.NewJson(in)
	if err != nil {
		return nil, err
	}
	f = &FriendList{}
	f.FriendMap = make(FriendMap)
	f.CataMap = make(CataMap)
	result := js.Get(`result`)
	for i, cat := 0, result.Get(`categories`); i < len(cat.MustArray()); i++ {
		f.CataMap[cat.GetIndex(i).Get(`index`).MustInt()] = cat.GetIndex(i).Get(`name`).MustString()
	}
	for i, frd := 0, result.Get(`friends`); i < len(frd.MustArray()); i++ {
		uin := fmt.Sprint(int64(frd.GetIndex(i).Get(`uin`).MustFloat64()))
		categories := frd.GetIndex(i).Get(`categories`).MustInt()
		f.FriendMap[uin] = &Friend{Uin: uin, Categories: categories}
	}
	for i, inf := 0, result.Get(`info`); i < len(inf.MustArray()); i++ {
		uin := fmt.Sprint(int64(inf.GetIndex(i).Get(`uin`).MustFloat64()))
		nick := inf.GetIndex(i).Get(`nick`).MustString()
		face := inf.GetIndex(i).Get(`face`).MustInt()
		flag := inf.GetIndex(i).Get(`flag`).MustInt()
		if ptr, ok := f.FriendMap[uin]; ok {
			ptr.Nick = nick
			ptr.Markname = nick
			ptr.Face = face
			ptr.Online = flag
		}
	}
	for i, mkn := 0, result.Get(`marknames`); i < len(mkn.MustArray()); i++ {
		markname := mkn.GetIndex(i).Get(`markname`).MustString()
		uin := fmt.Sprint(int64(mkn.GetIndex(i).Get(`uin`).MustFloat64()))
		if ptr, ok := f.FriendMap[uin]; ok {
			ptr.Markname = markname
		}
	}
	return
}
Ejemplo n.º 7
0
func (this *PollMessage) IsSysGMessage() (ret *SysGMessage, is bool) {
	if this.retCode != 0 || this.pollType != PT_SysGMessage {
		return nil, false
	}
	ret = new(SysGMessage)
	js, _ := simplejson.NewJson(this.value)
	ret.AdminUin = fmt.Sprint(int64(js.Get("admin_uin").MustFloat64()))
	ret.FromUin = fmt.Sprint(int64(js.Get("from_uin").MustFloat64()))
	ret.Gcode = fmt.Sprint(int64(js.Get("gcode").MustFloat64()))
	ret.Message = js.Get("msg").MustString("")
	ret.MessageId = int64(js.Get("msg_id").MustFloat64())
	ret.MessageId2 = int64(js.Get("msg_id2").MustFloat64())
	ret.MessageType = int64(js.Get("msg_type").MustFloat64())
	ret.ReplyIp = int64(js.Get("admin_uin").MustFloat64())
	ret.TGcode = fmt.Sprint(int64(js.Get("t_gcode").MustFloat64()))
	ret.ToUin = fmt.Sprint(int64(js.Get("to_uin").MustFloat64()))
	ret.Type = js.Get("type").MustString("")
	//{"admin_uin":1.366473281e+09,"from_uin":4.217094352e+09,"gcode":3.762527505e+09,
	//"msg":"","msg_id":32284,"msg_id2":22284,"msg_type":36,"reply_ip":1.76488537e+08,
	//"t_gcode":2.13871351e+08,"to_uin":1.73165159e+08,"type":"group_request_join_agree"}

	return ret, true
}
Ejemplo n.º 8
0
func (qq *Client) LoginStep2(ret LoginRet) (err error) {
	defer func() {
		if e := recover(); e != nil {
			err = e.(error)
		}
	}()

	if ret.p1 == `` {
		lg.Warn("p1 not set")
		return fmt.Errorf(`Please Set Verify Code First`)
	}

	vcl, vcs := ret.gen()

	re, err := qq.get(`https://ssl.ptlogin2.qq.com/login?u=` + qq.id + `&p=` + vcl + `&verifycode=` + vcs + `&webqq_type=10&remember_uin=1&login2qq=1&aid=1003903&u1=http%3A%2F%2Fweb2.qq.com%2Floginproxy.html%3Flogin2qq%3D1%26webqq_type%3D10&h=1&ptredirect=0&ptlang=2052&daid=164&from_ui=1&pttype=1&dumy=&fp=loginerroralert&action=3-29-12615&mibao_css=m_webqq&t=1&g=1&js_type=0&js_ver=10040&login_sig=glCTiV1*UGC58vTwRS3f-xyFDmTfq45dfLQxy2IMjw8BGt1UUldhM9fq2EXdSamn`)
	if err != nil {
		panic(fmt.Errorf("第一次握手失败,网络错误: %v", err))
	}
	defer re.Body.Close()

	sBody := ReadString(re.Body)
	lg.Debug("ptuiCB is %v", sBody)

	reg := regexp.MustCompile(`ptuiCB\('0','0','(.*)','0','登录成功!', '.*'\);`)

	if !reg.MatchString(sBody) {

		panic(errors.New(`第一次握手失败(密码错误?)`))
	}

	ssl := reg.FindStringSubmatch(sBody)
	re, err = qq.get(ssl[1])
	ErrHandle(err, `x`)
	defer re.Body.Close()

	v := url.Values{}
	v.Set(`clientid`, qq.clientid)
	v.Set(`psessionid`, `null`)

	c, err := json.Marshal(
		map[string]interface{}{
			`status`:     `online`,
			`ptwebqq`:    qq.ptwebqq,
			`passwd_sig`: ``,
			`clientid`:   qq.clientid,
			`psessionid`: nil})
	v.Set(`r`, string(c))

	re, err = qq.postForm(`http://d.web2.qq.com/channel/login2`, v)

	if err != nil {
		panic(fmt.Errorf("第二次握手失败:%v", err))
	}
	defer re.Body.Close()

	retb := ReadByte(re.Body)
	lg.Debug("online info is %s", retb)

	js, err := simplejson.NewJson(retb)
	if err != nil {
		panic(err)
	}

	if i := js.Get(`retcode`).MustFloat64(); i != float64(0) {
		panic(fmt.Errorf("第二次握手失败,错误码:%v", i))
	}

	qq.vfwebqq = js.Get(`result`).Get(`vfwebqq`).MustString()
	qq.psessionid = js.Get(`result`).Get(`psessionid`).MustString()
	return nil
}
Ejemplo n.º 9
0
func ParseRawPoll(retu []byte) (ret []*PollMessage, err error) {
	defer func() {
		if e := recover(); e != nil {
			err = e.(error)
		}

	}()
	lg.Debug("parse raw poll: msg is %s", retu)
	js, err := simplejson.NewJson(retu)
	if err != nil {
		panic(fmt.Errorf("parse poll error,%v", err))
	}

	retcode, err := js.Get(`retcode`).Int()

	if err != nil {
		panic(fmt.Errorf("parse poll error,%v", err))
	}

	lg.Debug("ret code is %d", retcode)

	switch retcode {
	case 0:
		{

			result := js.Get(`result`)

			for i := 0; i < len(result.MustArray()); i++ {
				r := new(PollMessage)
				r.retCode = 0
				r.t = time.Now()

				resulti := result.GetIndex(i)

				poll_type := resulti.Get(`poll_type`).MustString("")

				r.value, _ = resulti.Get(`value`).MarshalJSON()

				switch PollType(poll_type) {
				case PT_Message:
					r.pollType = PT_Message
				case PT_SystemMessage:
					r.pollType = PT_SystemMessage
					// switch resulti.Get(`value`).Get(`type`).MustString() {
					// case `added_buddy_sig`:
					// 	{
					// 		t := int64(resulti.Get(`value`).Get(`time`).MustFloat64())
					// 		fuin := strconv.FormatInt(int64(resulti.Get(`value`).Get(`from_uin`).MustFloat64()), 10)
					// 		ret = append(ret, &PollMessage{Type: `addBuddy`, FromUin: fuin, T: time.Unix(t, 0)})
					// 	}
					// }
				case PT_KickMessage:
					r.pollType = PT_KickMessage //您的帐号在另一地点登录,您已被迫下线。
					// ret = append(ret, &PollMessage{Type: `kicked`, FromUin: `10000`, T: time.Now()})
				case PT_GroupMessage:
					r.pollType = PT_GroupMessage
				case PT_InputStatus:
					r.pollType = PT_InputStatus
				case PT_BuddiesStatusChange:
					r.pollType = PT_BuddiesStatusChange
				case PT_Tips:
					r.pollType = PT_Tips
				case PT_InputNotify:
					r.pollType = PT_InputNotify
				case PT_OK:
					r.pollType = PT_OK
				case PT_SysGMessage:
					r.pollType = PT_SysGMessage
				case PT_GroupWebMessage:
					r.pollType = PT_GroupWebMessage
				case PT_BuddylistChange:
					r.pollType = PT_BuddylistChange
				case PT_DiscuMessage:
					r.pollType = PT_DiscuMessage
				case PT_SessMessage:
					r.pollType = PT_SessMessage
				default:
					lg.Critical("doesn't expected poll type", poll_type)
				}
				ret = append(ret, r)
			}
		}
	case 102:
		{
			r := new(PollMessage)
			r.retCode = 102
			r.t = time.Now()
			r.errMsg = js.Get("errmsg").MustString("")
			ret = append(ret, r)
		}
	case 116:
		{

			p := js.Get("p").MustString("")

			r := new(PollMessage)
			r.retCode = 116
			r.t = time.Now()
			r.value = []byte(p)
			ret = append(ret, r)
		}
	case 103:
		{
			r := new(PollMessage)
			r.retCode = 103
			r.t = time.Now()
			r.errMsg = js.Get("errmsg").MustString("")
			ret = append(ret, r)
		}
	case 121:
		{
			r := new(PollMessage)
			r.retCode = 121
			r.t = time.Now()
			r.errMsg = js.Get("errmsg").MustString("")
			ret = append(ret, r)
		}
	case 100006:
		{
			r := new(PollMessage)
			r.retCode = 100006
			r.t = time.Now()
			r.errMsg = js.Get("errmsg").MustString("")
			ret = append(ret, r)
		}
	case 108:
		{
			r := new(PollMessage)
			r.retCode = 108
			r.t = time.Now()
			r.errMsg = js.Get("errmsg").MustString("")
			ret = append(ret, r)
		}
	case 112:
		{
			r := new(PollMessage)
			r.retCode = 112
			r.t = time.Now()
			r.errMsg = js.Get("errmsg").MustString("")
			ret = append(ret, r)
		}
	default:
		{
			err = fmt.Errorf("unknown ret code:%v", retcode)
		}
	}
	return
}