Exemple #1
0
func CallBack(resp http.ResponseWriter, req *http.Request) {

	reqbody, err := ioutil.ReadAll(req.Body)
	var temp_req mobads_api.BidRequest
	err = proto.Unmarshal(reqbody, &temp_req)

	var title string
	var desc string
	switch *temp_req.App.Id {
	case "10042c1f":
		title = "I am Banner ad title"
		desc = "I am Banner ad desc"
	case "10044934":
		title = "I am kaiping ad title"
		desc = "I am kaiping ad desc"
	case "10044933":
		title = "I am chaping ad title"
		desc = "I am chaping ad desc"

	}

	var temp_ans mobads_api.BidResponse
	temp_ans.RequestId = new(string)
	*temp_ans.RequestId = "aaaaaa"
	temp_ans.Ads = make([]*mobads_api.Ad, 0)
	var ad *mobads_api.Ad
	ad = new(mobads_api.Ad)
	ad.AdslotId = new(string)
	*ad.AdslotId = "123"
	ad.MaterialMeta = new(mobads_api.Ad_MaterialMeta)
	material := ad.MaterialMeta
	material.CreativeType = new(mobads_api.CreativeType)
	//	*material.CreativeType = mobads_api.CreativeType_IMAGE
	*material.CreativeType = mobads_api.CreativeType_TEXT
	material.InteractionType = new(mobads_api.InteractionType)
	*material.InteractionType = mobads_api.InteractionType_DOWNLOAD
	material.Title = new(string)
	*material.Title = title
	material.Description1 = new(string)
	*material.Description1 = desc
	material.WinNoticeUrl = make([]string, 0)
	material.WinNoticeUrl = append(material.WinNoticeUrl, "http://192.168.1.5:8123/a.gif")
	material.MediaUrl = new(string)
	*material.MediaUrl = "http://192.168.1.5:8123/image/splash.png"
	material.ClickUrl = new(string)
	*material.ClickUrl = "http://smallkoo.wicp.net:8123/pkg/ditiepaoku_64.apk"
	temp_ans.Ads = append(temp_ans.Ads, ad)

	buf, err := proto.Marshal(&temp_ans)
	if err != nil {
		log.Printf("serialize fail . err[%s]", err.Error())
	}

	resp.Write(buf)

	return
}
Exemple #2
0
func (this *ReqQiushiModule) parse_resp(response *mobads_api.BidResponse, adtype AdType, inner_ads *[]context.AdInfo, bd_appsid string) (err error) {
	utils.DebugLog.Write("baidu_response [%s]", response.String())
	if response.ErrorCode != nil {
		utils.WarningLog.Write("request qiushi fail . error_code is %u", *response.ErrorCode)
		errstr := fmt.Sprintf("request qiushi fail . errcode[%d]", *response.ErrorCode)
		err = errors.New(errstr)
		return
	}
	for i := 0; i < len(response.Ads); i++ {
		var inner_ad context.AdInfo
		inner_ad.MaterialReady = true
		err = this.convert_ad(&inner_ad, adtype, response.Ads[i], bd_appsid)
		if err != nil {
			continue
		}
		*inner_ads = append(*inner_ads, inner_ad)
	}
	return
}