import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.net.URLEncoder;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Arrays;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.HashMap;
import java.util.Random;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javax.crypto.Mac;
import javax.crypto.spec.SecretKeySpec;
import org.json.JSONObject;
public class YueDongmm {
public static String strKey = "9b7adbd2ee5206224135&";
public static void main(String[] args) {
strKey = "201505yuedongxiaoyue&";
strKey = "9b7adbd2ee5206224135&";
// 201505yuedongxiaoyue&
// 9b7adbd2ee5206224135&
// encodeToString g.m.smail
// System.out.println(is32NO("1000049901201604270201853397948"));
String msg = "null";
String strChinese = "";
String strUtf8 = "\u4e2d\u56fd\u4f01\u4e1a\u5bb6\u6742\u5fd7";
try {
try {
} catch (Exception e) {
e.printStackTrace();
strChinese = "decode error";
}
// System.out.println(strChinese);
// System.out.println(getRalsmm());
// 开发者ID xxx
// String weixinurl = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=xxxxx&secret=xxxx";
// 开发者ID xxx
// weixinurl = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=xxxx&secret=xxxx";
onUsermmLong("13432857155", "123456");
// onUsermmLong("1xxxx5", "wxx");
// onloingiPhone("1xxx5", "wxxx");
// onSetStep2("76775338", "300", "txl79dfkw84bv5s1n0rvze");
// onSetStep2("42390219", "55555", "txl79dfkw84bv5s1n0rvze");
//System.out.println(get_user_step("76223958", "3o412cqentvdzih6fkwglg8x7s"));
//System.out.println(fuwu("42390219",""));//7qvgu5dv9lzxr8mn
//System.out.println(HttpRequest.sendGet(weixinurl, null));
// onloingiPhone("15xxx", "wxxx");
// onUserRegiste("15xxx", "wxxxx");
// System.out.println(new Random().nextInt(99999)+1000000);
// isMobileNO("13xxxxxxxx");
// System.out.println("0123456789".indexOf("11"));
// isStepsNO("1"); return HttpWebGet(StrUrl+"?"+StrData);
// onSetStep2("42390215","888888");
// onSetStep("42390219","88888");
// onUserRegiste("13xxxxxx", "123456");
// msg = onUsermmLong("13xxxxx", "123456");
// msg = onloingiPhone("13xxxxxx", "123456");
// apply_add_friend();
// String msg = get_user_step("42xxxx19", "lk0gpuz4iobmcahvgn8");
// String str = new String(msg.getBytes("ISO-8859-2"),"UTF-8");
// String strvalue = new String(msg.getBytes("ISO-8859-2"), "GBK").trim();
// String strvalue2 =new String(msg.getBytes("iso8859-1"));
//// str=new String(rs.getBytes(1),"GBK");
// str=new String(str.getBytes("UTF-8"),"GBK");
//
//// System.out.println(URLDecoder.decode(msg,"UTF-8"));
// System.out.println(msg);
// System.out.println(str);
// System.out.println(strvalue);
// System.out.println(strvalue2);
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* 任意关注用户
* @return
*/
@SuppressWarnings("deprecation")
public static String apply_add_friend(){
String url = "http://api.51yund.com/sport/apply_add_friend";
String s= "client_user_id=42390219"
+ "&friend_user_id=119531555"
+ "&language=zh-Hans"
+ "&locale=CN"
+ "&os=8.1.3"
+ "&phone_type=iPhone6%2C1"
+ "&sign=Q6jB/7kKhKIG1rPO5jjOoW2h7us%3D"
+ "&source=ios"
+ "&timezone=%2B8"
+ "&user_id=42390219"
+ "&ver=2.9.23"
+ "&xyy=7qvgu5dv9lzxr8mn";
HashMap paramHashMap = new HashMap();
paramHashMap.put("client_user_id", "42390219");//42390219
paramHashMap.put("friend_user_id", "119531555");//119531555
paramHashMap.put("language","zh-Hans");
paramHashMap.put("locale", "CN");
paramHashMap.put("os","8.1.3");
paramHashMap.put("phone_type", "iPhone6,1");
paramHashMap.put("source", "ios");
paramHashMap.put("timezone", "+8");
paramHashMap.put("user_id", "42390219");
paramHashMap.put("ver", "2.9.23");
// 加密
String strYueDmm = "";
String strdata1 = a("POST", getPathOfUrl(url), paramHashMap);
strYueDmm = jiami(strdata1, strKey);
System.err.println(strYueDmm);
paramHashMap.put("sign", strYueDmm);
paramHashMap.put("xyy", "7qvgu5dv9lzxr8mn");
String sr = HttpRequest.sendPost(url, paramHashMap);
System.out.println(sr);
// 加密
return strKey;
}
/**
* 用户注册
* @param strname
* @param strpwd
* @return
* @throws Exception
*/
public static String onUserRegiste(String strname, String strpwd) throws Exception{
//http://119.29.26.237/sport/register?phone=151xxxxx&passwd=5fc2xxxxe9f2e9465c2df8dd3&nick=123456&sex=0&device_id=866980025257229&invite_user_id=42390219&ver=3.1.1.6.189&phone_type=Lenovo&sdk=21&os=5.4.4&source=android_app&client_user_id=-1&channel=channel_360&sign=LO8bSq1NsxuooiHz%2F1T8f1vht%2BE%3D&xyy=7qvgu5dv9lzxr8mn
String url = "http://api.51yund.com/sport/register";
HashMap paramHashMap = new HashMap();
paramHashMap.put("os", "4.4.4");
paramHashMap.put("passwd", MD5Util.MD5(strpwd).toLowerCase());
paramHashMap.put("invite_user_id","42390219");
paramHashMap.put("sex", "1");
paramHashMap.put("phone",strname);
paramHashMap.put("phone_type", "LenovoK30-T");
paramHashMap.put("device_id", "8669"+strname);
paramHashMap.put("ver", "3.1.2.8.343");
paramHashMap.put("source", "android_app");
paramHashMap.put("sdk", "19");
paramHashMap.put("channel", "channel_wandoujia");
paramHashMap.put("client_user_id", "-1");
// paramHashMap.put("nick", "6666666666666");
// paramHashMap.put("xyy", "7qvgu5dv9lzxr8mn");
// 加密
String strdata1 = a("POST", getPathOfUrl(url), paramHashMap);
// 加密
String strYueDmm = jiami(strdata1.getBytes("UTF-8"), strKey);
System.err.println(strYueDmm);
// System.err.println("BDFvTfDBvayT/JPP6zId7xN+ZLw=");
// 表单
String StrName = String.valueOf(new Random().nextInt(99999)+1000000);// 随机密码
String strData =
// "phone=" + strname
// + "&passwd="+//MD5Util.MD5(strpwd).toLowerCase()
// + "&nick="+ StrName // 123456
// + "&sex=0"
// + "&device_id=866980025257219"
// + "&invite_user_id=42390219"
// + "&ver=3.1.1.6.189"
// + "&phone_type=LenovoK30-T"
// + "&sdk=19"
// + "&os=4.4.4"
// + "&source=android_app"
// + "&client_user_id=-1"
// + "&channel=channel_360"
// + "&sign="+strYueDmm
// + "&xyy=7qvgu5dv9lzxr8mn";//g0ldgvxqniu1twzr7csav
"os=4.4.4"
+ "&passwd="+MD5Util.MD5(strpwd).toLowerCase() //5fc2d383813bb4fe9f2e9465c2df8dd3
+ "&invite_user_id=42390219"
+ "&sex=1"
+ "&phone="+ strname //15669834304
+ "&phone_type=LenovoK30-T"
+ "&device_id=8669"+strname
+ "&ver=3.1.2.8.343"
+ "&sign="+strYueDmm
+ "&source=android_app"
+ "&nick=keji58"
+ "&sdk=19"
+ "&channel=channel_wandoujia"
// + "&xyy=7qvgu5dv9lzxr8mn11111111"//7qvgu5dv9lzxr8mn
+ "&client_user_id=-1";
//发送 POST 请求
String sr = HttpRequest.sendPost(url, strData);
System.out.println(sr);
return sr;
}
/**
* 刷步数1 过期
*/
public static String onSetStep(String strid, String strsteps) throws UnsupportedEncodingException, Exception{
// POST http://api.51yund.com/sport/report_runner_info_bracelet
// Host: api.51yund.com
// Content-Type: application/x-www-form-urlencoded
// Connection: keep-alive
// Connection: keep-alive
// Accept: */*
// User-Agent: SportsBar/2.9.12 (iPhone; iOS 8.1.3; Scale/2.00)
// Accept-Language: zh-Hans;q=1
// Accept-Encoding: gzip, deflate
// Content-Length: 290
//
// bracelet_uuid=nodevice&caloric=50.69430627441406&client_user_id=42390219&cost_time=60119&day_id=20160318&device_id=6DD40AF6-F48A-49C5-99DB-9D0F5117EFEF&kind_id=4&sign=3x4lPMxx/8w%2BAe8A2%2BlpmhQH%2Bog%3D&source=ios&steps=1269&time=1458230400&user_id=42390219&ver=2.9.12&xyy=7qvgu5dv9lzxr8mn
// 提交时间
String StrDate = onGetDate();
String StrDateMillis = "";
StrDateMillis = onGetDateMillis(StrDate);
// 数据界面
HashMap paramHashMap = new HashMap();
paramHashMap.put("bracelet_uuid", "nodevice");
paramHashMap.put("caloric","50.69430627441406");
paramHashMap.put("client_user_id", strid);
paramHashMap.put("cost_time", "65119");
paramHashMap.put("day_id", StrDate);
paramHashMap.put("device_id", "6DD40AF6-F48A-49C5-99DB-9D0F5117EFEF");
paramHashMap.put("kind_id", "4");
paramHashMap.put("source", "ios");
paramHashMap.put("steps", strsteps);// 1269
paramHashMap.put("time", StrDateMillis);
paramHashMap.put("user_id", strid);
paramHashMap.put("ver", "2.9.12");
// paramHashMap.put("xyy", "7qvgu5dv9lzxr8mn");
// 加密
String strdata1 = a("POST","/sport/report_runner_info_bracelet", paramHashMap);
String strYueDmm = jiami(strdata1.getBytes("UTF-8"), strKey);
// 表单拼接
String StrPostData =
"bracelet_uuid=nodevice"
+ "&sign="+strYueDmm//3x4lPMxx/8w%2BAe8A2%2BlpmhQH%2Bog%3D
+ "&caloric=50.69430627441406"
+ "&client_user_id="+strid
+ "&cost_time=65119"
+ "&day_id="+StrDate
+ "&device_id=6DD40AF6-F48A-49C5-99DB-9D0F5117EFEF"
+ "&kind_id=4"
+ "&source=ios"
+ "&steps="+strsteps//1269
+ "&time="+StrDateMillis
+ "&user_id="+strid
+ "&ver=2.9.12"
+ "&xyy=7qvgu5dv9lzxr8mn";
System.out.println(strYueDmm);
//发送 POST 请求
String sr = HttpRequest.sendPost("http://api.51yund.com/sport/report_runner_info_bracelet", StrPostData);
System.out.println(sr);
return sr;
}
/**
* 刷步数2 加密版
* @param strid
* @param strsteps
* @return {"code":0,"msg":"ok","flag":1,"cnt":0,"steps_array_resp":[{"index":0,"step":88888,"run_ts":1458569003,"cost_time":51,"code":0,"err":0,"runner_id":763398784}],"next_cnt":10}
* @throws {"code":1,"msg":"param:bad args is wrong?","flag":1,"cnt":0}
* @throws {"msg": "参数不合", "cnt": 1, "code": 1, "flag": 0}
* @throws UnsupportedEncodingException
* @throws Exception
*/
public static String onSetStep2(String strid, String strsteps, String xyy) throws UnsupportedEncodingException, Exception{
// POST http://report-segstep.51yund.com/sport/report_runner_info_step_batch
// Connection: Keep-Alive
// Content-Type: application/x-www-form-urlencoded
// Content-Length: 291
// Host: report-segstep.51yund.com
// Accept-Encoding: gzip
// User-Agent: okhttp/2.7.3
// subtype=0&sign=2FFeCfKrA17OwuXVp5GVirVxn0c%3D&xyy=7qvgu5dv9lzxr8mn&client_user_id=42390219&phone_type=MIPAD2&channel=channel_wandoujia&kind_id=2&ver=3.1.2.8.343&steps_array_json=%5B%7B%22cost_time%22%3A51%2C%22run_ts%22%3A1458535669%2C%22step%22%3A10%2C%22index%22%3A0%7D%5D&user_id=42390219
String url = "http://report-segstep.51yund.com/sport/report_runner_info_step_batch";// 1
url = "http://api.51yund.com/sport/report_runner_info_bracelet"; // 2
// 提交时间
String StrDate = onGetDate();
String StrDateMillis = "";
String steDataN = onGetDataN();
StrDateMillis = onGetDateMillis(StrDate);
// 时间计算
System.out.println(StrDate);
System.out.println(StrDateMillis);
System.out.println(steDataN);
// 1
HashMap paramHashMap = new HashMap();
// paramHashMap.put("subtype", "0");
// paramHashMap.put("client_user_id", strid);
// paramHashMap.put("phone_type","iPhone5s");//MIPAD2
// paramHashMap.put("channel", "CN");//channel_wandoujia
// paramHashMap.put("kind_id", "2");
// paramHashMap.put("ver", "2.9.28");
// paramHashMap.put("steps_array_json", "[{\"cost_time\":51,\"run_ts\":"+steDataN+",\"step\":"+strsteps+",\"index\":0}]");
// paramHashMap.put("user_id", strid);
// 2
paramHashMap.put("bracelet_uuid", "nodevice");
paramHashMap.put("caloric", "1" + strsteps + ".947384800720215");
paramHashMap.put("client_user_id", strid);
paramHashMap.put("cost_time", (Integer.valueOf(strsteps) * 1024) +"");
paramHashMap.put("day_id", StrDate);
paramHashMap.put("device_id", "65CA6BE8-B0F3-4C60-AD31-4A1D334E40B5");
paramHashMap.put("kind_id", "4");
paramHashMap.put("language", "zh-Hans");
paramHashMap.put("locale", "CN");
paramHashMap.put("os", "9.3.2");
paramHashMap.put("phone_type", "iPhone6S");
paramHashMap.put("source", "ios");
paramHashMap.put("steps",strsteps);
paramHashMap.put("time", StrDateMillis);
paramHashMap.put("timezone", "+8");
paramHashMap.put("user_id", strid);
paramHashMap.put("ver", "2.9.29");
// 加密1
String strdata1 = a("POST", getPathOfUrl(url), paramHashMap);
// 加密2
String strYueDmm = jiami(strdata1.getBytes("UTF-8"), strKey);
paramHashMap.put("sign", strYueDmm);
paramHashMap.put("xyy", xyy);
//发送 POST 请求
String sr = "";
// sr = HttpRequest.sendPost(url, paramHashMap);
sr = HttpRequestUtil.sendPost(url, paramHashMap);
System.out.println(strYueDmm);
System.out.println(sr);
return sr;
}
/**
* 步数提交
* @param strid id
* @param strsteps 步数
* @return
*/
public static String onStepUpload(String strid, String strsteps){
// 提交时间
String StrDate = onGetDate();
String StrDateMillis = "";
StrDateMillis = onGetDateMillis(StrDate);
// 表单
String strUrl = "http://api.51yund.com/sport/report_runner_info_bracelet";
String strData = "bracelet_uuid=nodevice"
+ "&caloric=12.05438"
+ "&client_user_id="+strid
+ "&cost_time=86400"
+ "&day_id="+StrDate
+ "&device_id=6DD40AF6-F48A-49C5-99DB-9D0F5117EFEF"
+ "&kind_id=4"
+ "&sign=0xXgETGzbDgtXia57bmOhrYLGJQ%3D"
+ "&source=ios"
+ "&steps="+strsteps
+ "&time="+StrDateMillis
+ "&user_id="+strid
+ "&ver=2.9.10"
+ "&xyy=7qvgu5dv9lzxr8mn";
//发送 POST 请求
String sr = HttpRequest.sendPost(strUrl, strData);
System.out.println(sr);
return sr;
}
/**
* 用户登录
*
*/
public static String onloingiPhone(String name, String pwd) throws Exception{
// POST http://api.51yund.com/sport/login HTTP/1.1
// Host: api.51yund.com
// Content-Type: application/x-www-form-urlencoded
// Connection: keep-alive
// Connection: keep-alive
// Accept: */*
// User-Agent: SportsBar/2.9.10 (iPhone; iOS 8.1.3; Scale/2.00)
// Accept-Language: zh-Hans;q=1
// Accept-Encoding: gzip, deflate
// Content-Length: 221
// client_user_id=42701325&latitude=22.98322549182702&longitude=22.5428226&os=8.1.3&passwd=5fc2d383813bb4fe9f2e9465c2df8dd3&phone=15xxxxxx&phone_type=iPhone6%2C1&sign=sbmSgkBsA6%2BbQjpxwdeDJyixOP4%3D&source=ios&ver=2.9.10
// 数据界面
HashMap paramHashMap = new HashMap();
paramHashMap.put("client_user_id", "42701325");
paramHashMap.put("latitude", "22.98322549182702");
paramHashMap.put("longitude", "22.5428226");
paramHashMap.put("os", "8.1.3");
paramHashMap.put("passwd", MD5Util.MD5(pwd).toLowerCase());
paramHashMap.put("phone", name);
paramHashMap.put("phone_type", "iPhone6,1"); //iPhone6,1 |iPhone6%2C1
paramHashMap.put("source", "ios");// ios |android_app
paramHashMap.put("ver", "2.9.10");
// 加密
String strdata1 = a("POST","/sport/login", paramHashMap);
String strYueDmm = jiami(strdata1.getBytes("UTF-8"), strKey);
// 表单拼接
String StrPostData =
"client_user_id=42701325"
+ "&latitude=22.98322549182702"
+ "&longitude=22.5428226"
+ "&os=8.1.3"
+ "&passwd="+MD5Util.MD5(pwd).toLowerCase()//5fc2d383813bb4fe9f2e9465c2df8dd3
+ "&phone="+name//15xxxxxxxxxxxx
+ "&phone_type=iPhone6%2C1"//iPhone6%2C1 |iPhone6,1
+ "&source=ios"
+ "&sign="+strYueDmm// sbmSgkBsA6%2BbQjpxwdeDJyixOP4%3D
+ "&ver=2.9.10";
//发送 POST 请求
String sr = HttpRequest.sendPost("http://api.51yund.com/sport/login", StrPostData);
//
// return HttpWebGet("http://api.51yund.com/sport/login?"+StrPostData);
return sr;
}
public static String getRalsmm(int i){
String temp = "";
String chars = "0123456789ACDEFGHIJKLMNOPQRSTUVWXYZ";
for(int p=0;p paramHashMap = new HashMap();
paramHashMap.put("client_user_id", "-1");//42701325
paramHashMap.put("device_id", Device);
paramHashMap.put("language", "zh-Hans");
paramHashMap.put("locale", "CN");
paramHashMap.put("os", "8.1.3");
paramHashMap.put("passwd", MD5Util.MD5(pwd).toLowerCase());
paramHashMap.put("phone", name);
paramHashMap.put("phone_type", "iPhone5s");
paramHashMap.put("source", "ios");
paramHashMap.put("timezone", "+8");//%2B8 +8
paramHashMap.put("ver", "2.9.28");
// 加密
String strdata1 = a("POST", getPathOfUrl(url), paramHashMap);
// 加密
String strYueDmm = jiami(strdata1.getBytes("UTF-8"), strKey);
paramHashMap.put("sign", strYueDmm);
//9D0F5117EFEF
StrData = "client_user_id=-1&device_id=" + Device + "&language=zh-Hans&locale=CN&os=8.1.3"
+ "&passwd="+MD5Util.MD5(pwd).toLowerCase()
+ "&phone="+name
+ "&phone_type=iPhone5s"
+ "&sign="+strYueDmm
+ "&source=ios&timezone=%2B8&ver=2.9.28";
System.out.println(strYueDmm);
System.out.println("url:"+url);
System.out.println("StrData:"+StrData);
// StrData = "client_user_id=42701325&device_id=6DD40AF6-F48A-49C5-99DB-9D0F5117EFEF&language=zh-Hans&locale=CN&os=8.1.3&passwd=e10adc3949ba59abbe56e057f20f883e&phone=13432857155&phone_type=iPhone5s&sign=aUWteyiJlrA5Iexeu2iCts13S2c=&source=ios&timezone=%2B8&ver=2.9.28";
//发送 POST 请求
// return HttpWebPost("http://1212.ip138.com/ic.asp", "get", "");
return HttpWebPost_127_0_0_1(url, "post", StrData);
}
/**
* 获取用户信息
* @param user_id 用户id
* @param xyy 用户xyy
* @return
* @throws Exception
*/
public static String get_user_step(String user_id, String xyy) throws Exception{
//201505yuedongxiaoyue&
//Tag: POST
//Message: /sport/get_user_group_run_step
//{end_cnt=1, user_id=76223958, ver=3.1.2.6.226, begin_cnt=0, phone_type=LenovoK30-T, channel=channel_office, client_user_id=76223958}
// 222222222222
// POST http://api.51yund.com/sport/get_user_group_run_step
// sign=aIFDHP50VbemHDJELQ1stEPszl4%3D
// &end_cnt=20
// &begin_cnt=0
// &phone_type=LenovoK30-T
// &user_id=114481348
// &ver=3.1.2.8.343
// &channel=channel_wandoujia
// &xyy=lk0gpuz4iobmcahvgn8
// &client_user_id=114481348
HashMap paramHashMap = new HashMap();
// paramHashMap.put("end_cnt", "1");
// paramHashMap.put("user_id", user_id);
// paramHashMap.put("ver", "3.1.2.6.226");
// paramHashMap.put("begin_cnt", "0");
// paramHashMap.put("phone_type", "LenovoK30-T");//LenovoK30-T IdeaTabA2207A-H
// paramHashMap.put("channel", "channel_office");
// paramHashMap.put("client_user_id", user_id);
paramHashMap.put("end_cnt", "20");
paramHashMap.put("begin_cnt", "0");
paramHashMap.put("phone_type", "LenovoK30");
paramHashMap.put("user_id", user_id);
paramHashMap.put("ver", "3.1.2.8.343");
paramHashMap.put("channel", "channel_wandoujia");//channel_office channel_wandoujia
paramHashMap.put("client_user_id", user_id);
// 加密
String strdata1 = a("POST","/sport/get_user_group_run_step", paramHashMap);
String sign = jiami(strdata1.getBytes("UTF-8"), strKey);
System.out.println(sign);
String StrUrl = "http://api.51yund.com/sport/get_user_group_run_step";
String StrData =
"sign="+sign
+ "&end_cnt=20"
+ "&begin_cnt=0"
+ "&phone_type=LenovoK30"
+ "&user_id="+user_id
+ "&ver=3.1.2.8.343"
+ "&channel=channel_wandoujia"
+ "&client_user_id="+user_id
+ "&xyy="+xyy;
paramHashMap.put("xyy", xyy);
paramHashMap.put("sign", sign);
// StrUrl = "http://api.51yund.com/sport/get_user_group_run_step?sign=aIFDHP50VbemHDJELQ1stEPszl4%3D&end_cnt=20&begin_cnt=0&phone_type=LenovoK30-T&user_id=114481348&ver=3.1.2.8.343&channel=channel_wandoujia&xyy=lk0gpuz4iobmcahvgn8&client_user_id=114481348";
// StrUrl = "http://api.51yund.com/sport/get_user_group_run_step?sign=gUXwLJGzqapYmv5zFFGQL7cHMLA=&end_cnt=20&begin_cnt=0&phone_type=LenovoK30&user_id=42390219&ver=3.1.2.8.343&channel=channel_wandoujia&client_user_id=42390219&xyy=lk0gpuz4iobmcahvgn8";
// System.out.println(StrData);
//发送 POST 请求
// return HttpRequest.sendPost(StrUrl, StrData);
return HttpWebGet(StrUrl+"?"+StrData);
}
/**
* post get
*/
public static String HttpWebPost_127_0_0_1(String setUrl, String seltype, String parms){
HashMap hanHashMap = new HashMap();
// hanHashMap.put("Accept", "application/json, text/javascript, */*; q=0.01");
// hanHashMap.put("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
// hanHashMap.put("X-Requested-With", "XMLHttpRequest");
// hanHashMap.put("User-Agent", "Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/53.0.2785.8 Safari/537.36");
// hanHashMap.put("Referer", "http://coolaf.com/");
// hanHashMap.put("Content-Type", "multipart/form-data; boundary=----WebKitFormBoundarywX1MBPmFiSFLwIyY");
// http://coolaf.com/
// Accept: application/json, text/javascript, */*; q=0.01
// X-Requested-With: XMLHttpRequest
// User-Agent: Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/38.0.2125.122 Safari/537.36 SE 2.X MetaSr 1.0
// Content-Type: multipart/form-data; boundary=----WebKitFormBoundarywX1MBPmFiSFLwIyY
//post get
String url = "http://127.0.0.1:9090/tool/ajaxgp";
String strData = "";
String sr = "";
try {
strData = "url=" + URLEncoder.encode(setUrl, "UTF-8") + "&seltype="+seltype+"&ck=&header=Content-Type%3Aapplication%2Fx-www-form-urlencoded&proxy=&code=utf8&parms="+URLEncoder.encode(parms, "UTF-8");
strData = "url=" + URLEncoder.encode(setUrl, "UTF-8") + "&seltype=post&ck=&header=Content-Type%3Aapplication%2Fx-www-form-urlencoded&parms="+URLEncoder.encode(parms, "UTF-8")+"&proxy=&code=utf8";
// strData = "url=http%3A%2F%2Fapi.51yund.com%2Fsport%2Flogin&seltype=post&ck=&header=Content-Type%3Aapplication%2Fx-www-form-urlencoded&parms=client_user_id%3D42701325%26device_id%3D6DD40AF6-F48A-49C5-99DB-9D0F5117EFEF%26language%3Dzh-Hans%26locale%3DCN%26os%3D8.1.3%26passwd%3De10adc3949ba59abbe56e057f20f883e%26phone%3D13432857155%26phone_type%3DiPhone5s%26sign%3DaUWteyiJlrA5Iexeu2iCts13S2c%253D%26source%3Dios%26timezone%3D%252B8%26ver%3D2.9.28&proxy=&code=utf8";
sr = HttpRequest.sendPost(url, strData, hanHashMap);
System.out.println("HttpWebPost,Request= "+sr);
JSONObject jsonObject = new JSONObject(sr);
String RetuenData = jsonObject.getJSONObject("data").getString("response");
System.out.println("HttpWebPost,data.response = "+RetuenData);
return RetuenData;
} catch (Exception e) {
e.printStackTrace();
}
return sr;
}
/**
* post get
*/
public static String HttpWebPost(String setUrl, String seltype, String parms){
HashMap hanHashMap = new HashMap();
hanHashMap.put("Accept", "application/json, text/javascript, */*; q=0.01");
hanHashMap.put("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
hanHashMap.put("X-Requested-With", "XMLHttpRequest");
hanHashMap.put("User-Agent", "Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/53.0.2785.8 Safari/537.36");
hanHashMap.put("Referer", "http://coolaf.com/");
hanHashMap.put("Content-Type", "multipart/form-data; boundary=----WebKitFormBoundarywX1MBPmFiSFLwIyY");
// http://coolaf.com/
// Accept: application/json, text/javascript, */*; q=0.01
// X-Requested-With: XMLHttpRequest
// User-Agent: Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/38.0.2125.122 Safari/537.36 SE 2.X MetaSr 1.0
// Content-Type: multipart/form-data; boundary=----WebKitFormBoundarywX1MBPmFiSFLwIyY
//post get
String url = "http://coolaf.com/tool/ajaxgp";
String strData = "";
String sr = "";
String TempTest = "\r\n";
try {
strData = "------WebKitFormBoundarywX1MBPmFiSFLwIyY"+TempTest
+"Content-Disposition: form-data; name=\"url\""+TempTest+TempTest
+"http://api.51yund.com/sport/login"+TempTest
+"------WebKitFormBoundarywX1MBPmFiSFLwIyY"+TempTest
+"Content-Disposition: form-data; name=\"seltype\""+TempTest+TempTest
// +"post"+TempTest
+seltype+TempTest
+"------WebKitFormBoundarywX1MBPmFiSFLwIyY"+TempTest
+"Content-Disposition: form-data; name=\"ck\""+TempTest+TempTest
+"------WebKitFormBoundarywX1MBPmFiSFLwIyY"+TempTest
+"Content-Disposition: form-data; name=\"header\""+TempTest+TempTest
+"Content-Type:application/x-www-form-urlencoded"+TempTest
+"------WebKitFormBoundarywX1MBPmFiSFLwIyY"+TempTest
+"Content-Disposition: form-data; name=\"parms\""+TempTest+TempTest
// +"client_user_id=-1&device_id=6DD40AF6-F48A-49C5-99DB-ELH1IK427FHA&language=zh-Hans&locale=CN&os=8.1.3&passwd=e10adc3949ba59abbe56e057f20f883e&phone=13432857155&phone_type=iPhone5s&sign=ZSC/GXJ4moja+o+Ia7MgCAXTp1g=&source=ios&timezone=%2B8&ver=2.9.28"+TempTest
+parms+TempTest
+"------WebKitFormBoundarywX1MBPmFiSFLwIyY"+TempTest
+"Content-Disposition: form-data; name=\"proxy\""+TempTest+TempTest
+"------WebKitFormBoundarywX1MBPmFiSFLwIyY"+TempTest
+"Content-Disposition: form-data; name=\"code\""+TempTest+TempTest
+"utf8"+TempTest
+"------WebKitFormBoundarywX1MBPmFiSFLwIyY--"+TempTest;
// strData = "url=" + URLEncoder.encode(setUrl, "UTF-8") + "&seltype="+seltype+"&ck=&header=Content-Type%3Aapplication%2Fx-www-form-urlencoded&proxy=&code=utf8&parms="+URLEncoder.encode(parms, "UTF-8");
// strData = "url=http%3A%2F%2Fapi.51yund.com%2Fsport%2Flogin&seltype=post&ck=&header=Content-Type%3Aapplication%2Fx-www-form-urlencoded&parms=client_user_id%3D42701325%26device_id%3D6DD40AF6-F48A-49C5-99DB-9D0F5117EFEF%26language%3Dzh-Hans%26locale%3DCN%26os%3D8.1.3%26passwd%3De10adc3949ba59abbe56e057f20f883e%26phone%3D13432857155%26phone_type%3DiPhone5s%26sign%3DaUWteyiJlrA5Iexeu2iCts13S2c%253D%26source%3Dios%26timezone%3D%252B8%26ver%3D2.9.28&proxy=&code=utf8";
sr = HttpRequest.sendPost(url, strData, hanHashMap);
// sr = HttpTookit.doPost(url, params, charset, pretty)
// System.out.println("HttpWebPost,strData= "+strData);
System.out.println("HttpWebPost,Request= "+sr);
JSONObject jsonObject = new JSONObject(sr);
String RetuenData = jsonObject.getJSONObject("data").getString("response");
System.out.println("HttpWebPost,data.response = "+RetuenData);
return RetuenData;
} catch (Exception e) {
e.printStackTrace();
}
return sr;
}
public static String HttpWebGet(String setUrl, String seltype){
HashMap hanHashMap = new HashMap();
hanHashMap.put("Accept", "application/json, text/javascript, */*; q=0.01");
hanHashMap.put("Content-Type", "application/x-www-form-urlencoded");
hanHashMap.put("X-Requested-With", "XMLHttpRequest");
hanHashMap.put("User-Agent", "Mozilla/4.0 (compatible; MSIE 9.0; Windows NT 6.1; 125LA; .NET CLR 2.0.50727; .NET CLR 3.0.04506.648; .NET CLR 3.5.21022)");
hanHashMap.put("Cache-Control", "no-cache");
//post get
String url = "http://coolaf.com/tool/ajaxgp";
String strData = "";
String sr = "";
try {
// strData = "method=POST&url="+URLEncoder.encode(setUrl, "UTF-8");
strData = "url=" + URLEncoder.encode(setUrl, "UTF-8") + "&seltype="+seltype+"&ck=&header=Content-Type%3Aapplication%2Fx-www-form-urlencoded&parms=&proxy=&code=utf8";
strData = "url=http%3A%2F%2Fapi.51yund.com%2Fsport%2Flogin%3Fsign%3DgrvcYdFotmj5YJbXsN92f4Ti%2Bww%3D%26passwd%3De10adc3949ba59abbe56e057f20f883e%26phone%3D13xxxxxxx%26source%3Dandroid_app%26phone_type%3DIdeaTabA2207A-H%26ver%3D3.1.2.6.226%26channel%3Dchannel_office%26client_user_id%3D-1&seltype=post&ck=&header=Content-Type%3Aapplication%2Fx-www-form-urlencoded&parms=&proxy=&code=utf8";
sr = HttpRequest.sendPost(url, strData, hanHashMap);
System.out.println(sr);
JSONObject jsonObject = new JSONObject(sr);
String RetuenData = jsonObject.getJSONObject("data").getString("response");
System.out.println(RetuenData);
// JSONObject StrTempjsonObject = new JSONObject(RetuenData).getJSONArray("infos").getJSONObject(0);
// System.out.println(StrTempjsonObject.getString("time"));
// System.out.println(StrTempjsonObject.getString("step"));
//
return RetuenData;
} catch (Exception e) {
e.printStackTrace();
}
return sr;
}
public static String HttpWebGet(String setUrl){
// "success": 1,
// "message":"2131232131231231"
// "header": "HTTP/1.1 200 OK\r\nServer: nginx\r\nDate: Tue, 10 May 2016 01:52:04 GMT\r\nContent-Type: application/json\r\nContent-Length: 1723\r\nConnection: close\r\nVary: Accept-Encoding\r\n\r\n",
// "code": 200,
// "time": 0.
// 测试
if(setUrl.equals(""))
setUrl = "http://api.51yund.com/sport/get_user_group_run_step?sign=VZbv32YKaSi4X/HOQWWjqu+hA6g=&end_cnt=20&begin_cnt=0&phone_type=LenovoK30&user_id=76223958&ver=3.1.2.8.343&channel=channel_wandoujia&client_user_id=76223958&xyy=3o412cqentvdzih6fkwglg8x7s";
HashMap hanHashMap = new HashMap();
hanHashMap.put("Accept", "*/*");
hanHashMap.put("Content-Type", "application/x-www-form-urlencoded");
hanHashMap.put("X-Requested-With", "XMLHttpRequest");
hanHashMap.put("User-Agent", "Mozilla/4.0 (compatible; MSIE 9.0; Windows NT 6.1; 125LA; .NET CLR 2.0.50727; .NET CLR 3.0.04506.648; .NET CLR 3.5.21022)");
hanHashMap.put("Cookie", "PHPSESSID=qlurko7774j0003ccpqlt084k3; Hm_lvt_b169f904ade5ef8ef30b1f93eb03f0ef=1466131046; Hm_lpvt_b169f904ade5ef8ef30b1f93eb03f0ef=1466131046; CNZZDATA5763499=cnzz_eid%3D758254695-1466130153-null%26ntime%3D1466130153; http_url=http%3A%2F%2Fapi.51yund.com%2Fsport%2Fget_user_group_run_step%3Fsign%3DVZbv32YKaSi4X%2FHOQWWjqu%2BhA6g%3D%26end_cnt%3D20%26begin_cnt%3D0%26phone_type%3DLenovoK30%26user_id%3D76223958%26ver%3D3.1.2.8.343%26channel%3Dchannel_wandoujia%26client_user_id%3D76223958%26xyy%3D3o412cqentvdzih6fkwglg8x7s; method=POST; params=; headers=");
hanHashMap.put("Cache-Control", "no-cache");
//POST GET
String url = "http://www.atool.org/include/httptest.inc.new.php";
String strData = "";
String sr = "";
try {
strData = "method=POST&url=" + URLEncoder.encode(setUrl, "UTF-8");
sr = HttpRequest.sendPost(url, strData, hanHashMap);
System.out.println("HttpWebGet url = "+setUrl);
if(sr.equals("")){
System.out.println("HttpWebGet data="+sr);
return sr;
}
JSONObject jsonObject = new JSONObject(sr);
String RetuenData = jsonObject.getString("message");
System.out.println(RetuenData);
// JSONObject StrTempjsonObject = new JSONObject(RetuenData).getJSONArray("infos").getJSONObject(0);
// System.out.println(StrTempjsonObject.getString("time"));
// System.out.println(StrTempjsonObject.getString("step"));
//
return RetuenData;
} catch (Exception e) {
e.printStackTrace();
}
return sr;
}
/**
* 获取微信关注密钥
* @param user_id 用户id
* @param xyy 登陆凭证
* @return 微信绑定二维码连接
* @throws Exception
*/
public static String fuwu(String user_id, String xyy) throws Exception{
//http://api.51yund.com/invite/get_wx_web_token_fuwu
//client_user_id=42390219&sign=HworQjC%2B3TLnxX1oT%2BxrRhe0bA8%3D&source=ios&ver=2.9.10&xyy=7qvgu5dv9lzxr8mn
HashMap paramHashMap = new HashMap();
paramHashMap.put("client_user_id", user_id);
paramHashMap.put("source", "ios");
paramHashMap.put("ver", "2.9.10");
// 加密
String strdata1 = a("POST","/invite/get_wx_web_token_fuwu", paramHashMap);
String sign = jiami(strdata1.getBytes("UTF-8"), strKey);
// 表单
String StrUrl = "http://api.51yund.com/invite/get_wx_web_token_fuwu";
String StrData = "client_user_id="+ user_id//42390219
+ "&sign="+ sign //HworQjC%2B3TLnxX1oT%2BxrRhe0bA8%3D
+ "&source=ios"
+ "&ver=2.9.10"
+ "&xyy="+ xyy;//7qvgu5dv9lzxr8mn
//发送 POST 请求1 获取微信连接
String strTokenData = HttpRequest.sendPost(StrUrl, StrData);
//System.out.println(strTokenData);
// json解析结果 token
JSONObject jsonObject = new JSONObject(strTokenData);
String strtoken = jsonObject.get("token").toString();
System.out.println(strtoken);
//*******************************************************************
// http://api.weixin.qq.com/device/create_qrcode?access_token=gE3w7eNdno3VIXOPmA-XduofIGE_ZWXdXyNA6fLiDtlhpKHyHSxyP_o8PY3afqJf9wjvRm_oFr2X6n8yi8gLWKMkYJpOZt-0V-BO1RRQQ18NRQcAIAGKJ
// {"device_num" : "1","device_id_list" : ["YD_42390219"]}
// 获取deviceid和二维码
String strurlWX = "http://api.weixin.qq.com/device/create_qrcode?access_token="+ strtoken;
String strdataWX = "{\"device_num\" : \"1\",\"device_id_list\" : [\"YD_"+ user_id +"\"]}";
//发送 POST 请求2
String strTokenData2 = HttpRequest.sendPost(strurlWX, strdataWX);
//System.out.println(strTokenData2);
// 利用deviceid更新设备属性
String bangdinUrl = "http://api.weixin.qq.com/device/authorize_device?access_token="+ strtoken;
String ydId = "YD_" + user_id;
String auth_key = MD5Util.MD5(ydId).toUpperCase();
String bangdinDat = "{\"device_list\":[{\"mac\":\"020000000000\",\"id\":\""
+ ydId + "\",\"connect_protocol\":\"4\",\"auth_ver\":\"0\",\"crypt_method\":\"0\",\"auth_key\":\""
+ auth_key + "\",\"conn_strategy\":\"4\",\"close_strategy\":\"1\",\"manu_mac_pos\":\"-1\",\"ser_mac_pos\":\"-2\"}],\"device_num\":\"1\"}";
String bangFanhui = HttpRequest.sendPost(bangdinUrl, bangdinDat); //发送 POST 请求3
System.out.println("绑定结果:"+bangFanhui);
// json解析结果 ticket 微信绑定二维码
jsonObject = new JSONObject(strTokenData2);
String strticket = jsonObject.getJSONArray("code_list").getJSONObject(0).get("ticket").toString();
System.out.println(user_id);
System.out.println(strticket);
System.out.println(auth_key);
//strticket = "";
return strticket;
}
/**
* 计算密钥 sign
* @param context
* @param key
* @return
* @throws Exception
*/
public static String jiami(byte[] context, String key) {
byte[] doFinal = null;
try {
// 一次加密
Mac localMac = Mac.getInstance("HmacSHA1"); // 类型
SecretKeySpec secretKeySpec = new SecretKeySpec(key.getBytes("UTF-8"), localMac.getAlgorithm());
localMac.init(secretKeySpec);
doFinal = localMac.doFinal(context);
} catch (Exception e) { }
// 二次加密
String encodeToString = Base64.getEncoder().encodeToString(doFinal);
//System.out.println(encodeToString);
return encodeToString;
}
public static String jiami(String context, String key) {
String encodeToString = "";
try {
byte[] Cont = context.getBytes("UTF-8");
// 一次加密
Mac localMac = Mac.getInstance("HmacSHA1"); // 类型
SecretKeySpec secretKeySpec = new SecretKeySpec(key.getBytes("UTF-8"), localMac.getAlgorithm());
localMac.init(secretKeySpec);
byte[] doFinal = localMac.doFinal(Cont);
// 二次加密
encodeToString = Base64.getEncoder().encodeToString(doFinal);
} catch (Exception e) { }
//System.out.println(encodeToString);
return encodeToString;
}
/**
* 加密2
* @param paramString1
* @param paramString2
* @param paramHashMap
* @param paramString3
* @return
* @throws Exception
*/
public static String a(String paramString1, String paramString2, HashMap paramHashMap, String paramString3)
throws Exception{
Mac localMac = Mac.getInstance("HmacSHA1");
SecretKeySpec secretKeySpec = new SecretKeySpec(paramString3.getBytes("UTF-8"), localMac.getAlgorithm());
localMac.init(secretKeySpec);
String encodeToString = Base64.getEncoder().encodeToString(localMac.doFinal(a(paramString1, paramString2, paramHashMap).getBytes("UTF-8")));
return encodeToString;
}
/**
* 加密1
* @param paramString1 方式
* @param paramString2 加密头
* @param paramHashMap 加密数数据
* @return
* @throws UnsupportedEncodingException
*/
public static String a(String paramString1, String paramString2, HashMap paramHashMap){
StringBuilder localStringBuilder = new StringBuilder(128);
try {
Object[] arrayOfObject = paramHashMap.keySet().toArray();
Arrays.sort(arrayOfObject);
localStringBuilder.append(paramString1.toUpperCase()).append("&").append(a(paramString2)).append("&");
StringBuilder paramString = new StringBuilder();
int i = 0;
while (i < arrayOfObject.length)
{
paramString.append(arrayOfObject[i]).append("=").append((String)paramHashMap.get(arrayOfObject[i]));
if (i != arrayOfObject.length - 1) {
paramString.append("&");
}
i += 1;
}
localStringBuilder.append(a(paramString.toString()));
} catch (Exception e) {}
return localStringBuilder.toString();
}
/**
* 加密3
* @param paramString
* @return
* @throws UnsupportedEncodingException
*/
public static String a(String paramString) throws UnsupportedEncodingException {
return URLEncoder.encode(paramString, "UTF-8").replace("+", "%20").replace("*", "%2A");
}
/**
* 获取今天时间
* @return 例如:20151220
*/
public static String onGetDate(){
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMdd"); //可以方便地修改日期格式yyyy/MM/dd HH:mm:ss
return dateFormat.format(new Date());
}
/**
* 获取时间10位
* @return
*/
public static String onGetDataN(){
Date date = new Date();
long time = date.getTime();
//mysq 时间戳只有10位 要做处理
String dateline = time + "";
dateline = dateline.substring(0, 10);
return dateline;
}
/**
* 把日期往后增加一天
* @param strDATE 整数往后推,负数往前移动
* @return 例如:20151220
*/
public static String onGetDate(int strDATE){
// 格式化
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMdd"); //可以方便地修改日期格式yyyy/MM/dd HH:mm:ss
// 时间
Date date = new Date();
// 时间修改
Calendar calendar = new GregorianCalendar();
calendar.setTime(date);
// 把日期往后增加一天.整数往后推,负数往前移动
calendar.add(Calendar.DATE, strDATE);
// 这个时间就是日期往后推一天的结果
date = calendar.getTime();
// 格式化结果
return dateFormat.format(date);
}
/**
* 指定时间区截止
* @param source 例如:20151220
* @return 例如:1450540800
* @throws ParseException
*/
public static String onGetDateMillis(String source) {
try {
DateFormat df = new SimpleDateFormat("yyyyMMdd"); // yyyy-MM-dd
Date date;
date = df.parse(source);
Calendar cal = Calendar.getInstance();
cal.setTime(date);
long timestamp = cal.getTimeInMillis()/1000;
return String.valueOf(timestamp);
} catch (ParseException e) {
e.printStackTrace();
System.out.println("指定时间区截止 onGetDateMillis 异常:"+e.toString());
}
return "0";
}
/**
* 判断是否是手机号
* @param mobiles
* @return
*/
public static boolean isMobileNO(String mobiles){
// Pattern p = Pattern.compile("^((13[0-9])|(15[^4,\\D])|(18[0,5-9]))\\d{8}$");
Pattern p = Pattern.compile("^1[3,4,5,6,7,8,9]\\d[\\s,-]?\\d{4}[\\s,-]?\\d{4}+$");
Matcher m = p.matcher(mobiles);
System.out.println(m.matches()+"---手机号判断");
return m.matches();
}
/**
* 判断是否是正确步数
* @param mobiles
* @return
*/
public static boolean isStepsNO(String mobiles){
Pattern p = Pattern.compile("^[1-9][0-9]{0,4}$");
Matcher m = p.matcher(mobiles);
System.out.println(m.matches()+"---判断是否是正确步数");
return m.matches();
}
/**
* 转账单号 31-32
* @param mobiles
* @return
*/
public static boolean is32NO(String mobiles){
Pattern p = Pattern.compile("^[0-9]{30,32}$");
Matcher m = p.matcher(mobiles);
System.out.println(m.matches()+"---判断是否是正确转账单号");
return m.matches();
}
/**
* 获取加密路径
* @param paramString
* @return
*/
private static String getPathOfUrl(String paramString)
{
if (paramString.indexOf("http://") != -1) {}
for (int i = paramString.indexOf("/", 8);; i = paramString.indexOf("/")) {
return paramString.substring(i);
}
}
}