Beispiel #1
0
func (this *PrePackModule) gencommonurl(ad *context.AdInfo, inner_data *context.Context, urltype jesgoo_protocol.Event_Body_EventType) (url string, err error) {
	var event_head jesgoo_protocol.Event_Head
	event_head.CryptoType = new(jesgoo_protocol.Event_Head_CryptoType)
	*event_head.CryptoType = jesgoo_protocol.Event_Head_JESGOO_BASE64
	event_head.CryptoParam = new(uint32)
	*event_head.CryptoParam = uint32(rand.Intn(len(this.coder)))
	coder := this.coder[*event_head.CryptoParam]
	var event_body jesgoo_protocol.Event_Body
	event_body.Type = new(jesgoo_protocol.Event_Body_EventType)
	*event_body.Type = urltype
	event_body.SearchId = new(string)
	*event_body.SearchId = inner_data.Searchid
	event_body.SearchTimestamp = new(uint32)
	*event_body.SearchTimestamp = uint32(time.Now().Unix())
	event_body.SearchIp = new(uint32)
	*event_body.SearchIp = inner_data.Req.Network.Ipint
	event_body.Media = new(jesgoo_protocol.Event_Body_Media)
	event_body.Media.MediaId = new(string)
	event_body.Media.ChannelId = new(string)
	*event_body.Media.MediaId = inner_data.Req.Media.Appsid
	*event_body.Media.ChannelId = inner_data.Req.Media.ChannelId
	event_body.Media.PackageName = new(string)
	*event_body.Media.PackageName = inner_data.Req.Media.App.PackageName

	event_body.Ad = new(jesgoo_protocol.Event_Body_Ad)
	event_body.Ad.UserId = new(uint32)
	*event_body.Ad.UserId = uint32(ad.Userid)
	event_body.Ad.PlanId = new(uint32)
	*event_body.Ad.PlanId = uint32(ad.Planid)
	event_body.Ad.GroupId = new(uint32)
	*event_body.Ad.GroupId = uint32(ad.Groupid)
	event_body.Ad.UnitId = new(uint32)
	*event_body.Ad.UnitId = uint32(ad.Adid)
	event_body.Charge = new(jesgoo_protocol.Event_Body_Charge)
	event_body.Charge.Type = new(jesgoo_protocol.ChargeType)
	*event_body.Charge.Type = jesgoo_protocol.ChargeType_CPC
	event_body.Charge.Price = new(uint32)
	*event_body.Charge.Price = uint32(ad.Price)
	//	event_body.Dsp = new(jesgoo_protocol.Dsp)
	event_body.DspInfo = new(jesgoo_protocol.DspInfo)
	dspinfo := event_body.DspInfo
	dspinfo.Dsp = new(jesgoo_protocol.Dsp)
	dsp := dspinfo.Dsp
	switch ad.AdSrc {
	case context.AdSrc_JESGOO:
		*dsp = jesgoo_protocol.Dsp_JESGOO_DSP
	case context.AdSrc_BAIDU:
		*dsp = jesgoo_protocol.Dsp_BAIDU_DSP
	default:
		*dsp = jesgoo_protocol.Dsp_JESGOO_DSP
	}
	dspinfo.MediaId = new(string)
	*dspinfo.MediaId = ad.DspMediaid

	event_body.Debug = new(bool)
	*event_body.Debug = inner_data.Req.Debug

	var head_enc []byte
	head_enc, err = proto.Marshal(&event_head)
	if err != nil {
		utils.WarningLog.Write("marshal click_head fail")
		return
	}
	head_str := this.basecoder.EncodeToString(head_enc)

	var body_enc []byte
	body_enc, err = proto.Marshal(&event_body)
	if err != nil {
		utils.WarningLog.Write("marshal click_body fail")
		return
	}

	body_str := coder.EncodeToString(body_enc)
	url = this.common_head + strings.Replace(head_str, "=", "", -1) + "." + strings.Replace(body_str, "=", "", -1)
	utils.DebugLog.Write("common url is [%s]", url)

	return
}
Beispiel #2
0
func (this *PrePackModule) genwinnotice(ad *context.AdInfo, inner_data *context.Context) (winnotice string, err error) {
	var event_head jesgoo_protocol.Event_Head
	event_head.CryptoType = new(jesgoo_protocol.Event_Head_CryptoType)
	*event_head.CryptoType = jesgoo_protocol.Event_Head_JESGOO_BASE64
	event_head.CryptoParam = new(uint32)
	*event_head.CryptoParam = uint32(rand.Intn(len(this.coder)))
	coder := this.coder[*event_head.CryptoParam]
	var event_body jesgoo_protocol.Event_Body
	event_body.Type = new(jesgoo_protocol.Event_Body_EventType)
	*event_body.Type = jesgoo_protocol.Event_Body_IMPRESSION
	event_body.SearchId = new(string)
	*event_body.SearchId = inner_data.Searchid
	event_body.SearchTimestamp = new(uint32)
	*event_body.SearchTimestamp = uint32(time.Now().Unix())
	event_body.SearchIp = new(uint32)
	*event_body.SearchIp = inner_data.Req.Network.Ipint
	event_body.Media = new(jesgoo_protocol.Event_Body_Media)
	event_body.Media.MediaId = new(string)
	event_body.Media.ChannelId = new(string)
	*event_body.Media.MediaId = inner_data.Req.Media.Appsid
	*event_body.Media.ChannelId = inner_data.Req.Media.ChannelId
	event_body.Media.PackageName = new(string)
	*event_body.Media.PackageName = inner_data.Req.Media.App.PackageName
	event_body.Media.AdslotId = new(string)
	*event_body.Media.AdslotId = inner_data.Req.AdSlot.Slotid
	event_body.Media.AdslotType = new(jesgoo_protocol.Event_Body_AdslotType)
	switch inner_data.Req.AdSlot.AdSlotType {
	case context.AdSlotType_BANNER:
		*event_body.Media.AdslotType = jesgoo_protocol.Event_Body_BANNER
	case context.AdSlotType_OFFERWALL:
		*event_body.Media.AdslotType = jesgoo_protocol.Event_Body_OFFERWALL
	case context.AdSlotType_RECOMMEND:
		*event_body.Media.AdslotType = jesgoo_protocol.Event_Body_RECOMMEND
	case context.AdSlotType_INITIALIZATION:
		*event_body.Media.AdslotType = jesgoo_protocol.Event_Body_INITIALIZATION
	default:
		*event_body.Media.AdslotType = jesgoo_protocol.Event_Body_BANNER
	}

	event_body.Region = new(jesgoo_protocol.Event_Body_Region)
	event_body.Region.Country = new(uint32)
	event_body.Region.Province = new(uint32)
	event_body.Region.City = new(uint32)
	*event_body.Region.Country = inner_data.Req.Location.Country
	*event_body.Region.Province = inner_data.Req.Location.Province
	*event_body.Region.City = inner_data.Req.Location.City
	//	event_body.Region = new(jesgoo_protocol.Event_Body_Region)
	event_body.Ad = new(jesgoo_protocol.Event_Body_Ad)
	event_body.Ad.UserId = new(uint32)
	*event_body.Ad.UserId = uint32(ad.Userid)
	event_body.Ad.PlanId = new(uint32)
	*event_body.Ad.PlanId = uint32(ad.Planid)
	event_body.Ad.GroupId = new(uint32)
	*event_body.Ad.GroupId = uint32(ad.Groupid)
	event_body.Ad.UnitId = new(uint32)
	*event_body.Ad.UnitId = uint32(ad.Adid)
	event_body.Charge = new(jesgoo_protocol.Event_Body_Charge)
	event_body.Charge.Type = new(jesgoo_protocol.ChargeType)
	*event_body.Charge.Type = jesgoo_protocol.ChargeType_CPC
	event_body.Charge.Price = new(uint32)
	*event_body.Charge.Price = uint32(ad.Price)
	//	event_body.Action = new(jesgoo_protocol.Event_Body_Action)
	//	event_body.Action.TargetUrl = new(string)
	//	*event_body.Action.TargetUrl = ad.ClickUrl

	//	event_body.Dsp = new(jesgoo_protocol.Dsp)

	event_body.DspInfo = new(jesgoo_protocol.DspInfo)
	dspinfo := event_body.DspInfo
	dspinfo.Dsp = new(jesgoo_protocol.Dsp)
	dsp := dspinfo.Dsp
	switch ad.AdSrc {
	case context.AdSrc_JESGOO:
		*dsp = jesgoo_protocol.Dsp_JESGOO_DSP
	case context.AdSrc_BAIDU:
		*dsp = jesgoo_protocol.Dsp_BAIDU_DSP
	default:
		*dsp = jesgoo_protocol.Dsp_JESGOO_DSP
	}
	dspinfo.MediaId = new(string)
	*dspinfo.MediaId = ad.DspMediaid

	event_body.Debug = new(bool)
	*event_body.Debug = inner_data.Req.Debug

	var head_enc []byte
	head_enc, err = proto.Marshal(&event_head)
	if err != nil {
		utils.WarningLog.Write("marshal click_head fail")
		return
	}
	head_str := this.basecoder.EncodeToString(head_enc)

	var body_enc []byte
	body_enc, err = proto.Marshal(&event_body)
	if err != nil {
		utils.WarningLog.Write("marshal click_body fail")
		return
	}
	body_str := coder.EncodeToString(body_enc)
	winnotice = this.win_head + strings.Replace(head_str, "=", "", -1) + "." + strings.Replace(body_str, "=", "", -1)
	return
}