Пример #1
0
func (this ParseJesgooRequestModule) Run(inner_data *context.Context) (err error) {
	var temp_req jesgoo_interface.SellerRequest
	err = proto.Unmarshal(inner_data.ReqBody, &temp_req)
	if err != nil {
		utils.WarningLog.Write("deseriallize jesgoo proto request fail [%s]", err.Error())
	}
	var inner_req *context.InnerReq
	inner_req = &inner_data.Req

	//media
	inner_media := &inner_req.Media
	if temp_req.Media == nil {
		err = errors.New("request media is null")
		return
	}
	if temp_req.Media.Id == nil || temp_req.Media.ChannelId == nil || temp_req.Media.Type == nil {
		err = errors.New("request media.id or media.channelid is nil")
		return
	}
	inner_media.Appsid = *temp_req.Media.Id
	inner_media.ChannelId = *temp_req.Media.ChannelId
	switch *temp_req.Media.Type {
	case jesgoo_interface.MediaType_APP:
		inner_media.MediaType = context.MediaType_APP
	case jesgoo_interface.MediaType_WAP:
		inner_media.MediaType = context.MediaType_WAP
	case jesgoo_interface.MediaType_WEB:
		inner_media.MediaType = context.MediaType_WEB
	default:
		inner_media.MediaType = context.MediaType_APP
	}
	if temp_req.Media.App != nil {
		inner_req.Media.App.PackageName = *temp_req.Media.App.PackageName
	}

	//device
	inner_device := &inner_req.Device
	if temp_req.Device != nil {
		if temp_req.Device.OsType != nil {
			switch *temp_req.Device.OsType {
			case jesgoo_interface.OSType_ANDROID:
				inner_device.OSType = context.OSType_ANDROID
			case jesgoo_interface.OSType_IOS:
				inner_device.OSType = context.OSType_IOS
			case jesgoo_interface.OSType_WP:
				inner_device.OSType = context.OSType_WP
			default:
				inner_device.OSType = context.OSType_UNKNOWN
			}
		}
		if len(temp_req.Device.Ids) > 0 {
			var device_id context.DeviceID
			switch *temp_req.Device.Ids[0].Type {
			case jesgoo_interface.DeviceIDType_IMEI:
				device_id.DevIDType = context.DeviceIDType_IMEI
			case jesgoo_interface.DeviceIDType_MAC:
				device_id.DevIDType = context.DeviceIDType_MAC
			case jesgoo_interface.DeviceIDType_IDFA:
				device_id.DevIDType = context.DeviceIDType_IDFA
			default:
				device_id.DevIDType = context.DeviceIDType_IMEI
			}
			device_id.ID = string(temp_req.Device.Ids[0].Id)
			inner_device.DevID = append(inner_device.DevID, device_id)
		}
	}

	//network
	inner_network := &inner_req.Network
	if temp_req.Network != nil {
		if temp_req.Network.Ip != nil {
			inner_network.Ip = *temp_req.Network.Ip
		}
		if temp_req.Network.Type != nil {
			switch *temp_req.Network.Type {
			case jesgoo_interface.NetworkType_WIFI:
				inner_network.NetworkType = context.NetworkType_WIFI
			case jesgoo_interface.NetworkType_CELLULAR_UNKNOWN:
				inner_network.NetworkType = context.NetworkType_UNKNOWN
			case jesgoo_interface.NetworkType_CELLULAR_2G:
				inner_network.NetworkType = context.NetworkType_2G
			case jesgoo_interface.NetworkType_CELLULAR_3G:
				inner_network.NetworkType = context.NetworkType_3G
			case jesgoo_interface.NetworkType_CELLULAR_4G:
				inner_network.NetworkType = context.NetworkType_4G
			default:
				inner_network.NetworkType = context.NetworkType_UNKNOWN
			}
		}
	}

	//adslot
	if len(temp_req.Adslots) > 0 {
		inner_adslot := &inner_req.AdSlot
		temp_adslot := *temp_req.Adslots[0]
		if temp_adslot.Id != nil {
			inner_adslot.Slotid = *temp_adslot.Id
		} else {
			inner_adslot.Slotid = "0"
		}
		if temp_adslot.Type != nil {
			switch *temp_adslot.Type {
			case jesgoo_interface.AdSlotType_BANNER:
				inner_adslot.AdSlotType = context.AdSlotType_BANNER
			case jesgoo_interface.AdSlotType_OFFERWALL:
				inner_adslot.AdSlotType = context.AdSlotType_OFFERWALL
			case jesgoo_interface.AdSlotType_RECOMMEND:
				inner_adslot.AdSlotType = context.AdSlotType_RECOMMEND
			case jesgoo_interface.AdSlotType_INTERSTITIAL:
				inner_adslot.AdSlotType = context.AdSlotType_INSERT
			case jesgoo_interface.AdSlotType_REALTIME_SPLASH:
				inner_adslot.AdSlotType = context.AdSlotType_INITIALIZATION
			default:
				inner_adslot.AdSlotType = context.AdSlotType_BANNER
			}
		} else {
			inner_adslot.AdSlotType = context.AdSlotType_BANNER
		}
		if temp_adslot.Capacity != nil {
			inner_adslot.Capacity = *temp_adslot.Capacity
		} else {
			inner_adslot.Capacity = 1
		}
	} else {
		err = errors.New("no adslot in request")
		return
	}

	//is debug request
	inner_data.Req.Debug = false
	if temp_req.Debug != nil {
		inner_data.Req.Debug = *temp_req.Debug
	}

	//searchid
	if len(inner_data.Req.Device.DevID) > 0 {
		inner_data.Searchid = utils.GenSearchid(inner_data.Req.Device.DevID[0].ID)
	} else {
		inner_data.Searchid = utils.GenSearchid("default")
	}

	return
}
Пример #2
0
func (this *ParseJesgooJsonRequestModule) parse(inner_data *context.Context) (err error) {

	var temp_req SellerRequest
	err = json.Unmarshal(inner_data.ReqBody, &temp_req)
	if err != nil {
		utils.WarningLog.Write("deserialized jesgoo json fail [%s] [%s]", err.Error(), inner_data.ReqBody)
		return
	}
	utils.DebugLog.Write("json request [%s]", temp_req)

	// media
	inner_media := &inner_data.Req.Media
	inner_media.Appsid = temp_req.Media.Id
	inner_media.ChannelId = temp_req.Media.Channel_id
	switch temp_req.Media.Type {
	case 1:
		inner_media.MediaType = context.MediaType_APP
	case 2:
		inner_media.MediaType = context.MediaType_WEB
	case 3:
		inner_media.MediaType = context.MediaType_WAP
	default:
		inner_media.MediaType = context.MediaType_WAP
	}
	//	inner_media.App.PackageName = temp_req.Media.App.Package_name

	//client
	inner_client := &inner_data.Req.Client
	temp_req_client := &temp_req.Client
	if temp_req_client == nil {
		utils.DebugLog.Write("request has no client info")
		inner_client.Type = context.ClientType_OPENAPI
	} else {
		switch temp_req_client.Type {
		case 1:
			inner_client.Type = context.ClientType_NATIVESDK
		case 2:
			inner_client.Type = context.ClientType_JSSDK
		case 3:
			inner_client.Type = context.ClientType_OPENAPI
		default:
			inner_client.Type = context.ClientType_OPENAPI
		}
		inner_client.Version.Major = temp_req_client.Version.Major
		inner_client.Version.Minor = temp_req_client.Version.Minor
		inner_client.Version.Micro = temp_req_client.Version.Micro
		inner_client.Version.Build = temp_req_client.Version.Build
		utils.DebugLog.Write("Major is %d", inner_client.Version.Major)
	}

	//device
	inner_device := &inner_data.Req.Device
	temp_req_device := &temp_req.Device
	if temp_req_device == nil {
		utils.DebugLog.Write("request has no device")
	} else {
		switch temp_req_device.Os_type {
		case 1:
			inner_device.OSType = context.OSType_ANDROID
		case 2:
			inner_device.OSType = context.OSType_IOS
		case 3:
			inner_device.OSType = context.OSType_WP
		default:
			inner_device.OSType = context.OSType_UNKNOWN
		}
		inner_device.OSVersion.Major = temp_req_device.Os_version.Major
		inner_device.OSVersion.Minor = temp_req_device.Os_version.Minor
		inner_device.OSVersion.Micro = temp_req_device.Os_version.Micro
		inner_device.Brand = temp_req_device.Brand
		inner_device.Model = temp_req_device.Model
		if temp_req_device.Ids != nil {
			var device_id DeviceId
			for i := 0; i < len(temp_req_device.Ids); i++ {
				device_id = temp_req_device.Ids[i]
				var inner_device_id context.DeviceID
				switch device_id.Type {
				case 1:
					inner_device_id.DevIDType = context.DeviceIDType_IMEI
				case 2:
					inner_device_id.DevIDType = context.DeviceIDType_MAC
				case 3:
					inner_device_id.DevIDType = context.DeviceIDType_IDFA
				case 4:
					inner_device_id.DevIDType = context.DeviceIDType_AAID
				default:
					inner_device_id.DevIDType = context.DeviceIDType_IMEI
				}
				inner_device_id.ID = device_id.Id
				inner_device.DevID = append(inner_device.DevID, inner_device_id)
			}
		}

		//network
		temp_req_network := &temp_req.Network
		if temp_req_network == nil {
			utils.DebugLog.Write("request has no network")
		} else {
			inner_network := &inner_data.Req.Network

			if len(temp_req_network.Ip) > 6 {
				inner_network.Ip = temp_req_network.Ip
				utils.DebugLog.Write("client ip is %s", temp_req_network.Ip)
			}
			switch temp_req_network.Type {
			case 1:
				inner_network.NetworkType = context.NetworkType_WIFI
			case 2:
				inner_network.NetworkType = context.NetworkType_UNKNOWN
			case 3:
				inner_network.NetworkType = context.NetworkType_2G
			case 4:
				inner_network.NetworkType = context.NetworkType_3G
			case 5:
				inner_network.NetworkType = context.NetworkType_4G
			}
		}

		//adslot
		if len(temp_req.Adslots) > 0 {
			temp_req_adslot := &temp_req.Adslots[0]
			inner_adslot := &inner_data.Req.AdSlot
			inner_adslot.Slotid = temp_req_adslot.Id
			switch temp_req_adslot.Type {
			case 1:
				inner_adslot.AdSlotType = context.AdSlotType_BANNER
			case 2:
				inner_adslot.AdSlotType = context.AdSlotType_OFFERWALL
			case 3:
				inner_adslot.AdSlotType = context.AdSlotType_RECOMMEND
			case 4:
				inner_adslot.AdSlotType = context.AdSlotType_INITIALIZATION
			case 5:
				inner_adslot.AdSlotType = context.AdSlotType_INSERT
			default:
				inner_adslot.AdSlotType = context.AdSlotType_BANNER
			}
			inner_adslot.Size.Width = temp_req_adslot.Size.Width
			inner_adslot.Size.Height = temp_req_adslot.Size.Height
			if temp_req_adslot.Capacity != 0 {
				inner_adslot.Capacity = temp_req_adslot.Capacity
			} else {
				inner_adslot.Capacity = 1
			}
		} else {
			err = errors.New("no adslot info in request")
			return
		}

		inner_data.Req.Debug = temp_req.Debug
		utils.DebugLog.Write("get debug flag [%d]", inner_data.Req.Debug)

		//searchid
		if len(inner_data.Req.Device.DevID) > 0 {
			inner_data.Searchid = utils.GenSearchid(inner_data.Req.Device.DevID[0].ID)
		} else {
			inner_data.Searchid = utils.GenSearchid("default")
		}
	}
	return
}