Exemplo n.º 1
0
/*
映射端口

POST /ipc HTTP/1.1
HOST: 192.168.1.253:1900
Content-Type: text/xml; charset="utf-8"
Content-Length: 615
SOAPACTION: "urn:schemas-upnp-org:service:WANIPConnection:1#AddPortMapping"

<?xml version="1.0"?>
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<s:Body>
<u:AddPortMapping xmlns:u="urn:schemas-upnp-org:service:WANIPConnection:1">
<NewRemoteHost></NewRemoteHost>
<NewExternalPort>5678</NewExternalPort>
<NewProtocol>TCP</NewProtocol>
<NewInternalPort>3389</NewInternalPort>
<NewInternalClient>192.168.1.100</NewInternalClient>
<NewEnabled>1</NewEnabled>
<NewPortMappingDescription>xxxxxxxx</NewPortMappingDescription>
<NewLeaseDuration>0</NewLeaseDuration>
</u:AddPortMapping>
</s:Body>
</s:Envelope>
*/
func (this *UPnPService) Link(v *AddPortMapping) (err error) {
	server_url := "http://" + this.ServerHost + "/ipc"
	util.DEBUG.Logf("linking %s : %+v", server_url, v)
	buf := bytes.NewBufferString("<?xml version=\"1.0\"?>\r\n")
	buf.WriteString("<s:Envelope xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\" s:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\">\r\n")
	buf.WriteString("<s:Body>\r\n")
	buf.WriteString("<u:AddPortMapping xmlns:u=\"urn:schemas-upnp-org:service:WANIPConnection:1\">\r\n")
	buf.WriteString("<NewRemoteHost>")
	xml.Escape(buf, []byte(v.NewRemoteHost))
	buf.WriteString("</NewRemoteHost>\r\n")
	buf.WriteString("<NewExternalPort>" + util.ToString(v.NewExternalPort) + "</NewExternalPort>\r\n")
	buf.WriteString("<NewProtocol>")
	xml.Escape(buf, []byte(v.NewProtocol))
	buf.WriteString("</NewProtocol>\r\n")
	buf.WriteString("<NewInternalPort>" + util.ToString(v.NewInternalPort) + "</NewInternalPort>\r\n")
	buf.WriteString("<NewInternalClient>")
	xml.Escape(buf, []byte(v.NewInternalClient))
	buf.WriteString("</NewInternalClient>\r\n")
	buf.WriteString("<NewEnabled>" + util.ToString(v.NewEnabled) + "</NewEnabled>\r\n")
	buf.WriteString("<NewPortMappingDescription>")
	xml.Escape(buf, []byte(v.NewPortMappingDescription))
	buf.WriteString("</NewPortMappingDescription>\r\n")
	buf.WriteString("<NewLeaseDuration>" + util.ToString(v.NewLeaseDuration) + "</NewLeaseDuration>\r\n")
	buf.WriteString("</u:AddPortMapping>\r\n</s:Body>\r\n</s:Envelope>\r\n\r\n")
	res, err := http.Post(server_url, "text/xml", buf)
	if err != nil {
		return
	}
	defer res.Body.Close()
	b, err := ioutil.ReadAll(res.Body)
	util.DEBUG.Log("\n[response]\n", string(b))
	return
}
Exemplo n.º 2
0
func (this *TargetQQWeibo) Send(src *source.FeedInfo) (rid string, e error) {
	util.DEBUG.Logf("QQWeibo.Send(%v:%v,repost_id:%v,title:%v,content:%v,picurl:%v)", src.SourceId, src.Id, src.RepostId, src.Title, src.Content, src.PicUrl)
	if src.RepostId != "" {
		r, err := this.Repost(src.Content, src.RepostId)
		if err != nil {
			e = err
			return
		}
		util.INFO.Logf("[qq.%v] Repost sent: %v", this.Name, r.Url())
		return util.ToString(r.Id), nil
	} else if src.PicUrl != nil && len(src.PicUrl) > 0 {
		r, err := this.UploadUrl(src.Content, src.PicUrl[0])
		if err != nil {
			e = err
			return
		}
		util.INFO.Logf("[qq.%v] UploadUrl sent: %v", this.Name, r.Url())
		return util.ToString(r.Id), nil
	} else {
		r, err := this.Update(src.Content)
		if err != nil {
			e = err
			return
		}
		util.INFO.Logf("[qq.%v] Update sent: %v", this.Name, r.Url())
		return util.ToString(r.Id), nil
	}
	return
}
Exemplo n.º 3
0
// 上传离线图片
func (this *WebQQ) UploadOfflinePic(peeruin Uin, pic io.Reader) (v *ResultOfflinePic, err error) {
	form := &bytes.Buffer{}
	formdata := multipart.NewWriter(form)
	formdata.WriteField("callback", "parent.EQQ.Model.ChatMsg.callbackSendPic")
	formdata.WriteField("locallangid", "2052")
	formdata.WriteField("clientversion", "1409")
	formdata.WriteField("uin", this.id_str)
	formdata.WriteField("skey", this.getCookie(util.MustParseUrl(_OFFLINE_UPLOAD_URL), "skey"))
	formdata.WriteField("appid", _WEBQQ_APPID)
	formdata.WriteField("peeruin", peeruin.String())
	formdata.WriteField("vfwebqq", this.vfwebqq)
	formdata.WriteField("fileid", util.ToString(fileid))
	formdata.WriteField("senderviplevel", "0")
	formdata.WriteField("reciverviplevel", "0")
	fileid++
	picdata, _ := formdata.CreateFormFile("file", "1.png")
	io.Copy(picdata, pic)
	formdata.Close()
	res, err := this.client.Post(_CFACE_UPLOAD_URL+"?time="+util.JsCurrentTime(), formdata.FormDataContentType(), form)
	if err != nil {
		return
	}
	defer res.Body.Close()
	b, err := ioutil.ReadAll(res.Body)
	if err != nil {
		return
	}
	sb := offlinePatten.FindStringSubmatch(string(b))
	if len(sb) > 1 {
		v = &ResultOfflinePic{}
		json.Unmarshal([]byte(sb[1]), v)
	}
	return
}
Exemplo n.º 4
0
// 上传自定义表情
func (this *WebQQ) UploadCustomFace(pic io.Reader) (v string, err error) {
	form := &bytes.Buffer{}
	formdata := multipart.NewWriter(form)
	formdata.WriteField("from", "control")
	formdata.WriteField("f", "EQQ.Model.ChatMsg.callbackSendPicGroup")
	formdata.WriteField("vfwebqq", this.vfwebqq)
	formdata.WriteField("fileid", util.ToString(fileid))
	fileid++
	picdata, _ := formdata.CreateFormFile("custom_face", "1.png")
	io.Copy(picdata, pic)
	formdata.Close()
	res, err := this.client.Post(_CFACE_UPLOAD_URL+"?time="+util.JsCurrentTime(), formdata.FormDataContentType(), form)
	if err != nil {
		return
	}
	defer res.Body.Close()
	b, err := ioutil.ReadAll(res.Body)
	if err != nil {
		return
	}
	sb := cfacePatten.FindStringSubmatch(string(b))
	if len(sb) > 1 {
		v = sb[1]
	}
	return
}
Exemplo n.º 5
0
func (this *TargetSinaWeibo) Send(src *source.FeedInfo) (rid string, e error) {
	util.DEBUG.Logf("SinaWeibo.Send(%v:%v,repost_id:%v,title:%v,content:%v,picurl:%v)", src.SourceId, src.Id, src.RepostId, src.Title, src.Content, src.PicUrl)
	if src.RepostId != "" {
		r, err := this.Repost(src.Content, src.RepostId)
		if err != nil {
			e = err
			return
		}
		util.INFO.Log("[sina."+this.Name+"] Repost sent:", r.Url())
		return util.ToString(r.Id), nil
	} else if src.PicUrl != nil && len(src.PicUrl) > 0 {
		if this.EnableUploadUrl {
			r, err := this.UploadUrl(src.Content, src.PicUrl[0])
			if err != nil {
				e = err
				return
			}
			util.INFO.Log("[sina.%s] UploadUrl sent: %v", this.Name, r.Url())
			return util.ToString(r.Id), nil
		} else {
			pic := util.FetchImageAsStream(src.PicUrl[0])
			r, err := this.Upload(src.Content, pic)
			if err != nil {
				e = err
				return
			}
			util.INFO.Log("[sina.%s] Upload sent: %v", this.Name, r.Url())
			return util.ToString(r.Id), nil
		}
	} else {
		r, err := this.Update(src.Content)
		if err != nil {
			e = err
			return
		}
		util.INFO.Log("Update sent:", r.Url())
		return util.ToString(r.Id), nil
	}
	return
}