Esempio n. 1
0
func GetFid(forumName string) (uint64, error, *postbar.PbError) {
	var parameters simple_http.Parameters
	parameters.Add("fname", misc.ToGBK(forumName))
	resp, err := simple_http.Post(`http://tieba.baidu.com/f/commit/share/fnameShareApi`, parameters)

	if err != nil {
		return 0, err, nil
	}

	var x struct {
		ErrorNo  int    `json:"no"`
		ErrorMsg string `json:"error"`
		Data     struct {
			Fid uint64 `json:"fid"`
		} `json:"data"`
	}

	if x.ErrorNo != 0 {
		return 0, nil, postbar.NewPbError(x.ErrorNo, x.ErrorMsg)
	}

	json.Unmarshal(resp, &x)

	return x.Data.Fid, nil, nil

}
Esempio n. 2
0
func GetAdvSearchResultPage(kw, un string, rn int, pn int) (string, error) {
	//120字符,不算上"回复:"
	var parameters simple_http.Parameters

	//parameters.Add("ie", "utf-8")
	parameters.Add("ie", "gbk")

	parameters.Add("kw", misc.ToGBK(kw))
	parameters.Add("rn", strconv.Itoa(rn))
	parameters.Add("un", misc.ToGBK(un))
	parameters.Add("sm", "1")
	if pn != 1 {
		parameters.Add("pn", strconv.Itoa(pn))
	}

	resp, err := simple_http.Get(`http://tieba.baidu.com/f/search/ures`, parameters, nil)
	if err != nil {
		return "", err
	}

	return string(resp), nil
}
Esempio n. 3
0
func HasWrongUserJson(userName string) (bool, error) {
	var parameters simple_http.Parameters
	parameters.Add("un", misc.UrlQueryEscape(misc.ToGBK(userName)))
	resp, err := simple_http.Get("http://tieba.baidu.com/i/sys/user_json", parameters, nil)
	if err != nil {
		return false, err
	}

	var x struct {
		RawName string `json:"raw_name"`
	}

	err2 := json.Unmarshal(resp, &x)

	if err2 != nil {
		return false, err2
	}

	return x.RawName == "", nil
}
Esempio n. 4
0
func GetUid(userName string) (uint64, error) { //忠于百度的写法,用Get取
	var parameters simple_http.Parameters
	parameters.Add("un", misc.UrlQueryEscape(misc.ToGBK(userName)))
	resp, err := simple_http.Get("http://tieba.baidu.com/i/sys/user_json", parameters, nil)
	//println(string(resp))
	if err != nil {
		return 0, err
	}

	var x struct {
		Creator struct {
			ID uint64 `json:"id"`
		} `json:"creator"`
	}

	err2 := json.Unmarshal(resp, &x)

	if err2 != nil {
		return 0, err2
	}

	return x.Creator.ID, nil

}