| | |
| | | import com.github.binarywang.wxpay.bean.request.WxPayRefundRequest; |
| | | import com.github.binarywang.wxpay.bean.result.WxPayRefundResult; |
| | | import com.github.binarywang.wxpay.exception.WxPayException; |
| | | import io.netty.handler.codec.base64.Base64Decoder; |
| | | import io.netty.handler.codec.base64.Base64Encoder; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import okhttp3.OkHttpClient; |
| | | import okhttp3.Request; |
| | | import okhttp3.Response; |
| | | import org.apache.commons.io.IOUtils; |
| | | import org.checkerframework.checker.units.qual.A; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | import sun.misc.BASE64Decoder; |
| | | |
| | | import java.io.ByteArrayInputStream; |
| | | import java.io.ByteArrayOutputStream; |
| | |
| | | * https://developers.weixin.qq.com/miniprogram/dev/OpenApiDoc/qrcode-link/qr-code/getUnlimitedQRCode.html |
| | | * @return |
| | | */ |
| | | public void generateWXMiniCode(Locks locks){ |
| | | SystemDictData systemDictData = systemDictDataBiz.queryByCode(Constants.MINI_PROGRAMME,Constants.ACCESS_TOKEN); |
| | | public void generateWXMiniCode(Locks locks,SystemDictData systemDictData){ |
| | | |
| | | if(Objects.isNull(systemDictData)){ |
| | | return; |
| | | } |
| | |
| | | body.put("env_version", "release"); |
| | | // 透明,根据你的场景自行设置body参数 |
| | | body.put("is_hyaline", false); |
| | | // body.put("page","pages/index/index"); |
| | | body.put("check_path", false); |
| | | body.put("page","pages/index/index"); |
| | | OkHttpClient client = new OkHttpClient().newBuilder().build(); |
| | | okhttp3.MediaType mediaType = okhttp3.MediaType.parse("application/json"); |
| | | okhttp3.RequestBody requestBody = okhttp3.RequestBody.create(mediaType, JSONObject.toJSONString(body)); |
| | |
| | | Response response = client.newCall(request).execute(); |
| | | if (response.isSuccessful()) { |
| | | InputStream inputStream = new ByteArrayInputStream(response.body().bytes()); |
| | | ByteArrayOutputStream baos = new ByteArrayOutputStream(); |
| | | byte[] buffer = new byte[1024]; |
| | | int len = -1; |
| | | while ((len = inputStream.read(buffer)) != -1) { |
| | | baos.write(buffer, 0, len); |
| | | } |
| | | |
| | | locks.setInfo("data:mediatype;base64," + Base64.getEncoder().encodeToString(baos.toByteArray())); |
| | | |
| | | // FileOutputStream out = new FileOutputStream("d:\\test.png"); |
| | | // byte[] buffer = new byte[8192]; |
| | | // int bytesRead = 0; |
| | | // while ((bytesRead = inputStream.read(buffer, 0, 8192)) != -1) { |
| | | // out.write(buffer, 0, bytesRead); |
| | | // } |
| | | // out.flush(); |
| | | // inputStream.close(); |
| | | // out.close(); |
| | | // 得到文件大小 |
| | | int i = inputStream.available(); |
| | | byte[] mFileBody = new byte[i]; |
| | | // 读数据 |
| | | inputStream.read(mFileBody); |
| | | locks.setInfo("data:image/Jpeg;base64," + Base64.getEncoder().encodeToString(mFileBody)); |
| | | } |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |