轉:微信生成二維碼java

  1. package com.wepayweb.weixin.util.device;  
  2. /***  
  3.  * V型知識庫 www.vxzsk.com  
  4.  */  
  5. import java.io.BufferedReader;  
  6. import java.io.IOException;  
  7. import java.io.InputStreamReader;  
  8. import java.net.MalformedURLException;  
  9. import java.net.URL;  
  10. import java.net.URLConnection;  
  11. public class DeviceTest {  
  12.        
  13.     public static String sendGet(String url, String charset, int timeout)  
  14.       {  
  15.         String result = "";  
  16.         try  
  17.         {  
  18.           URL u = new URL(url);  
  19.           try  
  20.           {  
  21.             URLConnection conn = u.openConnection();  
  22.             conn.connect();  
  23.             conn.setConnectTimeout(timeout);  
  24.             BufferedReader in = new BufferedReader(new InputStreamReader(conn.getInputStream(), charset));  
  25.             String line="";  
  26.             while ((line = in.readLine()) != null)  
  27.             {  
  28.                
  29.               result = result + line;  
  30.             }  
  31.             in.close();  
  32.           } catch (IOException e) {  
  33.             return result;  
  34.           }  
  35.         }  
  36.         catch (MalformedURLException e)  
  37.         {  
  38.           return result;  
  39.         }  
  40.            
  41.         return result;  
  42.       }  
  43.    
  44.     /**  
  45.      * @param args  
  46.      */  
  47.     public static void main(String[] args) {  
  48.         // TODO Auto-generated method stub  
  49.         String access_token="";//  
  50.         String product_id="";  
  51.         String data = DeviceTest.sendGet("https://api.weixin.qq.com/device/getqrcode?access_token="+access_token+"&product_id="+product_id, "utf-8", 30000);  
  52.         System.out.println("獲取設備的deviceid和二維碼:"+data);  
  53.     }  
  54.    
  55. }  


執行main方法便可,access_token  和product_id 自行獲取,產品的id號 可登錄公衆號管理平臺 硬件列表查詢。java

 

獲取的二維碼 是個地址字符串 須要讀者用二維碼生成器生成圖片web

相關文章
相關標籤/搜索