微信小程序二维码返回的二进制内容,是一个byte[].
微信小程序生成二维码接口文档:
/miniprogram/dev/api-backend/
所以直接用byte[]接收即可,然后写入文件中:
req – 请求的参数json字符串
import ;
import ;
import ;
// req举例{“scene”:“500003#461”,“page”:“pages/index/index”,“width”:300}
byte[] bytes = new RestTemplate().postForObject(二维码接口url + accessToken,
req, byte[].class);
ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
File file = new File(“D:/图片名.jpg”);
try {
BufferedImage img = (bais);
(img, “jpg”, file);
} catch (IOException e) {
// ("【二维码生成失败】: {}", ());
}