
com.yunpian.sdk.service.TplOperator Maven / Gradle / Ivy
package com.yunpian.sdk.service;
import com.google.gson.reflect.TypeToken;
import com.yunpian.sdk.common.Config;
import com.yunpian.sdk.common.YunpianException;
import com.yunpian.sdk.constants.YunpianConstants;
import com.yunpian.sdk.model.ResultDO;
import com.yunpian.sdk.model.TemplateInfo;
import com.yunpian.sdk.util.HttpUtil;
import com.yunpian.sdk.util.JsonUtil;
import java.lang.reflect.Type;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* Created by bingone on 16/1/19.
*/
public class TplOperator extends AbstractOperator {
private String apikey;
public TplOperator(String apikey) {
this.apikey = apikey;
}
public ResultDO> getDefault() {
return getDefault("");
}
public ResultDO> getDefault(final String tplId) {
return send(Config.URI_GET_DEFAULT_TPL_SMS, new HashMap() {{
put(YunpianConstants.TPL_ID, tplId);
}}, new TypeToken>() {
}.getType());
}
public ResultDO add(final String Tplcontent) {
return send(Config.URI_ADD_TPL_SMS, new HashMap() {{
put(YunpianConstants.TPL_CONTENT, Tplcontent);
}});
}
public ResultDO> get(final String tplId) {
return send(Config.URI_GET_TPL_SMS, new HashMap() {{
put(YunpianConstants.TPL_ID, tplId);
}}, new TypeToken>() {
}.getType());
}
public ResultDO> get() {
return get("");
}
public ResultDO update(final String tplId, final String Tplcontent) {
return send(Config.URI_UPD_TPL_SMS, new HashMap() {{
put(YunpianConstants.TPL_ID, tplId);
put(YunpianConstants.TPL_CONTENT, Tplcontent);
}});
}
public ResultDO del(final String tplId) {
return send(Config.URI_DEL_TPL_SMS, new HashMap() {{
put(YunpianConstants.TPL_ID, tplId);
}});
}
public ResultDO send(String url, Map parms) {
return send(url, parms, new TypeToken() {
}.getType());
}
public ResultDO send(String url, Map parms, Type t) {
ResultDO resultDO = new ResultDO();
parms.put(YunpianConstants.API_KEY, apikey);
try {
String ret = HttpUtil.post(url, parms);
resultDO.setData(JsonUtil.fromJson(ret, t));
resultDO.setSuccess(true);
} catch (Throwable e) {
resultDO.setE(e);
}
return resultDO;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy