|
|
@@ -20,6 +20,8 @@ import org.apache.http.impl.client.CloseableHttpClient; |
|
|
|
|
|
|
|
import java.io.File; |
|
|
|
import java.io.IOException; |
|
|
|
import java.util.regex.Matcher; |
|
|
|
import java.util.regex.Pattern; |
|
|
|
|
|
|
|
/** |
|
|
|
* Created by ecoolper on 2017/5/5. |
|
|
@@ -38,6 +40,8 @@ public class TtMediaUploadRequestExecutor implements RequestExecutor<String, Fil |
|
|
|
|
|
|
|
@Override |
|
|
|
public String execute(String uri, File file, WxType wxType) throws WxErrorException, IOException { |
|
|
|
String material_type = handleUrl(uri); |
|
|
|
|
|
|
|
HttpPost httpPost = new HttpPost(uri); |
|
|
|
if (requestHttp.getRequestHttpProxy() != null) { |
|
|
|
RequestConfig config = RequestConfig.custom().setProxy(requestHttp.getRequestHttpProxy()).build(); |
|
|
@@ -46,6 +50,7 @@ public class TtMediaUploadRequestExecutor implements RequestExecutor<String, Fil |
|
|
|
if (file != null) { |
|
|
|
HttpEntity entity = MultipartEntityBuilder |
|
|
|
.create() |
|
|
|
.addTextBody("material_type",material_type) |
|
|
|
.addBinaryBody("material_file", file) |
|
|
|
.setMode(HttpMultipartMode.RFC6532) |
|
|
|
.build(); |
|
|
@@ -63,5 +68,22 @@ public class TtMediaUploadRequestExecutor implements RequestExecutor<String, Fil |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
//material_type 并返回 |
|
|
|
private String handleUrl(String url){ |
|
|
|
String material_type = null; |
|
|
|
Pattern pXM = Pattern.compile("material_type=([^&]*)"); |
|
|
|
Matcher mXM = pXM.matcher(url); |
|
|
|
int i = 0; |
|
|
|
while (mXM.find()) { |
|
|
|
i++; |
|
|
|
material_type = mXM.group(1); |
|
|
|
} |
|
|
|
if(i > 1){ |
|
|
|
return null; |
|
|
|
} |
|
|
|
url = url.replaceAll("&?material_type=[^&]*",""); |
|
|
|
return material_type; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |