百度信息流广告对接最终总结
<p>迩来对接了百度信息流广告,将对接流程记载如下:</p><p>业务需求:通过用户点击广告, 获取用户信息,统计有用户信息</p>
<p>实现原理:<br />*.用户点击百度app中的广告<br />*.百度app记载手机用户点击变乱,信息,并将用户信息传给百度服务器<br />*.百度服务器回调广告主事先在百度监控平台设置好的url(广告主本身开发)<br />*.广告主url获取用户点击变乱,根据哀求参数,来匹配用户的转换数据(应用激活)<br />*.广告主将匹配陈宫的转换数据拼接后<br />*.利用callback_rul,将数据回传到百度</p>
<p>*.百度背景会表现数据上传乐成的界面<br />*.结束</p>
<p> </p>
<p>业务流程如下:</p>
<p></p>
<p> </p>
<p> </p>
<p>详细接口文档很清楚,就不多说:</p>
<p>接口 文档所在: <a href="http://ocpc.baidu.com/developer/ocpc-doc/app/app-interface/README1.html">http://ocpc.baidu.com/developer/ocpc-doc/app/app-interface/README1.html</a></p>
<p>回调所在文档:<a href="http://ocpc.baidu.com/developer/ocpc-doc/app/app-interface/README1.html#callbackUrl">http://ocpc.baidu.com/developer/ocpc-doc/app/app-interface/README1.html#callbackUrl</a></p>
<p> </p>
<p>须要注意地方:</p>
<p>1.百度推广背景回调监测 URL,即feedback url(由广告主自行开发)</p>
<p>2.广告主将匹配乐成的转化数据与广告点击数据举行拼接,利用callback_url将数据回传给百度</p>
<p>3.广告主须要将url,在百度监控背景设置好(就是广告主的应用发布所在)</p>
<p>4.用户扫描对应的二维码</p>
<p>5.返回到保举页面,轻轻刷一下保举,然后 往下拉,找到百度测试广告的链接</p>
<p>6.点击广告测试广告的链接 (7.点击后,百度会回调个广告主的的应用,然后,点击后,百度会回调个广告主的的应用)</p>
<p>7.然后百度背景,会提示:数据上传中,</p>
<p>8.数据上传乐成(=假如不停是数据上传中,没有上传乐成,那么就要查抄应用的设置,代码的设置)</p>
<p>注意:假如你调用feedback函数,的哀求参url错了,如:sign,没有举行md5加密,大概没有sign参数,百度也会表现回调乐成(error_code=0)</p>
<p>这个时间,数据不停是上传中。须要调解代码</p>
<p>百度监测中央:</p>
<p>设置url地方:工具中央->转换追踪->新建</p>
<p></p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p>数据上传乐成后的截图:</p>
<p></p>
<p> </p>
<p> </p>
<p>t调试的时间,elk的记载</p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p>百度推广回调广告主代码逻辑:</p>
<p> private static string Okey = "";</p>
<p> public AdChannelNotice Notify(ushort behaviorType, HttpRequest request)<br /> {</p>
<p> var qs = request.Query;<br /> var os = ParseOs(qs["os"]);<br /> var idfa = qs["idfa"];<br /> var imeiMd5 = qs["imei_md5"];<br /> var timestamp = qs["ts"];<br /> var id = qs["ip"];<br /> var uid = qs["uid"];</p>
<p> var raw = request.QueryString.ToString();<br /> return new AdChannelNotice<br /> {<br /> AdId = uid,<br /> Idfa = idfa,<br /> AndroidIdMd5 = "",<br /> ImeiMd5 = imeiMd5,<br /> Os = os,<br /> Raw = raw,<br /> Time = TimestampHelper.FromTimestamp(timestamp)</p>
<p> };</p>
<p> }</p>
<p> private ushort ParseOs(string os)<br /> {<br /> switch (os)<br /> {<br /> case "1": return MobileOs.Ios;<br /> case "2": return MobileOs.Android;<br /> default: return 1;<br /> }<br /> }</p>
<p> </p>
<p> </p>
<p>广告主拼接数据后,将数据md5后给到百度广告主</p>
<p>代码逻辑:</p>
<p> public async Task Feedback(ushort channelId, ushort typeId, string raw)<br /> {<br /> var parameter = QueryHelpers.ParseQuery(raw);<br /> if (parameter == null)<br /> {<br /> _logger.Info($"Tuhu.Marketing.RealTime->BaiduAd->Feedback 获取Feedback参数失败,raw:{raw},channelId:{channelId},typeId:{typeId}");<br /> return;<br /> }<br /> var callbackUrl = parameter["callback_url"];</p>
<p> var url = BuildCallBackUrl(callbackUrl);</p>
<p> await SendBaiduMessage(channelId, url);<br /> }</p>
<p> private async Task SendBaiduMessage(ushort channelId, string url)<br /> {<br /> _logger.Info($"Tuhu.Marketing.RealTime->BaiduAd->Feedback 百度,哀求参数,channelId:{channelId},url:{url}");<br /> var responseMessage = await HttpClient.GetAsync(url);</p>
<p> var details = await responseMessage.Content.ReadAsStringAsync();</p>
<p> if (!responseMessage.IsSuccessStatusCode) throw new Exception($"Tuhu.Marketing.RealTime->BaiduAd->Feedback->error occured when feedback to channel {channelId} , details:{details}");</p>
<p> if (responseMessage.StatusCode == HttpStatusCode.OK)<br /> {<br /> _logger.Info($"Tuhu.Marketing.RealTime->BaiduAd->Feedback 百度,返回乐成,Message:{details}");</p>
<p> var jObj = JsonConvert.DeserializeObject<JObject>(details);<br /> var code = jObj.Value<int>("error_code");</p>
<p> if (code != 0) _logger.Error($"Tuhu.Marketing.RealTime->BaiduAd->Feedback 百度,服务器错误,Code:{code},Message:{details}");<br /> }<br /> }</p>
<p> private static string BuildCallBackUrl(Microsoft.Extensions.Primitives.StringValues callbackUrl)<br /> {<br /> var url = HttpUtility.UrlDecode(callbackUrl, Encoding.UTF8);<br /> url = url.Replace("{{ATYPE}}", "activate");<br /> url = url.Replace("{{AVALUE}}", "0");<br /> var sign = ToMd5($"{url}{Okey}");<br /> url = $"{url}&sign={sign}";<br /> return url;<br /> }</p>
<p> /// <summary><br /> /// 字符串加密Md5<br /> /// </summary><br /> /// <param name="str"></param><br /> /// <returns></returns><br /> private static string ToMd5(string str)<br /> {<br /> StringBuilder sb = new StringBuilder(32);<br /> MD5 md5 = new MD5CryptoServiceProvider();<br /> byte[] t = md5.ComputeHash(Encoding.UTF8.GetBytes(str));<br /> for (int i = 0; i < t.Length; i++)<br /> {<br /> sb.Append(t.ToString("x2"));<br /> }<br /> return sb.ToString();<br /> }</p>
<p><br /> private static class HttpUtility<br /> {<br /> /// <summary><br /> /// 对 URL 字符串举行编码<br /> /// </summary><br /> /// <param name="str">字符串</param><br /> /// <returns>编码效果</returns><br /> public static string UrlEncode(string str, Encoding e)<br /> {<br /> return System.Web.HttpUtility.UrlEncode(str, e);<br /> }</p>
<p> /// <summary><br /> /// 将已经为在 URL 中传输而编码的字符串转换为解码的字符串<br /> /// </summary><br /> /// <param name="str">字符串</param><br /> /// <returns>解码效果</returns><br /> public static string UrlDecode(string str, Encoding e)<br /> {<br /> return System.Web.HttpUtility.UrlDecode(str, e);<br /> }<br /> }</p>
<p> </p>
页:
[1]