1、添加设备
登录微信开发平台
2、开始添加设备
开始添加设备内容
最后直接添加就行
3、生成二维码
写一个http请求
package com.rinlink.intelligent.test;
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 getErWeiMA(String url, String charset, int timeout){
String result = "+";
try {
URL u = new URL(url);
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 (MalformedURLException e) {
return result;
} catch (IOException e) {
return result;
}
return result;
}
public static void main(String[] args) {
String url = "https://api.weixin.qq.com/device/getqrcode?access_token=ACCESS_TOKEN&product_id=PRODUCT_ID";
url = url.replace("ACCESS_TOKEN","De_ThXO0B_sknl5NXGAyP9LQrsj0gKE5lMZWDm-48Og79GvvakHXU-5AHqEzPI_u5AYQITXh0FE_Rawoz-KBDA-B6ZI15OnyY8F2BaG69S4PSNgAHACFA").replace("PRODUCT_ID", "38121");
String data = DeviceTest.getErWeiMA(url, "utf-8", 30000);
System.out.println("获取设备的deviceid和二维码:" + data);
}
}
替换你Token,注意Token时效只有两个小时,product_id取自设备图标的的5位数字。
可以采用微信提供测试工具获取Token:点击打开链接 ,注意要提供appid 和 secret
输入的结果:
获取设备的deviceid和二维码:{"base_resp":{"errcode":0,"errmsg":"ok"},"deviceid":"gh_ec691ba51b77_fa20ade3fc17675f","qrticket":"http:\/\/we.qq.com\/d\/AQB25GnBLdtAAv3C1Ngc8sZHwujMqgiAVTI1DDWp"}
如果Token过期显示:
获取设备的deviceid和二维码:+{"errcode":40001,"errmsg":"invalid credential, access_token is invalid or not latest"}
4、生成二维码 复制grticket的值