package com.qq.open.weibo;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import org.apache.http.entity.mime.MultipartEntity;
import org.apache.http.entity.mime.content.StringBody;
import com.qq.open.common.OpenQqConstants;
import com.qq.open.common.OpenQqUtils;
import com.qq.open.common.json.JSONException;
import com.qq.open.common.json.JSONObject;
import com.qq.open.weibo.bean.param.WeiBoDelParamBean;
import com.qq.open.weibo.bean.result.WeiBoDelResultBean;
/**
* 根据微博ID删除指定微博
*
* @author HaoLiang
*
*/
public class WeiBoDel {
/** QQ互联工具类 */
private OpenQqUtils oqu = new OpenQqUtils();
/**
* 根据微博ID删除指定微博
*
* @param paramBean 参数
* @return 接口返回的数据
* @throws JSONException
* @throws IOException
* @throws
*/
public WeiBoDelResultBean delT(WeiBoDelParamBean paramBean) throws JSONException, IOException {
// 请求接口返回json数据
String jsonData = oqu.doPost(OpenQqConstants.WEIBO_DEL_T_URL, this.getInterfaceData(paramBean));
return this.jsonToBean(jsonData);
}
/**
* 获取接口数据
*
* @param paramBean 参数
* @return 接口数据
* @throws UnsupportedEncodingException
*/
private MultipartEntity getInterfaceData(WeiBoDelParamBean paramBean) throws UnsupportedEncodingException {
MultipartEntity reqEntity = new MultipartEntity();
// AccessToken
reqEntity.addPart("access_token", new StringBody(paramBean
.getAccessToken()));
// AppId
reqEntity.addPart("oauth_consumer_key", new StringBody(oqu.getConfigValue("qq.appid")));
// Openid
reqEntity.addPart("openid", new StringBody(paramBean.getOpenId()));
// 定义API返回的数据格式
reqEntity.addPart("format", new StringBody("json"));
// 微博消息的ID
reqEntity.addPart("id", new StringBody(paramBean.getId()));
return reqEntity;
}
/**
* json数据转换成Bean数据
*
* @param jsonData 参数
* @return Bean数据
* @throws JSONException
*/
private WeiBoDelResultBean jsonToBean(String jsonData) throws JSONException {
WeiBoDelResultBean resultBean = new WeiBoDelResultBean();
JSONObject jsonObjRoot = new JSONObject(jsonData);
// 接口返回错误的场合
if (jsonObjRoot.getInt("ret") != 0) {
// 设置错误标识为真
resultBean.setErrorFlg(true);
// 设置错误编号
resultBean.setErrorCode(jsonObjRoot.get("errcode").toString());
// 设置错误内容
resultBean.setErrorMes(jsonObjRoot.getString("msg"));
}
return resultBean;
}
}