加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

爬去 ios app 下载量的代码

发布时间:2020-12-14 22:54:59 所属栏目:大数据 来源:网络整理
导读:今天PHP站长网 52php.cn把收集自互联网的代码分享给大家,仅供参考。 package com.wecash.bi.job;import java.io.IOException;import java.util.HashMap;import java.util.Iterator;import java.util.Map;import org.apac

以下代码由PHP站长网 52php.cn收集自互联网

现在PHP站长网小编把它分享给大家,仅供参考

package com.wecash.bi.job;

import java.io.IOException;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;

import org.apache.commons.httpclient.Header;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.methods.PostMethod;
import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;

import com.google.gson.Gson;
import com.wecash.bi.util.Config;
import com.wecash.bi.util.WecashTool;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

public class IosAttentionJob implements Job {
	@Override
	public void execute(JobExecutionContext context) throws JobExecutionException {
		String startDate=WecashTool.lastDay("yyyy-MM-dd",-3);
		String endDate=WecashTool.lastDay("yyyy-MM-dd",-1);
		writeIosNewUser(startDate,endDate);															
	}
	/**
	 * @param startDate  开始时间  yyyy-MM-dd
	 * @param endDate   结束时间  yyyy-MM-dd
	 */
	public static void writeIosNewUser(String startDate,String endDate) {
		try {
 	       HttpClient httpclient = new HttpClient();
 		    PostMethod post = new PostMethod("https://idmsa.apple.com/appleauth/auth/signin");
 		    Map iosUser=new HashMap ();
 		    iosUser.put("accountName",Config.instace().getProperty("bi.wecash.ios.user"));
 		    iosUser.put("password",Config.instace().getProperty("bi.wecash.ios.password"));
 		    iosUser.put("rememberMe",true);
 			post.setRequestBody( new Gson().toJson(iosUser));
 			Map cookie_m=new HashMap ();
 			cookie_m.put("dssf",1);
 			cookie_m.put("dssid2","a7aaab83-0ba7-4eab-b003-1e2fb51ac453");
 			cookie_m.put("s_vnum_n2_cn","0%7C1");
 		    post.addRequestHeader("Content-Type","application/json");
 	 	    post.addRequestHeader("Cookie",buildCookie(cookie_m  )  );
 		    post.addRequestHeader("Accept-Language","zh-CN,zh;q=0.8");
			httpclient.executeMethod(post);
			 Header[] ls = post.getResponseHeaders( "Set-Cookie"); 
			 Map m = getCookie(cookie_m,ls);
			 post = new PostMethod("https://itunesconnect.apple.com/WebObjects/iTunesConnect.woa?");
			 post.addRequestHeader("Cookie",buildCookie(m )  );
			 httpclient.executeMethod(post);
			 ls = post.getResponseHeaders( "Set-Cookie"); 
			 m = getCookie(cookie_m,ls);
			 post = new PostMethod("https://analytics.itunes.apple.com/analytics/api/v1/data/time-series");
			 post.addRequestHeader("Cookie",buildCookie(cookie_m  )  );
			 post.addRequestHeader("X-Requested-By","analytics.itunes.apple.com");
			 post.addRequestHeader("Content-Type","application/json");
		 	 post.setRequestBody(String.format(   "{"adamId":["863934534"],"startTime":"%sT00:00:00Z","endTime":"%sT00:00:00Z","frequency":"DAY","measures":["units"],"group":null,"dimensionFilters":[]}",startDate,endDate) );
			 httpclient.executeMethod(post);
		 	 JSONObject jsonObject=JSONObject.fromObject( post.getResponseBodyAsString() );
		 	 JSONArray arr = ((JSONObject)jsonObject.getJSONArray("results").get(0))  . getJSONArray("data");
		 	 for (  Object o:arr ) {
		 		jsonObject=(JSONObject)o;
		 	    String date= 	jsonObject.getString("date").substring(0,10);
		 	      double value = jsonObject.getDouble("units");
		 		WxAttentionJob.dataDay(date,"iosTrigger","IOS激活",value);
			}
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

	private static Map  getCookie(  	Map m,Header[] ls) {
		 for (Header header : ls) {
			  String v = header.getValue();
			int i1= v.indexOf("=");
			 int i2 = v.indexOf(";",i1);
			 m.put(  v.substring(0,i1),v.substring(i1+1,i2));
		 }
		return m;
	}
	private static String  buildCookie(  	Map m,String ... cookie) {
		  StringBuffer sb =new StringBuffer();
		  for (int i = 0; i < cookie.length; i++) {
			  sb.append(cookie[i]);
			  sb.append("=");
			  sb.append(m.get(cookie[i] ).toString() );
			  sb.append(";");
		}
		return sb.toString();
	}
	
	private static String  buildCookie(  	Map m  ) {
	     Iterator i = m.keySet().iterator();
	     StringBuffer sb =new StringBuffer();
	     while (i.hasNext()) {
	    	  String  k =(String) i.next();
	   	  sb.append( k);
		  sb.append("=");
		  sb.append(m.get(k).toString() );
		  sb.append(";");
		}
		return sb.toString();
	}
	
}

以上内容由PHP站长网【52php.cn】收集整理供大家参考研究

如果以上内容对您有帮助,欢迎收藏、点赞、推荐、分享。

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读