複製程式碼如下:
私有靜態字串 url = PropertiesLoader.getProperty("ALLYES_SERVER", false);
私有靜態字串使用者名稱 = PropertiesLoader.getProperty("ALLYES_USERNAME", false);
私有靜態字串密碼 = PropertiesLoader.getProperty("ALLYES_PASSWORD", false);
/**
* 創作創意
*
* @param創意審計
* @返回
*/
公共靜態Map <字串,物件> addCreative(CreativeAudit CreativeAudit){
//名稱、寬度、高度、型別、creativeTagId、程式碼、bindId
字串型別=“9”;
if (creativeAudit.getRelative_path().toLowerCase().endsWith("gif"))
類型=“10”;
if (creativeAudit.getRelative_path().toLowerCase().endsWith("swf"))
類型=“11”;
Map<String, Object> 結果 = new HashMap<String, Object>();
String addUrl = url + "/creatives/add";
DefaultHttpClient httpClient = new DefaultHttpClient();
httpClient.getCredentialsProvider().setCredentials(AuthScope.ANY, new UsernamePasswordCredentials(使用者名稱, 密碼));
嘗試 {
List<NameValuePair> postparams = new ArrayList<NameValuePair>();
postparams.add(new BasicNameValuePair(“名稱”,creativeAudit.getName()));
postparams.add(new BasicNameValuePair("width", Integer.toString(creativeAudit.getWidth())));
postparams.add(new BasicNameValuePair("height", Integer.toString(creativeAudit.getHeight())));
postparams.add(new BasicNameValuePair("type", type));
postparams.add(new BasicNameValuePair("creativeTagId",creativeAudit.getAdCategory().getAd_caterory().substring(2)));
postparams.add(new BasicNameValuePair("code",creativeAudit.getCode()));
postparams.add(new BasicNameValuePair(“bindId”,creativeAudit.getGeoid()));
UrlEncodedFormEntity 實體 = new UrlEncodedFormEntity(postparams, "UTF-8");
HttpPost httpPost = new HttpPost(addUrl);
httpPost.setEntity(實體);
HttpResponse httpResponse = httpClient.execute(httpPost);
int statusCode = httpResponse.getStatusLine().getStatusCode();
if (statusCode == HttpStatus.SC_OK) {
HttpEntity httpEntity = httpResponse.getEntity();
String createResult = EntityUtils.toString(httpEntity, "UTF-8");
JSONObject jsonObject = JSONObject.fromObject(createResult);
String uuid = jsonObject.get("id").toString();
創意審核.setUuid(uuid);
result.put("成功", CreativeAudit);
} 別的 {
HttpEntity httpEntity = httpResponse.getEntity();
String createResult = EntityUtils.toString(httpEntity, "UTF-8");
String errorMessage = "新增創意:" + CreativeAudit.getGeoid() + "錯誤、狀態碼:" + statusCode + "; " + createResult;
result.put("失敗", errorMessage);
}
} catch (異常ue) {
ue.printStackTrace();
result.put("失敗", "新增創意時提交的資料有問題!");
}
/*
CreativeAudit.setUuid("189-"+creativeAudit.getGeoid());
result.put("成功",creativeAudit);
*/
返回結果;
}