package com.nos.java.action;
import java.util.ArrayList;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.HttpStatus;
import org.apache.commons.httpclient.NameValuePair;
import org.apache.commons.httpclient.methods.PostMethod;
import org.apache.commons.httpclient.methods.StringRequestEntity;
import org.apache.commons.httpclient.params.HttpMethodParams;
public class 参考HttpSmsUtil {
public static void main(String[] args) {
// System.out.println(new MD5().getMD5ofStr("kouyan12345").toLowerCase());
// testGetClient();
// senSmsTest();
/* testPool(); */
/* for(int i=0; i<5000; i++) {
new Thread(new Test()).start();
}*/
/* testYsy();
LoggerUtil.debug("****************************", "*******************************************");*/
// System.out.println(MD5Util.md5Hex("123456"));
// HttpSmsUtil.senSmsTest();
// HttpSmsUtil.testGetInvitedMeets();
// HttpSmsUtil.testHandShake();
// HttpSmsUtil.testYsyHandShake();
// HttpSmsUtil.testGetMobileKey();
// HttpSmsUtil.testRegCompMem();
// HttpSmsUtil.testfe();
}
public static void testPool() {
try {
HttpClient client = new HttpClient();//定义client对象
client.getParams().setParameter(HttpMethodParams.HTTP_CONTENT_CHARSET, "UTF-8");//指定传送字符集为GBK格式
client.getHttpConnectionManager().getParams().setConnectionTimeout(3000);//设置连接超时时间为2秒(连接初始化时间)
PostMethod method = new PostMethod("http://10.0.7.20/linkjm.action?cid=86243850&codeid=bcqpy");
// http://192.168.10.14:8080/wms/backPlant/mobileLogin/mGetgoodsList.action
int statusCode = client.executeMethod(method);
if (statusCode != HttpStatus.SC_OK) {
System.out.println("远程访问失败。");
}
System.out.println(method.getResponseBodyAsString());//输出反馈结果
}catch(Exception e) {
e.printStackTrace();
}
}
// public static void senSmsTest() {
// try {
// HttpClient client = new HttpClient();//定义client对象
// client.getParams().setParameter(HttpMethodParams.HTTP_CONTENT_CHARSET, "UTF-8");//指定传送字符集为GBK格式
// client.getHttpConnectionManager().getParams().setConnectionTimeout(2000);//设置连接超时时间为2秒(连接初始化时间)
// PostMethod method = new PostMethod("http://119.145.9.12/sendSMS.action");
// method.setRequestBody(new NameValuePair[] {
// new NameValuePair("enterpriseID" , "15591"),
// new NameValuePair("loginName" , "admin"),
// new NameValuePair("password" , MD5Util.md5Hex("kouyan12345").toLowerCase()),
// new NameValuePair("smsId" , ""),
// new NameValuePair("subPort" , "01"),
// new NameValuePair("content" , "hello sms!!"),
// new NameValuePair("mobiles" , "13725571493"),
// new NameValuePair("sendTime" , "")
// });
// int statusCode = client.executeMethod(method);
// if (statusCode != HttpStatus.SC_OK) {
// System.out.println("远程访问失败。");
// }
// System.out.println(method.getResponseBodyAsString());//输出反馈结果
// client.getHttpConnectionManager().closeIdleConnections(1);
// }catch(Exception e) {
// e.printStackTrace();
// }
// }
//
// public static void testGetClient() {
// try {
// HttpClient client = new HttpClient();//定义client对象
// client.getParams().setParameter(HttpMethodParams.HTTP_CONTENT_CHARSET, "UTF-8");//指定传送字符集为GBK格式
// client.getHttpConnectionManager().getParams().setConnectionTimeout(2000);//设置连接超时时间为2秒(连接初始化时间)
// PostMethod method = new PostMethod("http://10.0.7.20/servlet/getClientAccKey");
// String sb = "CRMT:LU1FRVRVUkw9MTAuMC43LjIwL3NlcnZsZXQvZ2V0Q2xpZW50QWNjS2V5Ci1NRUVUPTg2MjQzODUwOzgwMjA0YTA2MmMyYmFhOTM1MDYxNDY5ZWNiZDIyYjQxO0NMT1VEUk9PTQotQUNOVD0wOzQ7MDg4OGQ2MWI1MTRjMzFjZTI4ZDRhZjg2NWRmNzg5MzU7NjE2YzcwNjg2MTsKLUxBTkc9emhfQ04KLU1FRVRUWVBFPU1BSU4KLUxPR0NGRz0wCi1XRUJTVlI9MTAuMC43LjIwOzEwLjAuNy4yMDsxMC4wLjcuMjA=";
// /* InputStream body = new ByteArrayInputStream(sb.getBytes());
// method.setRequestBody(body);*/
// StringRequestEntity entity = new StringRequestEntity(sb,null,"UTF-8");
// method.setRequestEntity(entity);
// int statusCode = client.executeMethod(method);
// if (statusCode != HttpStatus.SC_OK) {
// System.out.println("远程访问失败。");
// }
// // System.out.println(method.getResponseBodyAsString());//输出反馈结果
// }catch(Exception e) {
// e.printStackTrace();
// }
// }
// //http://10.0.7.20/link_start.action?codeid=bcqmq&cid=27092130&retry=0&nickname=agent1
// public static void testJoinLink() {
// try {
// HttpClient client = new HttpClient();//定义client对象
// client.getParams().setParameter(HttpMethodParams.HTTP_CONTENT_CHARSET, "UTF-8");//指定传送字符集为GBK格式
// client.getHttpConnectionManager().getParams().setConnectionTimeout(2000);//设置连接超时时间为2秒(连接初始化时间)
// PostMethod method = new PostMethod("http://10.0.7.20/link_start.action?codeid=bcqpy&cid=86243850&retry=0&nickname=alpha");
// // String sb = "CRMT:LU1FRVRVUkw9MTAuMC43LjIwL3NlcnZsZXQvZ2V0Q2xpZW50QWNjS2V5Ci1NRUVUPTQwNDMxMjE5OzlkODE3ZGIxMGRjN2EyNTJlODhhMzk5OTFmOThlNmZmO0NMT1VEUk9PTQotQUNOVD0xMDAwMDAwMDM2OzE7NzU5YTRiZjAwYWRmZDA1NjQ5YjdlNjBjMTIyNjFlY2E7NjE2YzcwNjg2MTsKLUxBTkc9emhfQ04KLU1FRVRUWVBFPU1BSU4KLUxPR0NGRz0wCi1XRUJTVlI9MTAuMC43LjIwOzEwLjAuNy4yMDsxMC4xMS4xMi4xMzsxMC4wLjcuMjA=";
// /* InputStream body = new ByteArrayInputStream(sb.getBytes());
// method.setRequestBody(body);*/
// // StringRequestEntity entity = new StringRequestEntity(sb,null,"UTF-8");
// // method.setRequestEntity(entity);
// int statusCode = client.executeMethod(method);
// if (statusCode != HttpStatus.SC_OK) {
// System.out.println("远程访问失败。");
// }
// System.out.println(method.getResponseBodyAsString());//输出反馈结果
// }catch(Exception e) {
// e.printStackTrace();
// }
// }
//
// public static void testYsy() {
//
// try {
// HttpClient client = new HttpClient();//定义client对象
// client.getParams().setParameter(HttpMethodParams.HTTP_CONTENT_CHARSET, "UTF-8");//指定传送字符集为GBK格式
// client.getHttpConnectionManager().getParams().setConnectionTimeout(2000);//设置连接超时时间为2秒(连接初始化时间)
// PostMethod method = new PostMethod("http://127.0.0.1/si/auth/notice?streamingno=13221345&rand=2525&encode=3231");
// int statusCode = client.executeMethod(method);
// if (statusCode != HttpStatus.SC_OK) {
// System.out.println("远程访问失败。");
// }
// System.out.println(method.getResponseBodyAsString());//输出反馈结果
// }catch(Exception e) {
// e.printStackTrace();
// }
// }
//
// public static void testImgSrc() {
//
// try {
// HttpClient client = new HttpClient();//定义client对象
// client.getParams().setParameter(HttpMethodParams.HTTP_CONTENT_CHARSET, "UTF-8");//指定传送字符集为GBK格式
// client.getHttpConnectionManager().getParams().setConnectionTimeout(2000);//设置连接超时时间为2秒(连接初始化时间)
// PostMethod method = new PostMethod("http://localhost/news/81.html");
// int statusCode = client.executeMethod(method);
// if (statusCode != HttpStatus.SC_OK) {
// System.out.println("远程访问失败。");
// }
// System.out.println(method.getResponseBodyAsString());//输出反馈结果
//
// List<String> rest = getImgStr(method.getResponseBodyAsString());
// for(String rs : rest) {
// System.out.println("rs:"+rs);
// }
//
// }catch(Exception e) {
// e.printStackTrace();
// }
// }
//
// public static List<String> getImgStr(String htmlStr){
// String img="";
// Pattern p_image;
// Matcher m_image;
// List<String> pics = new ArrayList<String>();
//
// // String regEx_img = "<img.*src=(.*?)[^>]*?>"; //图片链接地址
//
// String regEx_img = "<img.*src\\s*=\\s*(.*?)[^>]*?>";
// p_image = Pattern.compile
// (regEx_img,Pattern.CASE_INSENSITIVE);
// m_image = p_image.matcher(htmlStr);
// while(m_image.find()){
// img = img + "," + m_image.group();
// // Matcher m = Pattern.compile("src=\"?(.*?)(\"|>|\\s+)").matcher(img); //匹配src
//
// Matcher m = Pattern.compile("src\\s*=\\s*\"?(.*?)(\"|>|\\s+)").matcher(img);
//
// while(m.find()){
// pics.add(m.group(1));
// }
// }
// return pics;
// }
//
//
// public static void testGetInvitedMeets() {
// try {
// HttpClient client = new HttpClient();//定义client对象
// client.getParams().setParameter(HttpMethodParams.HTTP_CONTENT_CHARSET, "UTF-8");//指定传送字符集为GBK格式
// client.getHttpConnectionManager().getParams().setConnectionTimeout(2000);//设置连接超时时间为2秒(连接初始化时间)
// PostMethod method = new PostMethod("http://10.0.0.136/servlet/GetInvitedMeets");
// /* method.setRequestBody(new NameValuePair[] {
// new NameValuePair("{RequestId" , "15591ss"),
// new NameValuePair("OEMKey" , "CLOUDROOM"),
// new NameValuePair("UserPswd" , new MD5().getMD5ofStr("123456").toLowerCase()),
// new NameValuePair("ClientVer" , "1.2.0"),
// new NameValuePair("UserName" , "
[email protected]}")
// }); */
// String sb = "{\"RequestId\":\"15591ss\",\"OEMKey\":\"CLOUDROOM\",\"UserPswd\":\""+MD5Util.md5Hex("123456").toLowerCase()+"\",\"ClientVer\":\"1.2.0\",\"UserName\":\"3261750121\"}";
// /* InputStream body = new ByteArrayInputStream(sb.getBytes());
// method.setRequestBody(body);*/
// StringRequestEntity entity = new StringRequestEntity(sb,null,"UTF-8");
// method.setRequestEntity(entity);
// int statusCode = client.executeMethod(method);
// if (statusCode != HttpStatus.SC_OK) {
// System.out.println("远程访问失败。");
// }
// System.out.println(method.getResponseBodyAsString());//输出反馈结果
// }catch(Exception e) {
// e.printStackTrace();
// }
// }
//
// public static void testHandShake() {
// try {
// HttpClient client = new HttpClient();//定义client对象
// client.getParams().setParameter(HttpMethodParams.HTTP_CONTENT_CHARSET, "UTF-8");//指定传送字符集为GBK格式
// client.getHttpConnectionManager().getParams().setConnectionTimeout(2000);//设置连接超时时间为2秒(连接初始化时间)
// PostMethod method = new PostMethod("http://10.0.7.20/servlet/HandShake");
// /* method.setRequestBody(new NameValuePair[] {
// new NameValuePair("{RequestId" , "15591ss"),
// new NameValuePair("OEMKey" , "CLOUDROOM"),
// new NameValuePair("UserPswd" , new MD5().getMD5ofStr("123456").toLowerCase()),
// new NameValuePair("ClientVer" , "1.2.0"),
// new NameValuePair("UserName" , "
[email protected]}")
// }); */
// String sb = "{\"RequestId\":\"15591ss\",\"OEMKey\":\"CLOUDROOM\",\"UserPswd\":\""+MD5Util.md5Hex("123456").toLowerCase()+"\",\"ClientVer\":\"1.2.0\",\"UserName\":\"3261750121\",\"MeetID\":\"12345678\",\"Status\":\"2\"}";
// /* InputStream body = new ByteArrayInputStream(sb.getBytes());
// method.setRequestBody(body);*/
// StringRequestEntity entity = new StringRequestEntity(sb,null,"UTF-8");
// method.setRequestEntity(entity);
// int statusCode = client.executeMethod(method);
// if (statusCode != HttpStatus.SC_OK) {
// System.out.println("远程访问失败。");
// }
// System.out.println(method.getResponseBodyAsString());//输出反馈结果
// }catch(Exception e) {
// e.printStackTrace();
// }
// }
//
//
// public static void testYsyHandShake() {
// try {
// HttpClient client = new HttpClient();//定义client对象
// client.getParams().setParameter(HttpMethodParams.HTTP_CONTENT_CHARSET, "UTF-8");//指定传送字符集为GBK格式
// client.getHttpConnectionManager().getParams().setConnectionTimeout(5000);//设置连接超时时间为2秒(连接初始化时间)
// PostMethod method = new PostMethod("http://www.189esy.cn:8080/FS-ECD-CLIENT/loginForPhone");
// /* method.setRequestBody(new NameValuePair[] {
// new NameValuePair("{RequestId" , "15591ss"),
// new NameValuePair("OEMKey" , "CLOUDROOM"),
// new NameValuePair("UserPswd" , new MD5().getMD5ofStr("123456").toLowerCase()),
// new NameValuePair("ClientVer" , "1.2.0"),
// new NameValuePair("UserName" , "
[email protected]}")
// }); */
// long epoch = System.currentTimeMillis()/1000;
// String sb = "{\"userid\":\"18906917784\",\"password\":\"654321a\",\"encrypted\":\"0\",\"imei\":\"359652053048984\",\"appid\":\"140002350000000000000011\",\"timestamp\":\""+epoch+"\",\"authenticator\":\""+MD5Util.ysymd5("18906917784"+"654321a"+"359652053048984"+"140002350000000000000011"+epoch+"5029C3055D51")+"\"}";
// // String sb = "{userid:'master@1163688247',password:'n3P//IKYRk1Q7TzGDZqp3g==',encrypted:'1',imei:'359652053048984',appid:'140002350000000000000011',timestamp:'1414999077',authenticator:'LHlgdJhqKiyrVrhJA/RLxA=='}";
// /* InputStream body = new ByteArrayInputStream(sb.getBytes());
// method.setRequestBody(body);*/
// StringRequestEntity entity = new StringRequestEntity(sb,"application/json","UTF-8");
// method.setRequestEntity(entity);
// int statusCode = client.executeMethod(method);
// if (statusCode != HttpStatus.SC_OK) {
// System.out.println("远程访问失败。");
// }
// System.out.println(method.getResponseBodyAsString());//输出反馈结果
// }catch(Exception e) {
// e.printStackTrace();
// }
// }
//
// public static void testGetMobileKey() {
// try {
// HttpClient client = new HttpClient();//定义client对象
// client.getParams().setParameter(HttpMethodParams.HTTP_CONTENT_CHARSET, "UTF-8");//指定传送字符集为GBK格式
// client.getHttpConnectionManager().getParams().setConnectionTimeout(2000);//设置连接超时时间为2秒(连接初始化时间)
// PostMethod method = new PostMethod("http://127.0.0.1/appws/app/register/getSmsKey");
//
// String sb = "{\"RequestId\":\"15591ss\",\"mobile\":\"13725571493\"}";
// StringRequestEntity entity = new StringRequestEntity(sb,"application/json","UTF-8");
//
// method.setRequestEntity(entity);
//
// int statusCode = client.executeMethod(method);
// if (statusCode != HttpStatus.SC_OK) {
// System.out.println("远程访问失败。");
// }
// System.out.println(method.getResponseBodyAsString());//输出反馈结果
// }catch(Exception e) {
// e.printStackTrace();
// }
// }
//
// public static void testRegCompMem() {
// try {
// HttpClient client = new HttpClient();//定义client对象
// client.getParams().setParameter(HttpMethodParams.HTTP_CONTENT_CHARSET, "UTF-8");//指定传送字符集为GBK格式
// client.getHttpConnectionManager().getParams().setConnectionTimeout(5000);//设置连接超时时间为2秒(连接初始化时间)
// PostMethod method = new PostMethod("http://127.0.0.1/appws/app/register/regmem");
// String sb = "{\"RequestId\":\"cccccccccc13213\",\"mobile\":\"13725571493\",\"compMobile\":\"17790090601\",\"identifyCode\":\"960925\"}";
// StringRequestEntity entity = new StringRequestEntity(sb,"application/json","UTF-8");
// method.setRequestEntity(entity);
// int statusCode = client.executeMethod(method);
// if (statusCode != HttpStatus.SC_OK) {
// System.out.println("远程访问失败。");
// }
// System.out.println(method.getResponseBodyAsString());//输出反馈结果
// }catch(Exception e) {
// e.printStackTrace();
// }
// }
//
// public static void testfe() {
// try {
// HttpClient client = new HttpClient();//定义client对象
// client.getParams().setParameter(HttpMethodParams.HTTP_CONTENT_CHARSET, "UTF-8");//指定传送字符集为GBK格式
// client.getHttpConnectionManager().getParams().setConnectionTimeout(5000);//设置连接超时时间为2秒(连接初始化时间)
// PostMethod method = new PostMethod("http://10.2.11.123/appws/app/cmpuser/adduser");
// String sb = "{\"RequestId\":\"cccccccccc13213\",\"mobile\":\"13725571493\",\"compMobile\":\"17790090601\",\"identifyCode\":\"960925\"}";
// StringRequestEntity entity = new StringRequestEntity(sb,"application/json","UTF-8");
// method.setRequestEntity(entity);
// int statusCode = client.executeMethod(method);
// if (statusCode != HttpStatus.SC_OK) {
// System.out.println("远程访问失败。");
// }
// System.out.println(method.getResponseBodyAsString());//输出反馈结果
// }catch(Exception e) {
// e.printStackTrace();
// }
// }
//
//}
class Test implements Runnable{
public void run() {
参考HttpSmsUtil.testPool();
// HttpSmsUtil.testGetClient();
// HttpSmsUtil.testJoinLink();
}
}
}