コード例 #1
0
ファイル: bcms.go プロジェクト: heartszhang/famous
func (this bcms_queue) FetchAny(msgid, fetch_num *uint) ([]string, error) {
	v := make([]string, 0)
	var err error
	q := bcms_fetch{
		bcms_common: bcms_common{
			method:       "fetch",
			timestamp:    unix_current(),
			access_token: this.access_token,
			client_id:    this.client_id,
		},
		msg_id:    msgid,
		fetch_num: fetch_num,
	}

	var bcmsr struct {
		RequestId int64        `json:"request_id"`
		Response  BcmsResponse `json:"response_params"`
	}
	uri := bcms_urlbase + this.queue_name
	q.sign = bcms_sign("POST", uri, q, this.client_secret) // use client_secret to sign post-params
	vals := oauth2.HttpQueryValues(q)
	c := curl.NewCurlerDetail("", curl.CurlProxyPolicyNoProxy, 0, nil, nil)
	err = c.PostFormAsJson(uri, vals, &bcmsr)

	if err == nil {
		for _, i := range bcmsr.Response.Messages {
			v = append(v, i.Message)
		}
	}
	return v, err
}
コード例 #2
0
ファイル: pubsub.go プロジェクト: heartszhang/famous
func (this pubsuber) Unsubscribe(uri string) (int, error) {
	p := pubunsub_param{
		mode:     "unsubscribe",
		topic:    uri,
		callback: hub_callback,
		verify:   &this.verify,
	}
	c := curl.NewCurlerDetail("", this.proxy_policy, 0, nil, nil)
	resp, err := c.PostForm(this.service_provider, oauth2.HttpQueryValues(p))
	return resp, err
}
コード例 #3
0
ファイル: bcms.go プロジェクト: heartszhang/famous
func bcms_sign(method, uri string, params interface{}, client_secret string) string {
	vals := oauth2.HttpQueryValues(params)
	keys := sortedkeys_from_map(vals)
	var t []string
	for _, i := range keys {
		val := vals[i]
		for _, j := range val {
			t = append(t, fmt.Sprintf("%v=%v", i, j))
		}
	}
	q := fmt.Sprintf("%v %v%v%v", method, uri, strings.Join(t, "&"), client_secret)
	q = url.QueryEscape(q)
	h := md5.New()
	io.WriteString(h, q)
	sign := fmt.Sprintf("%x", h.Sum(nil))
	return sign
}