收藏
回答

生成小程序二维码,微信方返回码是200,但是生成的图片是损坏的?

URL url = new URL("https://api.weixin.qq.com/wxa/getwxacodeunlimit?access_token=" + access_token);
HttpURLConnection httpURLConnection = (HttpURLConnection) url.openConnection();
httpURLConnection.setRequestMethod("POST");// 提交模式
httpURLConnection.setDoOutput(true);
httpURLConnection.setDoInput(true);
JSONObject paramJson = new JSONObject();
paramJson.put("scene", userId);//这就是你二维码里携带的参数 String型  名称不可变
paramJson.put("page", "/pages/index/index"); //这是设置扫描二维码后跳转的页面pages/home/home
paramJson.put("width", 280);//默认430,二维码的宽度,单位 px,最小 280px,最大 1280 px
paramJson.put("is_hyaline", true);
paramJson.put("check_path", false);
paramJson.put("env_version", "trial");//正式版为 "release",体验版为 "trial",开发版为 "develop"。默认是正式版。
PrintWriter printWriter = new PrintWriter(httpURLConnection.getOutputStream());
printWriter.write(paramJson.toString());
printWriter.flush();
BufferedInputStream bis = new BufferedInputStream(httpURLConnection.getInputStream());
int responseCode = httpURLConnection.getResponseCode();
System.out.println("二维码返回码" + responseCode);
return bis;


这里  responseCode 返回的内容是  200
证明api调用成功,图片已获取到。但是通过 BufferedInputStream 进行存储成图片后,图片变成了损坏状态
小程序已经发布体验版了
求解答:
回答关注问题邀请回答
收藏

1 个回答

  • Mr.Zhao
    Mr.Zhao
    发表于小程序端
    01-11

    如何知道一定返回图片?

    01-11
    有用
    回复 5
    • 峋成🇨🇳
      峋成🇨🇳
      01-11
      responseCode 返回200,就证明微信返回的是图片了吧
      然后我是通过存起来的图片通过BufferedImage把图片文件再读出来校验图像是否有效
      01-11
      回复
    • Mr.Zhao
      Mr.Zhao
      01-11回复峋成🇨🇳
      谁告诉你的?
      01-11
      回复
    • Mr.Zhao
      Mr.Zhao
      01-11回复峋成🇨🇳
      http状态码  业务状态码,两回事,200是接口通了,返回图片判断content-type
      01-11
      回复
    • 峋成🇨🇳
      峋成🇨🇳
      发表于移动端
      01-11回复Mr.Zhao
      content-type也打印了,是图片格式。已经找到问题了,小程序版本的原因🤒
      01-11
      回复
    • Mr.Zhao
      Mr.Zhao
      01-11回复峋成🇨🇳
      没明白,服务端接口跟小程序版本有啥关系
      01-11
      回复
登录 后发表内容