google 广告条代码

 

 

----------------------WAP 手机页面放入GOOGLE广告代码

wap放入代码时注意:

1、google广告代码的输入里已自动处理<p></p>所心嵌入代码必须不包括<p></p>

2、如果同一页面需要放多个广告,由于<%! int i ; %> 声明的是类成员变量 ,所以引入两个文件中的代码都为以下一样

 

<%@ page contentType="text/vnd.wap.wml; charset=utf-8" language="java" import="java.io.BufferedReader,java.io.InputStreamReader,java.io.IOException,java.io.UnsupportedEncodingException,java.net.URL,java.net.URLEncoder,java.util.ArrayList,java.util.List" %>
<%//@ include file="g_session.jsp"%>
<%!
//google
public static final String PAGEAD ="http://pagead2.googlesyndication.com/pagead/ads?";

public void googleAppendUrl(StringBuilder url, String param, String value)
    throws UnsupportedEncodingException {
  if (value != null) {
    String encodedValue = URLEncoder.encode(value, "UTF-8");
    url.append("&").append(param).append("=").append(encodedValue);
  }
}

public void googleAppendColor(StringBuilder url, String param,String value, long random) {
  String[] colorArray = value.split(",");
  url.append("&").append(param).append("=").append(
      colorArray[(int)(random % colorArray.length)]);
}

public void googleAppendScreenRes(StringBuilder url, String uaPixels, String xUpDevcapScreenpixels, String xJphoneDisplay) {
  String screenRes = uaPixels;
  if (screenRes == null) {
    screenRes = xUpDevcapScreenpixels;
  }
  if (screenRes == null) {
    screenRes = xJphoneDisplay;
  }
  if (screenRes != null) {
    String[] resArray = screenRes.split("[x,*]");
    if (resArray.length == 2) {
      url.append("&u_w=").append(resArray[0]);
      url.append("&u_h=").append(resArray[1]);
    }
  }
}

public void googleAppendMuid(StringBuilder url, List<String> muids) {
  for (String muid : muids) {
    if (muid != null) {
      url.append("&muid=").append(muid);
    }
  }
}

public void googleAppendViaAndAccept(StringBuilder url, String via,String accept) throws UnsupportedEncodingException {
  googleAppendUrl(url, "via", via);
  googleAppendUrl(url, "accept", accept);
}
//end google


//google广告参数
long googleDt=0;
StringBuilder googleAdUrlStr=null;
String googleUrl=null;
String googleUserAgent =null;
List<String> googleMuids=null;
%>


<%
//google  out.prlint
 googleDt = System.currentTimeMillis();
 googleAdUrlStr = new StringBuilder(PAGEAD);
googleAdUrlStr.append("ad_type=text_image");
googleAdUrlStr.append("&channel=7175379058");
googleAdUrlStr.append("&client=ca-mb-pub-0900016263132484");
googleAdUrlStr.append("&dt=").append(googleDt);
googleAdUrlStr.append("&format=mobile_double");
googleAppendUrl(googleAdUrlStr, "ip", request.getRemoteAddr());
googleAdUrlStr.append("&markup=wml");
googleAdUrlStr.append("&oe=utf8");
googleAdUrlStr.append("&output=wml");
googleAppendUrl(googleAdUrlStr, "ref", request.getHeader("Referer"));
 googleUrl = request.getRequestURL().toString();
if (request.getQueryString() != null) {
  googleUrl += "?" + request.getQueryString().toString();
}
googleAppendUrl(googleAdUrlStr, "url", googleUrl);
 googleUserAgent = request.getHeader("User-Agent");
googleAppendUrl(googleAdUrlStr, "useragent", googleUserAgent);
googleAppendScreenRes(googleAdUrlStr, request.getHeader("UA-pixels"),
    request.getHeader("x-up-devcap-screenpixels"),
    request.getHeader("x-jphone-display"));
 googleMuids = new ArrayList<String>();
googleMuids.add(request.getHeader("X-DCMGUID"));
googleMuids.add(request.getHeader("X-UP-SUBNO"));
googleMuids.add(request.getHeader("X-JPHONE_UID"));
googleMuids.add(request.getHeader("X-EM-UID"));
googleAppendMuid(googleAdUrlStr, googleMuids);
if (googleUserAgent == null || googleUserAgent.length() == 0) {
  googleAppendViaAndAccept(googleAdUrlStr, request.getHeader("Via"),
      request.getHeader("Accept"));
}
try {
  URL googleAdUrl = new URL(googleAdUrlStr.toString());
  BufferedReader reader = new BufferedReader(
      new InputStreamReader(googleAdUrl.openStream(), "UTF-8"));
  for (String line; (line = reader.readLine()) != null;) {
    out.println(line);
  }
} catch (IOException e) {}
//end google
%>
<p>
<img src="http://wap.ggwan.com/images/wap_logo.gif" alt="GGwan"/><br/>
<a href="http://wap.ggwan.com/index.jsp">首页</a>|<a href="http://wap.ggwan.com/user_regist.jsp">注册</a>|<a href="http://wap.ggwan.com/login.jsp">登陆</a>|<a href="search.jsp">搜索</a><br/>
<a href="http://wap.ggwan.com/ranking_list.jsp">排行</a>|<a href="http://wap.ggwan.com/game_sectypelist.jsp">分类</a>|<a href="http://wap.ggwan.com/game_commend_list.jsp">推荐</a>|<a href="http://wapgame.ggwan.com">社区</a><br/>
</p>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值