- 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号 可登陆公众号管理平台 硬件列表查询。
获取的二维码 是个地址字符串 需要读者用二维码生成器生成图片