package com.fenxiao.channel.quxun; import java.io.IOException; import java.util.Map; import org.apache.commons.httpclient.HttpClient; import org.apache.commons.httpclient.HttpException; import org.apache.commons.httpclient.methods.PostMethod; import org.apache.log4j.LogManager; import org.apache.log4j.Logger; import com.fenxiao.channel.qiannai.util.MD5Util; /** * 2.1.產品訂購 * @author wn * */ public class JiuDianjiuTest { @SuppressWarnings("unused") private Logger log = LogManager.getLogger(JiuDianjiuTest.class); @SuppressWarnings({ "rawtypes"}) public Object testOrder() throws HttpException,IOException{ String accountVal = "13301516477"; //手機號碼 String notifyUrl = "https://www.baidu.com/"; //通知回調地址 String orderNo = "23167771251045981811249827799033"; //渠道訂單編碼 String supplierId = "kedang201605042323erwg"; //渠道代碼 String spuId = "LT010020" ; //產品代碼 String ts = System.currentTimeMillis()+""; //時間戳 String sign = ""; //簽名 String key ="kedang0504"; //密鑰 //拼接成字符串 StringBuffer sb = new StringBuffer(); sb.append("accountVal").append(accountVal).append("notifyUrl").append( notifyUrl).append("orderNo") .append(orderNo).append("spuId").append(spuId).append("supplierId").append(supplierId).append("ts").append(ts).append(key); System.out.println("33333"+sb.toString()); sign = MD5Util.encrypt(sb.toString()); String url = "http://cz.9dian9.cn/u/stdchn/kedang/charge.xml"; //請求地址 HttpClient client = new HttpClient(); client.getParams().setContentCharset("UTF-8"); PostMethod postMethod = new PostMethod(url); String s = "supplierId="+supplierId+"&sign="+sign+"&spuId="+spuId+"&orderNo="+orderNo+"&accountVal="+accountVal+"¬ifyUrl="+notifyUrl+"&ts="+ts; System.out.println(s); postMethod.addParameter("supplierId", supplierId); // 商戶號 postMethod.addParameter("sign", sign); // 簽名 postMethod.addParameter("spuId", spuId); // 產品號 postMethod.addParameter("orderNo", orderNo); // 流水號 postMethod.addParameter("accountVal", accountVal); // 手機號 postMethod.addParameter("notifyUrl", notifyUrl); // 回調地址 postMethod.addParameter("ts", ts); // 日期 Map resultMap = null; client.executeMethod(postMethod); System.out.println(postMethod.getResponseBodyAsString()); return resultMap; } public static void main(String[] args) throws HttpException, IOException { JiuDianjiuTest test = new JiuDianjiuTest(); test.testOrder(); } }