func (this *ReqQiushiModule) request(inner_data *context.Context, adtype AdType, inner_ads *[]context.AdInfo, ch *chan bool) { // client := &http.Client{} var err error defer func() { // this.req_chan[int(adtype)] <- true *ch <- true utils.DebugLog.Write("true set into chan[%d]", int(adtype)) }() var request_body = mobads_api.BidRequest{} var bd_appsid string var bd_adslotid string // select baidu appsid switch adtype { case Banner: bd_appsid = "10042c1f" bd_adslotid = "L0000041" case Initlization: bd_appsid = "10044934" bd_adslotid = "L000000d" case Insert: bd_appsid = "10044933" bd_adslotid = "L000000a" default: bd_appsid = "10042c1f" bd_adslotid = "L0000041" } utils.DebugLog.Write("CHANNELID is [%s]", inner_data.Req.Media.ChannelId) if inner_data.Req.Media.ChannelId == "ac1f1b2a" { bd_appsid = "10045907" bd_adslotid = "L000001a" } err = this.packreq(&request_body, inner_data, bd_appsid, bd_adslotid) utils.DebugLog.Write("baidu_request [%s]", request_body.String()) var request_byte []byte request_byte = make([]byte, 0) request_byte, err = proto.Marshal(&request_body) if err != nil { utils.WarningLog.Write("proto marshal fail ! %s", err.Error()) return } var request *http.Request request, err = http.NewRequest("POST", this.qiushi_url, bytes.NewBuffer(request_byte)) if err != nil { utils.WarningLog.Write("create http post request fail [%s]", err.Error()) return } request.Header.Set("Content-Type", "application/x-protobuf") request.Header.Set("Accept", "application/x-protobuf") request.Header.Set("User-Agent", "Jesgoo-API") request.Header.Set("Connection", "Keep-alive") var response *http.Response response, err = this.client.Do(request) defer func() { if response != nil && response.Body != nil { response.Body.Close() } }() if err != nil { utils.WarningLog.Write("request qiushi server fail [%s]", err.Error()) return } if response.StatusCode != 200 { err = errors.New("qiushi respose code is " + string(response.StatusCode)) utils.WarningLog.Write("qiushi response code is %d", response.StatusCode) return } var response_body = mobads_api.BidResponse{} var response_byte []byte response_byte, err = ioutil.ReadAll(response.Body) if err != nil { utils.WarningLog.Write("error occured [%s]", err.Error()) return } err = proto.Unmarshal(response_byte, &response_body) if err != nil { utils.WarningLog.Write("error occur [%s]", err.Error()) return } err = this.parse_resp(&response_body, adtype, inner_ads, bd_appsid) return }
func (this *ReqQiushiModule) packreq(request *mobads_api.BidRequest, inner_data *context.Context, bd_appsid string, bd_adslotid string) (err error) { request.RequestId = new(string) *request.RequestId = inner_data.Searchid //version parament request.ApiVersion = new(mobads_api.Version) version_tmp := request.ApiVersion version_tmp.Major = new(uint32) version_tmp.Minor = new(uint32) version_tmp.Micro = new(uint32) *version_tmp.Major = 4 *version_tmp.Minor = 0 *version_tmp.Micro = 0 //app parament request.App = new(mobads_api.App) app_tmp := request.App app_tmp.StaticInfo = new(mobads_api.App_StaticInfo) app_static_info := app_tmp.StaticInfo app_static_info.BundleId = new(string) *app_static_info.BundleId = "com.jesgoo.app" app_tmp.Id = new(string) // *app_tmp.Id = "10042c1f" *app_tmp.Id = bd_appsid //device parament request.Device = new(mobads_api.Device) device_tmp := request.Device device_tmp.Type = new(mobads_api.Device_Type) *device_tmp.Type = mobads_api.Device_PHONE device_tmp.Os = new(mobads_api.Device_Os) switch inner_data.Req.Device.OSType { case context.OSType_ANDROID: *device_tmp.Os = mobads_api.Device_ANDROID case context.OSType_IOS: *device_tmp.Os = mobads_api.Device_IOS default: *device_tmp.Os = mobads_api.Device_ANDROID } *version_tmp.Major = inner_data.Req.Device.OSVersion.Major *version_tmp.Minor = inner_data.Req.Device.OSVersion.Minor *version_tmp.Micro = inner_data.Req.Device.OSVersion.Micro device_tmp.OsVersion = new(mobads_api.Version) device_tmp.OsVersion.Major = new(uint32) device_tmp.OsVersion.Minor = new(uint32) device_tmp.OsVersion.Micro = new(uint32) *device_tmp.OsVersion.Major = inner_data.Req.Device.OSVersion.Major *device_tmp.OsVersion.Minor = inner_data.Req.Device.OSVersion.Minor *device_tmp.OsVersion.Micro = inner_data.Req.Device.OSVersion.Micro device_tmp.Udid = new(mobads_api.Device_UdId) device_udid := device_tmp.Udid for i := 0; i < len(inner_data.Req.Device.DevID); i++ { switch inner_data.Req.Device.DevID[0].DevIDType { case context.DeviceIDType_IMEI: device_udid.Imei = new(string) *device_udid.Imei = inner_data.Req.Device.DevID[0].ID case context.DeviceIDType_MAC: device_udid.Mac = new(string) *device_udid.Mac = inner_data.Req.Device.DevID[0].ID case context.DeviceIDType_IDFA: device_udid.Idfa = new(string) *device_udid.Idfa = inner_data.Req.Device.DevID[0].ID default: device_udid.Imei = new(string) *device_udid.Imei = inner_data.Req.Device.DevID[0].ID } } //trick code /* if device_udid.Imei == nil { device_udid.Imei = new(string) *device_udid.Imei = "863778014726969" }*/ device_tmp.Vendor = new(string) *device_tmp.Vendor = inner_data.Req.Device.Brand device_tmp.Model = new(string) *device_tmp.Model = inner_data.Req.Device.Model //network request.Network = new(mobads_api.Network) network_tmp := request.Network network_tmp.Ipv4 = new(string) *network_tmp.Ipv4 = inner_data.Req.Network.Ip network_tmp.Type = new(mobads_api.Network_Type) switch inner_data.Req.Network.NetworkType { case context.NetworkType_WIFI: *network_tmp.Type = mobads_api.Network_WIFI default: *network_tmp.Type = mobads_api.Network_MOBILE network_tmp.Subtype = new(mobads_api.Network_SubType) *network_tmp.Subtype = mobads_api.Network_HSPA } utils.DebugLog.Write("req qiushi inner_ip [%s]", inner_data.Req.Network.Ip) //adslot var adslot_tmp mobads_api.AdSlot adslot_tmp.Id = new(string) // *adslot_tmp.Id = "L0000041" *adslot_tmp.Id = bd_adslotid var size_tmp mobads_api.Size size_tmp.Width = new(uint32) size_tmp.Height = new(uint32) if inner_data.Req.AdSlot.Size.Width != 0 { *size_tmp.Width = uint32(inner_data.Req.AdSlot.Size.Width) *size_tmp.Height = uint32(inner_data.Req.AdSlot.Size.Height) } else { *size_tmp.Width = 320 *size_tmp.Height = 48 } adslot_tmp.Size = new(mobads_api.Size) *adslot_tmp.Size = size_tmp request.Adslots = make([]*mobads_api.AdSlot, 0) request.Adslots = append(request.Adslots, &adslot_tmp) return }