收藏
回答

为撒通过access_token获取二维码图片无权限啊???求解

{"errcode":48001,"errmsg":"api unauthorized hint: [pYkR5a0316vr43!]"}




public class Test1 extends Thread {

private static WXkey key=null;

private static String access_token="";

private static int num=1;

public static void main(String[] args) throws Exception{

key=XmlWxkey.key("youpu_com",XmlWxkey.gzhypds);

for (int i = 0; i <9999; i++) {

new Test1().start();

}

}

public  void run(){

try {

getToken(key);

} catch (Exception e) { e.printStackTrace(); }

}

public static void getToken(WXkey key) throws Exception{  

if(num%444==0 || "".equals(access_token)){

String  loadurl="https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid="+

key.getAppId()+"&secret="+key.getAppSecret(); 

String jsonstr=url(loadurl,""); 

JSONObject json=JSONObject.fromObject(jsonstr); 

access_token=Convert.filter(json.get("access_token"));

} getCodeImg(access_token);

}

public static void getCodeImg(String access_token) throws Exception{

String loadurl="https://api.weixin.qq.com/cgi-bin/wxaapp/createwxaqrcode?access_token="+access_token;

JSONObject json=new JSONObject();

json.put("path","pag/index/index");json.put("width",400);

String jsonstr=WXurl.url(loadurl,json.toString());   

System.out.println(jsonstr);

}

public static String url(String url,String where)throws Exception{

String result="";

URL address=new URL(url);  

HttpURLConnection uc=(HttpURLConnection)address.openConnection();

uc.setRequestProperty("Charsert", "UTF-8"); 

uc.setRequestProperty("Accept", "*/*");

uc.setRequestProperty("Content-Type", "application/json");

uc.setRequestProperty("connection", "Keep-Alive");

uc.setRequestProperty("User-Agent", "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0) ");

uc.setRequestMethod("POST"); 

uc.setDoOutput(true);

OutputStream os = uc.getOutputStream(); 

os.write(where.getBytes());  // &password=admin

os.close();  

uc.connect(); 

InputStream inputStream=uc.getInputStream();

InputStreamReader inputStreamReader=new InputStreamReader(inputStream,"utf8");

BufferedReader news=new   BufferedReader(inputStreamReader);

String  line=news.readLine();

while (line!=null)   { 

result+=line; line=news.readLine(); 

news.close();

inputStreamReader.close();

inputStream.close();

return result;

}

}


回答关注问题邀请回答
收藏
登录 后发表内容