- package com.wepayweb.weixin.util.device;
- /***
- * V型知識庫 www.vxzsk.com
- */
- import java.io.BufferedReader;
- import java.io.IOException;
- import java.io.InputStreamReader;
- import java.net.MalformedURLException;
- import java.net.URL;
- import java.net.URLConnection;
- public class DeviceTest {
-
- public static String sendGet(String url, String charset, int timeout)
- {
- String result = "";
- try
- {
- URL u = new URL(url);
- try
- {
- URLConnection conn = u.openConnection();
- conn.connect();
- conn.setConnectTimeout(timeout);
- BufferedReader in = new BufferedReader(new InputStreamReader(conn.getInputStream(), charset));
- String line="";
- while ((line = in.readLine()) != null)
- {
-
- result = result + line;
- }
- in.close();
- } catch (IOException e) {
- return result;
- }
- }
- catch (MalformedURLException e)
- {
- return result;
- }
-
- return result;
- }
-
- /**
- * @param args
- */
- public static void main(String[] args) {
- // TODO Auto-generated method stub
- String access_token="";//
- String product_id="";
- String data = DeviceTest.sendGet("https://api.weixin.qq.com/device/getqrcode?access_token="+access_token+"&product_id="+product_id, "utf-8", 30000);
- System.out.println("獲取設備的deviceid和二維碼:"+data);
- }
-
- }
執行main方法便可,access_token 和product_id 自行獲取,產品的id號 可登錄公衆號管理平臺 硬件列表查詢。java
獲取的二維碼 是個地址字符串 須要讀者用二維碼生成器生成圖片web