|
@@ -1,24 +1,24 @@
|
|
|
package me.chanjar.weixin.mp.util.requestexecuter.material;
|
|
|
|
|
|
-import java.io.IOException;
|
|
|
-
|
|
|
-import org.slf4j.Logger;
|
|
|
-import org.slf4j.LoggerFactory;
|
|
|
-
|
|
|
+import com.google.common.collect.ImmutableMap;
|
|
|
import me.chanjar.weixin.common.WxType;
|
|
|
import me.chanjar.weixin.common.error.WxError;
|
|
|
import me.chanjar.weixin.common.error.WxErrorException;
|
|
|
import me.chanjar.weixin.common.util.http.RequestHttp;
|
|
|
import me.chanjar.weixin.common.util.http.ResponseHandler;
|
|
|
import me.chanjar.weixin.common.util.http.okhttp.OkHttpProxyInfo;
|
|
|
-import okhttp3.FormBody;
|
|
|
-import okhttp3.OkHttpClient;
|
|
|
-import okhttp3.Request;
|
|
|
-import okhttp3.RequestBody;
|
|
|
-import okhttp3.Response;
|
|
|
+import me.chanjar.weixin.common.util.json.WxGsonBuilder;
|
|
|
+import okhttp3.*;
|
|
|
+import org.slf4j.Logger;
|
|
|
+import org.slf4j.LoggerFactory;
|
|
|
+
|
|
|
+import java.io.IOException;
|
|
|
|
|
|
/**
|
|
|
- * Created by ecoolper on 2017/5/5.
|
|
|
+ * .
|
|
|
+ *
|
|
|
+ * @author ecoolper
|
|
|
+ * @date 2017/5/5
|
|
|
*/
|
|
|
public class MaterialDeleteOkhttpRequestExecutor extends MaterialDeleteRequestExecutor<OkHttpClient, OkHttpProxyInfo> {
|
|
|
private final Logger logger = LoggerFactory.getLogger(this.getClass());
|
|
@@ -28,25 +28,25 @@ public class MaterialDeleteOkhttpRequestExecutor extends MaterialDeleteRequestEx
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public void execute(String uri, String data, ResponseHandler<Boolean> handler, WxType wxType) throws WxErrorException, IOException {
|
|
|
+ public void execute(String uri, String data, ResponseHandler<Boolean> handler, WxType wxType)
|
|
|
+ throws WxErrorException, IOException {
|
|
|
handler.handle(this.execute(uri, data, wxType));
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public Boolean execute(String uri, String materialId, WxType wxType) throws WxErrorException, IOException {
|
|
|
logger.debug("MaterialDeleteOkhttpRequestExecutor is running");
|
|
|
- //得到httpClient
|
|
|
- OkHttpClient client = requestHttp.getRequestHttpClient();
|
|
|
|
|
|
- RequestBody requestBody = new FormBody.Builder().add("media_id", materialId).build();
|
|
|
+ RequestBody requestBody = RequestBody.create(MediaType.parse("application/json"),
|
|
|
+ WxGsonBuilder.create().toJson(ImmutableMap.of("media_id", materialId)));
|
|
|
Request request = new Request.Builder().url(uri).post(requestBody).build();
|
|
|
- Response response = client.newCall(request).execute();
|
|
|
+ Response response = requestHttp.getRequestHttpClient().newCall(request).execute();
|
|
|
String responseContent = response.body().string();
|
|
|
WxError error = WxError.fromJson(responseContent, WxType.MP);
|
|
|
if (error.getErrorCode() != 0) {
|
|
|
throw new WxErrorException(error);
|
|
|
- } else {
|
|
|
- return true;
|
|
|
}
|
|
|
+
|
|
|
+ return true;
|
|
|
}
|
|
|
}
|