本文实例为大家分享了java实现上传网络图片到微信临时素材的具体代码,供大家参考,具体内容如下
package org.afuos.playcontrol.service;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import java.io.*;
import java.net.HttpURLConnection;
import java.net.URL;
/**
* Created by Mohon on 2017/8/10.
*/
public class UploadPicToWx {
/**
* 网络图片上传到微信服务器
*
* @param urlPath 图片路径
* @return JSONObject
* @throws Exception
*/
public String getMediaIdFromUrl(String urlPath, String fileType) throws Exception {
String result = null;
String url = "http://file.api.weixin.qq.com/cgi-bin/media/upload?access_token= Access_token &type=" + fileType + "";
String fileName = urlPath.substring(urlPath.lastIndexOf("/")