当前位置:首页 » 文件管理 » 微信上传api

微信上传api

发布时间: 2022-09-19 06:16:07

Ⅰ 如何把微信上(国产手机上它人发过来的)照片上传到apid上

登两个qq发过去

Ⅱ 怎么为微信公众号配置API接口

为微信公众号配置API接口难吗,怎么操作的呢,那么怎么为微信公众号配置API接口呢?下面是我收集整理的怎么为微信公众号配置API接口,希望对大家有帮助~~

为微信公众号配置API接口的方法

方法/步骤

复制我们为你生成的Url和Token

Ⅲ 微信的公众平台api怎样才能接入成功

1、进入微信公众平台后台,进入开发者中心
2、同意成为开发者
3、获得开发者appid和APPsecret 等开发数据
4、在你所进行开发的项目的服务器上做配置
5、获取你开发项目的服务器的 url和token,并填到微信公众平台的开发者中心。
6、微信公众平台api接入成功

Ⅳ 如何向微信服务器上传文件

在某些开发中,我们需要向微信服务器发送文件,比如图片,语音等等,借助微信服务器来实现我们的一些需求,具体的实现如下:

/**
* 向微信服务器上传文件
*
* @param accessToken
* 进入的接口
* @param type
* 文件类型(语音或者是图片)(对于文档不适合)
* @param url
* 文件的存储路径
* @return json的格式{"media_id":
* "nrSKG2eY1E__pdiNiSXuijbCmWWc8unzBQ"
* ,"created_at":1408436207,"type":"image"}
*/
public JSONObject uploadFile(String fileType, String filePath)
throws Exception {
GetExistAccessToken getExistAccessToken = GetExistAccessToken.getInstance();
String accessToken = getExistAccessToken.getExistAccessToken();
// 上传文件请求路径
String action = "http://file.api.weixin.qq.com/cgi-bin/media/upload?access_token="
+ accessToken + "&type=" + fileType;
URL url = new URL(action);
String result = null;
File file = new File(filePath);
if (!file.exists() || !file.isFile()) {
throw new IOException("上传的文件不存在");
}
HttpURLConnection con = (HttpURLConnection) url.openConnection();
con.setRequestMethod("POST"); // 以Post方式提交表单,默认get方式
con.setDoInput(true);
con.setDoOutput(true);
con.setUseCaches(false); // post方式不能使用缓存
// 设置请求头信息
con.setRequestProperty("Connection", "Keep-Alive");
con.setRequestProperty("Charset", "UTF-8");
// 设置边界
String BOUNDARY = "----------" + System.currentTimeMillis();
con.setRequestProperty("Content-Type", "multipart/form-data; boundary="
+ BOUNDARY);
// 请求正文信息
// 第一部分:
StringBuilder sb = new StringBuilder();
sb.append("--"); // 必须多两道线
sb.append(BOUNDARY);
sb.append("\r\n");
sb.append("Content-Disposition: form-data;name=\"file\";filename=\""
+ file.getName() + "\"\r\n");
sb.append("Content-Type:application/octet-stream\r\n\r\n");
byte[] head = sb.toString().getBytes("utf-8");
// 获得输出流
OutputStream out = new DataOutputStream(con.getOutputStream());
// 输出表头
out.write(head);
// 文件正文部分
// 把文件已流文件的方式 推入到url中
DataInputStream in = new DataInputStream(new FileInputStream(file));
int bytes = 0;
byte[] bufferOut = new byte[1024];
while ((bytes = in.read(bufferOut)) != -1) {
out.write(bufferOut, 0, bytes);
}
in.close();
// 结尾部分
byte[] foot = ("\r\n--" + BOUNDARY + "--\r\n").getBytes("utf-8");// 定义最后数据分隔线
out.write(foot);
out.flush();
out.close();
StringBuffer buffer = new StringBuffer();
BufferedReader reader = null;
try {
// 定义BufferedReader输入流来读取URL的响应
reader = new BufferedReader(new InputStreamReader(con
.getInputStream()));
String line = null;
while ((line = reader.readLine()) != null) {
buffer.append(line);
}
if (result == null) {
result = buffer.toString();
}
} catch (IOException e) {
System.out.println("发送POST请求出现异常!" + e);
e.printStackTrace();
throw new IOException("数据读取异常");
} finally {
if (reader != null) {
reader.close();
}
}
JSONObject jsonObj = new JSONObject(result);
return jsonObj;
}

