复制番号代番号次のように:
private static String url = PropertiesLoader.getProperty("ALLYES_SERVER", false);
private static String ユーザー名 = PropertiesLoader.getProperty("ALLYES_USERNAME", false);
private static String パスワード = PropertiesLoader.getProperty("ALLYES_PASSWORD", false);
/**
* 追加创意
*
* @paramクリエイティブ監査
* @戻る
*/
public static Map<String, Object> addCreative(CreativeAudit CreativeAudit) {
//名前、幅、高さ、タイプ、クリエイティブタグID、コード、バインドId
文字列型 = "9";
if (creativeAudit.getRelative_path().toLowerCase().endsWith("gif"))
タイプ = "10";
if (creativeAudit.getRelative_path().toLowerCase().endsWith("swf"))
タイプ = "11";
Map<String, Object> 結果 = new HashMap<String, Object>();
文字列 addUrl = URL + "/creatives/add";
DefaultHttpClient httpClient = 新しい 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("高さ", 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("コード", CreativeAudit.getCode()));
postparams.add(new BasicNameValuePair("bindId", CreativeAudit.getGeoid()));
UrlEncodedFormEntity エンティティ = new UrlEncodedFormEntity(postparams, "UTF-8");
HttpPost httpPost = 新しい 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);
文字列 uuid = jsonObject.get("id").toString();
CreativeAudit.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("failed", "追加创意時提交データ有问题!");
}
/*
CreativeAudit.setUuid("189-"+creativeAudit.getGeoid());
result.put("成功",creativeAudit);
*/
結果を返します。
}