获取微信小程序码(接口B:适用于需要的码数量极多的业务场景)

/**
     *
    * @Title: getWeChatSmallProgramCode
    * @Description:  获取微信小程序码
    * @date 2018年6月26日下午3:35:25
     */
    private BufferedImage getWeChatSmallProgramCode(String UserIdOfEncryption){
        RestTemplate rest = new RestTemplate();
        InputStream inputStream = null;
        BufferedImage bufferedImage = null;
        try {
            String accessToken = “你的access_token”;
            String url = "https://api.weixin.qq.com/wxa/getwxacodeunlimit?access_token=" + accessToken;
            Map<String, Object> param = new HashMap<String, Object>();
            param.put("width", 160);
            param.put("auto_color", false);
            Map<String, Object> line_color = new HashMap<>();
            line_color.put("r", 0);
            line_color.put("g", 0);
            line_color.put("b", 0);
            param.put("line_color", line_color);
            param.put("page", "小程序页面");
            param.put("scene", "参数");
            param.put("is_hyaline", true);
            logger.info("调用生成微信URL接口传参:" + JSON.toJSONString(param));
            MultiValueMap<String, String> headers = new LinkedMultiValueMap<>();
            HttpEntity requestEntity = new HttpEntity(JSON.toJSONString(param), headers);
            ResponseEntity<byte[]> entity = rest.exchange(url, HttpMethod.POST, requestEntity, byte[].class, new Object[0]);
            byte[] result = entity.getBody();
            inputStream = new ByteArrayInputStream(result);
            bufferedImage = ImageIO.read(inputStream);
        } catch (Exception e) {
            logger.info(e.getMessage(),e);
        }
        
        return bufferedImage;

    }

 

使用的是接口B:适用于需要的码数量极多的业务场景:page参数仔细阅读官方文档可发现,该参数的小程序页面必须是已发布的小程序页面,开发版和体验版传此参数会报错:

无效的页面({

  "errcode": 41030,
  "errmsg": "invalid page hint: [X7Y8ya02774528]"
})

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值