Ⅳ 求助关于微信上传图片功能的API使用方法

localIds就已经可以预览了,不需要额外的操作了,serverId是一串普通字符串,而不是一个图片资源地址,不能用于预览吧。

Ⅵ 微信开发平台中有个接口是上传多媒体文件,我用的是java 开发的,我怎么样才能在后台实现呢代码如下:

/**
*文件上传到微信服务器
*@paramfileType文件类型
*@paramfilePath文件路径
*@returnJSONObject
*@throwsException
*/
publicstaticJSONObjectsend(StringfileType,StringfilePath)throwsException{
Stringresult=null;
Filefile=newFile(filePath);
if(!file.exists()||!file.isFile()){
thrownewIOException("文件不存在");
}
/**
*第一部分
*/
URLurlObj=newURL("http://file.api.weixin.qq.com/cgi-bin/media/upload?access_token="+getAccess_token()+"&type="+fileType+"");
HttpURLConnectioncon=(HttpURLConnection)urlObj.openConnection();
con.setRequestMethod("POST");//以Post方式提交表单,默认get方式
con.setDoInput(true);
con.setDoOutput(true);
con.setUseCaches(false);//post方式不能使用缓存
//设置请求头信息
con.setRequestProperty("Connection","Keep-Alive");
con.setRequestProperty("Charset","UTF-8");
//设置边界
StringBOUNDARY="----------"+System.currentTimeMillis();
con.setRequestProperty("Content-Type","multipart/form-data;boundary="+BOUNDARY);
//请求正文信息
//第一部分:
StringBuildersb=newStringBuilder();
sb.append("--");//必须多两道线
sb.append(BOUNDARY);
sb.append(" ");
sb.append("Content-Disposition:form-data;name="file";filename=""+file.getName()+"" ");
sb.append("Content-Type:application/octet-stream ");
byte[]head=sb.toString().getBytes("utf-8");
//获得输出流
OutputStreamout=newDataOutputStream(con.getOutputStream());
//输出表头
out.write(head);
//文件正文部分
//把文件已流文件的方式推入到url中
DataInputStreamin=newDataInputStream(newFileInputStream(file));
intbytes=0;
byte[]bufferOut=newbyte[1024];
while((bytes=in.read(bufferOut))!=-1){
out.write(bufferOut,0,bytes);
}
in.close();
//结尾部分
byte[]foot=(" --"+BOUNDARY+"-- ").getBytes("utf-8");//定义最后数据分隔线
out.write(foot);
out.flush();
out.close();
StringBufferbuffer=newStringBuffer();
BufferedReaderreader=null;
try{
//定义BufferedReader输入流来读取URL的响应
reader=newBufferedReader(newInputStreamReader(con.getInputStream()));
Stringline=null;
while((line=reader.readLine())!=null){
//System.out.println(line);
buffer.append(line);
}
if(result==null){
result=buffer.toString();
}
}catch(IOExceptione){
System.out.println("发送POST请求出现异常!"+e);
e.printStackTrace();
thrownewIOException("数据读取异常");
}finally{
if(reader!=null){
reader.close();
}
}
JSONObjectjsonObj=newJSONObject(result);
returnjsonObj;
}

Ⅶ 微信的公众平台api怎样才能接入成功呢

你能给我发一个连接微信Api的DEMO么!谢谢![email protected]

热点内容
Csharp在线编译 发布:2024-10-10 16:09:58 浏览:141
键值数据库存储图片 发布:2024-10-10 16:01:22 浏览:794
苹果手机设置了密码忘了怎么办 发布:2024-10-10 16:01:17 浏览:73
百视通tv怎么缓存视频 发布:2024-10-10 15:56:12 浏览:679
数据库删除全部数据 发布:2024-10-10 15:43:14 浏览:39
如何破解电脑密码win7 发布:2024-10-10 15:36:29 浏览:131
android视频p2p 发布:2024-10-10 15:16:06 浏览:715
python3scrapy爬虫 发布:2024-10-10 15:11:55 浏览:91
身份存储 发布:2024-10-10 14:51:29 浏览:535
ns2源码 发布:2024-10-10 14:46:42 浏览:565