use of com.creditease.uav.httpasync.api.ParaValuePair in project uavstack by uavorg.
the class SMSAction method run.
@Override
public boolean run(NotificationEvent notifyEvent) {
// 模板关键字
Map<String, String> keywords = new HashMap<String, String>();
String title = notifyEvent.getTitle();
long timeFlag = notifyEvent.getTime();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String sd = sdf.format(new Date(timeFlag));
keywords.put("custName", sd);
keywords.put("comName", title);
/**
* 若notifyEvent中包含目的地址,则用该地址;否则使用默认地址
*/
String sms = notifyEvent.getArg(cName);
if (StringHelper.isEmpty(sms)) {
if (log.isTraceEnable()) {
log.warn(this, "Send SMS FAIL as no any phone numbers.");
}
return false;
}
String[] phoneNums = sms.split(",");
for (String phone : phoneNums) {
List<ParaValuePair> nvps = new ArrayList<ParaValuePair>();
// 接口版本
nvps.add(new ParaValuePair("version", "3.0"));
// 批次号
nvps.add(new ParaValuePair("batchId", Long.toString(System.currentTimeMillis())));
// 组织机构号
nvps.add(new ParaValuePair("orgNo", "2265"));
// 模板号
nvps.add(new ParaValuePair("typeNo", "7209"));
// 关键字替换
nvps.add(new ParaValuePair("keywords", JSON.toJSONString(keywords)));
// 手机号
nvps.add(new ParaValuePair("mobile", phone));
if (log.isDebugEnable()) {
log.debug(this, "Send SMS START: phone=" + phone);
}
final String phoneNum = phone;
client.doAsyncHttpPost(baseUrl + "send", nvps, "utf-8", new HttpClientCallback() {
@Override
public void completed(HttpClientCallbackResult result) {
String results = result.getReplyDataAsString();
JSONObject jo = JSON.parseObject(results);
// 错误码
String code = jo.getString("code");
// 错误信息
String desc = jo.getString("desc");
if (log.isDebugEnable()) {
log.debug(this, "Send SMS END: phone=" + phoneNum + ",code=" + code + ",desc=" + desc);
}
}
@Override
public void failed(HttpClientCallbackResult result) {
String results = result.getReplyDataAsString();
log.err(this, "Send SMS FAIL: phone=" + phoneNum + ", result=" + results);
}
});
}
return true;
}
use of com.creditease.uav.httpasync.api.ParaValuePair in project uavstack by uavorg.
the class HttpAsyncClient method buildPostMethod.
private HttpUriRequest buildPostMethod(String url, List<ParaValuePair> nvps, String encoding) {
HttpUriRequest httpMethod;
httpMethod = new HttpPost(url);
if (null == nvps) {
return null;
}
List<BasicNameValuePair> bnvps = new ArrayList<>();
for (ParaValuePair pvp : nvps) {
BasicNameValuePair bnvp = new BasicNameValuePair(pvp.getName(), pvp.getValue());
bnvps.add(bnvp);
}
try {
((HttpPost) httpMethod).setEntity(new UrlEncodedFormEntity(bnvps, encoding));
} catch (UnsupportedEncodingException e) {
// ignore
httpMethod.abort();
} catch (Exception e) {
httpMethod.abort();
}
return httpMethod;
}
Aggregations