复制代码代码如下:
私有静态字符串 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);
*/
返回结果;
}