//POST================================
public JSONObject sendPostToMobileForQ(HttpServletRequest request, LlyOrder LlyOrder, String BipActivityCode){
JSONObject jsonObject = new JSONObject();
JSONObject json = new JSONObject();
// 1. 创建HttpClient对象
CloseableHttpClient httpClient = HttpClientBuilder.create().build();
// 2. 创建HttpPost对象
HttpPost post = new HttpPost("http://antiresaletest.i139.cn/tftc_order_intf_h5/confirm/v1");
// 3. 设置POST请求传递参数
//随机数
String nonce = llyUtils.getRund();
//创建时间 格式"yyyy-MM-dd'T'HH:mm:ss'Z'".
String created = llyUtils.getCreate();
//密码摘要
System.out.println("==========向移动确认订购开始============");
System.out.println("LlyOrder.getOrderNo()======================"+LlyOrder.getOrderNo());
System.out.println("LlyOrder.getMobile()======================"+LlyOrder.getMobile());
System.out.println("BipActivityCode======================"+BipActivityCode);
System.out.println("LlyOrder.getProductCode()======================"+LlyOrder.getProductCode());
String passworddigest = EncryptionToDecryptUtil.getBase64((EncryptionToDecryptUtil.String2SHA256(nonce+created+SECRET_KEY+(LlyOrder.getOrderNo()+LlyOrder.getMobile()+BipActivityCode+LlyOrder.getProductCode())+prodid)));
json.put("passworddigest",passworddigest);
json.put("nonce",EncryptionToDecryptUtil.getBase64(nonce));
json.put("created",created);
json.put("prodid",prodid);
System.out.println("EncryptionToDecryptUtil.getBase64(nonce)======================"+EncryptionToDecryptUtil.getBase64(nonce));
System.out.println("passworddigest======================"+passworddigest);
//认证token
post.addHeader("Authorization", json.toString());
post.addHeader("BipCode", "BIP4B003");
post.addHeader("ActivityCode", "T4011140");
post.addHeader("OrderId", LlyOrder.getOrderNo());
post.addHeader("ProductID", prodid);
post.addHeader("content-Type", "application/json;charset=utf-8");
JSONObject param =new JSONObject();
param.put("OrderId",LlyOrder.getOrderNo());
param.put("MobNum",LlyOrder.getMobile());
param.put("BipActivityCode",String.valueOf(LlyOrder.getOrderType()));
param.put("UserPackage",LlyOrder.getProductCode());
param.put("UsageLimit","");
param.put("TransParams","");
param.put("srcTransId","");
try {
StringEntity se = new StringEntity(param.toString(), "utf-8");
post.setEntity(se);
// 4. 执行请求并处理响应
CloseableHttpResponse responsess = httpClient.execute(post);
HttpEntity entitys = responsess.getEntity();
if (entitys != null){
String entitystr = EntityUtils.toString(entitys);
System.out.println("entitystr================================"+entitystr);
jsonObject = JSONObject.fromObject(entitystr);
System.out.println("移动返回参数================================"+jsonObject.toString());
System.out.println("==============向移动确认结束==================");
}
responsess.close();
}catch (IOException e){
LoggerService.addErrorLog(request,e);
e.printStackTrace();
}finally {
// 释放资源
try {
httpClient.close();
} catch (IOException e) {
e.printStackTrace();
}
}
return jsonObject;
}
//GET==================================================
String url = "http://XXXX";
JSONObject json = new JSONObject();
CloseableHttpClient httpclient = HttpClients.createDefault();
CloseableHttpResponse responses = null;
String resultUrl = "";//接收请求返回的结果
try {
String urlName = url + "&"+"MobNum="+MobNum + "&UserPackage="+productCode;
HttpGet httpget = new HttpGet(urlName);
//认证token
httpget.addHeader("Authorization", json.toString());
httpget.addHeader("BipCode", BipCode);
httpget.addHeader("ActivityCode", ActivityCode);
httpget.addHeader("OrderId", LlyOrder.getOrderNo());
httpget.addHeader("ProductID", prodid);
httpget.addHeader("content-Type", "application/json;charset=utf-8");
//发送httpget请求
responses = httpclient.execute(httpget);
int result =responses.getStatusLine().getStatusCode();
//判断
if (result== HttpStatus.SC_OK){
resultUrl = EntityUtils.toString(responses.getEntity(),"utf-8");
}
} catch (Exception e) {
e.printStackTrace();
}
// 使用finally块来关闭输入流
finally {
// 6. 释放资源
try {
responses.close();
httpclient.close();
} catch (IOException e) {
e.printStackTrace();
}
}