當前位置:首頁 » 文件管理 » 微信上傳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]

熱點內容
字母大小寫編程 發布:2024-10-10 17:25:40 瀏覽:630
安卓大陸用戶怎麼玩傳說對決 發布:2024-10-10 17:11:56 瀏覽:431
上傳照片登錄 發布:2024-10-10 17:00:27 瀏覽:828
用友nc伺服器的ip地址是什麼 發布:2024-10-10 17:00:27 瀏覽:292
雲伺服器雙線 發布:2024-10-10 16:52:18 瀏覽:163
python不重復隨機數 發布:2024-10-10 16:51:45 瀏覽:824
注塑機密碼多少 發布:2024-10-10 16:48:09 瀏覽:276
ptslinux 發布:2024-10-10 16:42:27 瀏覽:114
Csharp在線編譯 發布:2024-10-10 16:09:58 瀏覽:142
鍵值資料庫存儲圖片 發布:2024-10-10 16:01:22 瀏覽:795