求助,谁做过微信小程序生成小程序码?

363 阅读1分钟

求助,谁做过微信小程序生成小程序码的功能?

我先用appId和secret获取access_tocken, 然后直接拿去获取微信小程序码就会报错,意思是tocken不是最新的。明明是上面刚刚获取到的。

代码如下:

  @Test
    public void httpTest() throws JSONException{
    	
        String url = "https://api.weixin.qq.com/cgi-bin/token";
        String params ="grant_type=client_credential&appid="+ appId +"&secret=" + secret;
        String result = HttpRequest.sendGet(url,params);
        System.out.println("---->");
        String tocken = result.toLowerCase();
        org.json.JSONObject json = new org.json.JSONObject(tocken);
        String tockenStr = json.getString("access_token");
        System.out.println("----------------------");
        System.out.println(tockenStr);
        String Codeurl = "https://api.weixin.qq.com/cgi-bin/wxaapp/createwxaqrcode?access_token=" + tockenStr;
        
        
        
        System.out.println(Codeurl);
        String codeParms = "page=/pages/index/index&width=200&scene=1&is_hyaline=false&auto_color=false&line_color={“r”:”0”,”g”:”0”,”b”:”0”}";
        String codeRes = HttpRequest.sendPost(Codeurl, codeParms);
        System.out.println("获取二维码成功!");
        System.out.println(codeRes);
        
    }

返回的结果如下:

{"errcode":40001,"errmsg":"invalid credential, access_token is invalid or not latest hint: [rumeza0465z782!]"}

tocken 是可以正常获取的。就是不知道哪个步骤出了问题。求大神帮忙解答啊!