微信公众号获取带参数的二维码

    public void publicQR(
            HttpServletResponse response,HttpServletRequest request,@RequestBody String dataid) {
        ResultMap map = new ResultMap();
        try {
            JSONObject jsondata = JSONObject.fromObject(dataid);
            String udid = jsondata.getString("参数");
            if(MyUtil.isEmpty(“”参数“”)) {
                map.setState(ResultMap.ERROR);
                map.setMsg("参数不能为空");
                return map;
            }
            String url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid="+appid+"&secret="+secret;
            String resultStr = HttpHelper.httpGet(url,null);
            System.out.println("resultStr"+resultStr);
            JSONObject json = JSONObject.fromObject(resultStr);
            String token = json.getString("access_token");
            System.out.println("access_token"+token);
            String qrUrl = "https://api.weixin.qq.com/cgi-bin/qrcode/create?access_token="+token;
            Map<String,String> idMap = new HashMap<String,String>();
                idMap.put("scene_str", "参数");
            Map<String,Object> scenMap = new HashMap<String,Object>();
                scenMap.put("scene", idMap);
            Map<String,Object> param = new HashMap<String,Object>();
            String expire_seconds ="10000";
            String action_name = "QR_STR_SCENE";
                param.put("expire_seconds", expire_seconds);
                param.put("action_name", action_name);
                param.put("action_info", scenMap);
            String data = new Gson().toJson(param);
            String qrResult = HttpHelper.httpPost(qrUrl, data, null);
            System.out.println("qrResult"+qrResult);
            JSONObject qrJson = JSONObject.fromObject(qrResult);
            String qrCode = qrJson.getString("url");
            String ticket = qrJson.getString("ticket");
            System.out.println("ticket"+ticket);
            String qrsUrl = "https://mp.weixin.qq.com/cgi-bin/showqrcode?ticket="+ticket; 

           response.getWriter().print(qrsUrl );
        } catch (Exception e) {

        }

    }

猜你喜欢

转载自blog.csdn.net/weixin_40836984/article/details/83141786