复制代码代码如下:
private static String url = PropertiesLoader.getProperty("ALLYES_SERVER", false);
nama pengguna String statis pribadi = PropertiesLoader.getProperty("ALLYES_USERNAME", false);
kata sandi String statis pribadi = PropertiesLoader.getProperty("ALLYES_PASSWORD", false);
/**
* 添加创意
*
* @param creativeAudit
* @kembali
*/
peta statis publik<String, Objek> addCreative(CreativeAudit creativeAudit) {
//nama,lebar,tinggi,jenis,creativeTagId, kode,bindId
Tipe string = "9";
jika (creativeAudit.getRelative_path().toLowerCase().endsWith("gif"))
ketik = "10";
jika (creativeAudit.getRelative_path().toLowerCase().endsWith("swf"))
ketik = "11";
Peta<String, Objek> hasil = HashMap baru<String, Objek>();
String addUrl = url + "/kreatif/tambahkan";
DefaultHttpClient httpClient = baru DefaultHttpClient();
httpClient.getCredentialsProvider().setCredentials(AuthScope.ANY, UsernamePasswordCredentials baru(nama pengguna, kata sandi));
mencoba {
Daftar<NameValuePair> postparams = ArrayList baru<NameValuePair>();
postparams.add(BasisNameValuePair baru("nama", creativeAudit.getName()));
postparams.add(BasisNameValuePair baru("lebar", Integer.toString(creativeAudit.getWidth())));
postparams.add(BasisNameValuePair("tinggi", Integer.toString(creativeAudit.getHeight())));
postparams.add(BasisNameValuePair baru("tipe", tipe));
postparams.add(BasisNameValuePair baru("creativeTagId", creativeAudit.getAdCategory().getAd_caterory().substring(2)));
postparams.add(BasisNameValuePair baru("kode", creativeAudit.getCode()));
postparams.add(BasisNameValuePair baru("bindId", creativeAudit.getGeoid()));
Entitas UrlEncodedFormEntity = UrlEncodedFormEntity baru(postparams, "UTF-8");
HttpPost httpPost = HttpPost baru(addUrl);
httpPost.setEntity(entitas);
HttpResponse httpResponse = httpClient.execute(httpPost);
int statusCode = httpResponse.getStatusLine().getStatusCode();
jika (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();
creativeAudit.setUuid(uuid);
hasil.put("sukses", creativeAudit);
} kalau tidak {
HttpEntity httpEntity = httpResponse.getEntity();
String createResult = EntityUtils.toString(httpEntity, "UTF-8");
String errorMessage = "新增创意:" + creativeAudit.getGeoid() + "出错,状态码:" + statusCode + "; " + createResult;
hasil.put("gagal", errorMessage);
}
} catch (Pengecualian) {
ue.printStackTrace();
result.put("gagal", "添加创意时提交的数据有问题!");
}
/*
creativeAudit.setUuid("189-"+creativeAudit.getGeoid());
hasil.put("sukses",creativeAudit);
*/
hasil pengembalian;
}