import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.Socket;
import java.net.URLEncoder;
import java.util.Date;

import org.apache.http.HttpResponse;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.DefaultHttpClient;

import net.sf.json.JSONObject;

public class PostTest {
	
	public static void main1(String[] args) throws ClientProtocolException, IOException{
		Socket obj=new Socket("10.8.18.151",8088);
		System.out.println(obj.getLocalAddress());
	} 
	public static void main(String[] args) throws ClientProtocolException, IOException{
		System.out.println(new Date());
		String servlet="asnReceiveServlet";//loginApp,scanDomestic,asnReceiveServlet(装车卸货回单),pickingServlet(下单界面数据提取),queryInvServlet(保存下单信息),

		String ip="192.168.56.175:";//"192.168.56.175:  47.100.54.81:";
		String prot="8080/KAMS";//http://47.100.54.81:81/kams//"8080/KAMS
		String url ="http://"+ip+prot+"/"+"appService/"
				+ servlet;
		System.out.println(url);
		HttpClient httpclient = null;
		HttpPost httpPost = new HttpPost(url);
		httpclient = new DefaultHttpClient();
		JSONObject params = new JSONObject();
		String method_type="queryRkDetailList";
		try {
			if(servlet.equals("loginApp")){
				params.put("loginName", "admin");
				params.put("passWord", "admin");
			}else if(servlet.equals("scanDomestic")){
				params.put("key", "981PR65166151130        1114062090204202111170000050K0002       00325 JA0354NA0533001");//
			}else if(servlet.equals("asnReceiveServlet")){
				if(method_type.equals("queryRkList")){
					 params.put("queryInfo", "");
				 }else if(method_type.equals("scanRkLp")){
					 params.put("jzxh", "OOCU9021598-测试");
					 params.put("fph", "");
					 params.put("tph", "23/01-A-1");
				 }else if(method_type.equals("scanRkKey")){
					 params.put("item_code", "3C08117101");
					 params.put("xpp", "9813C08117101700090     111506055561220211025     4872000       00609 UC3A32B10700");
				 }else if(method_type.equals("scanRkDstLoc")){
					 params.put("dst_loc", "C1库/中部品");
					 params.put("xpp", "9813C08117101700090     111506055561220211025     4872000       00609 UC3A32B10707");
					 params.put("d_id", "109007");
					 params.put("pf_id", "4566");
					 params.put("qty", "48");
					 params.put("jzxh", "OOCU9021598-测试");
					 params.put("fph", "");
				 }else if(method_type.equals("queryRkDetailList")){
					 params.put("jzxh", "OOCU9021598-测试");
					 params.put("fph", "");
				 }
			}else if(servlet.equals("ediServlet")){
				//
				 if(method_type.equals("queryBhList")){
					 params.put("queryInfo", "");
				 }else if(method_type.equals("scanKey")){
					 params.put("key", "981PG00188511130        2032064744071202203010000080P0007       P0004             001");
					 params.put("pId", "174");
				 }else if(method_type.equals("confirmPick")){
					 params.put("key", "981PG00188511130        2032064744071202203010000080P0007       P0004             001");
					 params.put("pId", "165");
					 params.put("pptdId", "3818");
					 params.put("ptdId", "2555");
//					 params.put("ckType", "XPP");
					 params.put("ckType", "QTCK");
					 params.put("itemCode", "PG00111821");
					 params.put("shsl", "100");
				 }else if(method_type.equals("queryBhDetailList")){
					 params.put("pId", "174");
				 }else if(method_type.equals("queryBhXppDetailList")){
					 params.put("pId", "174");
				 }else if(method_type.equals("queryFhList")){
					 params.put("queryInfo", "");
				 }else if(method_type.equals("queryFhDetailList")){
					 params.put("pId", "174");
				 }else if(method_type.equals("scanItemCode")){
					 params.put("pId", "165");
					 params.put("itemCode", "PG00111821");
				 }else if(method_type.equals("confirmShip")){
					 params.put("pId", "165");
				 }else if(method_type.equals("confirmPickForDetail")){
					 params.put("pId", "168");
					 params.put("ptdId", "2594");
					 params.put("bhQty", "20");
				 }else if(method_type.equals("confirmPickALL")){
					 params.put("pId", "168");
				 }
			}
			params.put("methodType", method_type);
//			params.put("type", 1);
//			params.put("wId", 1);
//			params.put("workerId", 1080);
		    StringEntity stringEntity = new StringEntity(params.toString(),"utf-8");
		    httpPost.setEntity(stringEntity);
		    HttpResponse re = httpclient.execute(httpPost);
			System.out.println(re.getStatusLine()+params.toString());
			 if (re.getStatusLine().getStatusCode()==200){    
//				 String strResult = EntityUtils.toString(re.getEntity());
//				 System.out.println(strResult);
			 }
		} catch (ClientProtocolException e) {
			e.printStackTrace();
		}
	}
	static JSONObject getAsn(JSONObject params,String method_type) throws UnsupportedEncodingException{
			if(method_type.equals("scanAsnCode")){
				params.put("asn_code", "RP201200031");
			}else if(method_type.equals("scanLocationPut")){
				params.put("loc_code", "JS32L2");
			}else if(method_type.equals("getAsnDetails")){
				params.put("asn_id", 6408);
			}else if(method_type.equals("scanItemCode")){
				params.put("asn_id", 6408);
				params.put("item_code", "VD03");
			}else if(method_type.equals("receiveConfirm")){
				params.put("asn_id", 6408);
				params.put("asn_detail_id", 12411);
				params.put("case_qty", 0);
				params.put("put_qty", 3);
				params.put("pc1", "");
				params.put("pd1", "");
				params.put("inv_status", "");
				params.put("loc_id", 28250);
				params.put("lp_code", "");
				params.put("temperature", "");
				params.put("bar_code", "");
				params.put("weight", 0);
			}
			
			return params;
		}
	static JSONObject getPick(JSONObject params,String method_type) throws UnsupportedEncodingException{
		if(method_type.equals("getPickForWorker")){
			params.put("pick_code", "");
		}else if(method_type.equals("getPickDetails")){
			params.put("pt_id", 27879);
		}else if(method_type.equals("pickConfirm")){
			params.put("task_id", 180992);
			params.put("case_qty", 0);
			params.put("pick_qty", 300);
		}else if(method_type.equals("getBarCode")){
			params.put("task_id", 180992);
			params.put("pt_id", 27879);
			params.put("bar_code", "8017948016101");
		}else if(method_type.equals("refreshPickCode")){
			params.put("pt_id", 27879);
		}else if(method_type.equals("refreshTask")){
			params.put("pt_id", 27879);
		}else if(method_type.equals("activePickTicketDetail")){
			params.put("ptd_id", 968192);
		}
		
		return params;
	}
	
}
