| | |
| | | import cn.hutool.core.date.DateTime; |
| | | import cn.hutool.core.date.DateUtil; |
| | | import cn.hutool.core.util.ObjectUtil; |
| | | import cn.hutool.json.JSONUtil; |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | |
| | | @Test |
| | | public void qrcodeBase64(){ |
| | | WxGenerateQrCodeDto wxGenerateQrCodeDto = new WxGenerateQrCodeDto(); |
| | | wxGenerateQrCodeDto.setPage("pages/index/index"); |
| | | wxGenerateQrCodeDto.setScene("15"); |
| | | wxGenerateQrCodeDto.setPage("pages/product/details"); |
| | | wxGenerateQrCodeDto.setScene("35"); |
| | | FebsResponse febsResponse = iXcxPayService.generateQrCode(wxGenerateQrCodeDto); |
| | | String data = febsResponse.get("data").toString(); |
| | | System.out.println(data); |
| | |
| | | String json = JSON.toJSONString(param); |
| | | ByteArrayInputStream inputStream = sendPost(url, json); |
| | | |
| | | System.out.println(inputStream); |
| | | //这里判断的是返回的图片还是错误信息,一般错误信息不会大于200 |
| | | if (inputStream.available() <= 200){ |
| | | ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); |
| | |
| | | byteArrayOutputStream.write(buffer,0,i); |
| | | } |
| | | String str = new String(byteArrayOutputStream.toByteArray()); |
| | | System.out.println(str); |
| | | //错误信息的格式在官方文档里有 |
| | | JSONObject jsonObject = JSONObject.parseObject(str); |
| | | if ("41030".equals(jsonObject.getString("errcode"))){ |
| | |
| | | //输出到本地的代码 |
| | | FileOutputStream fileOutputStream = new FileOutputStream("D:/123.png"); |
| | | int i; |
| | | byte[] buffer = new byte[200]; |
| | | byte[] buffer = new byte[10240000]; |
| | | while ((i = inputStream.read(buffer)) != -1){ |
| | | fileOutputStream.write(buffer,0,i); |
| | | } |
| | | |
| | | fileOutputStream.flush(); |
| | | fileOutputStream.close(); |
| | | |
| | | inputStream.close(); |
| | | }catch (Exception e){ |
| | | } |
| | |
| | | inputStream.close(); |
| | | // 把outStream里的数据写入内存 |
| | | byteArrayInputStream = new ByteArrayInputStream(outStream.toByteArray()); |
| | | byte[] data = outStream.toByteArray(); |
| | | String result = new String(Base64.getEncoder().encode(data)); |
| | | result = "data:image/jpeg;base64," + result; |
| | | System.out.println(result); |
| | | } |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |