QRC
This commit is contained in:
@@ -20,6 +20,7 @@ import java.net.HttpURLConnection;
|
||||
import java.net.URL;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.*;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
@Component
|
||||
@Service
|
||||
@@ -431,7 +432,56 @@ public class QRCodeUtil {
|
||||
return (serverPath +"/" + fileName);
|
||||
}
|
||||
|
||||
|
||||
|
||||
// 对字节数组字符串进行Base64解码并生成图片
|
||||
//imgFilePath 待保存的本地路径
|
||||
public static String GenerateImage(String base64Str, String imgFilePath) {
|
||||
if (base64Str == null) // 图像数据为空
|
||||
return null;
|
||||
Base64.Decoder decoder = Base64.getDecoder();
|
||||
try {
|
||||
// Base64解码
|
||||
byte[] bytes = decoder.decode(base64Str);
|
||||
for (int i = 0; i < bytes.length; ++i) {
|
||||
if (bytes[i] < 0) {// 调整异常数据
|
||||
bytes[i] += 256;
|
||||
}
|
||||
}
|
||||
|
||||
//设置图片名称,这个随意
|
||||
String date = new Random().nextInt(99999999)+".jpg";
|
||||
String fileName = date ;
|
||||
|
||||
// 生成jpg图片
|
||||
OutputStream out = new FileOutputStream(imgFilePath +"/" + fileName);
|
||||
out.write(bytes);
|
||||
out.flush();
|
||||
out.close();
|
||||
return (imgFilePath +"/" + fileName);
|
||||
} catch (Exception e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean isBase64(String url){
|
||||
String reg = "[a-zA-z]+://[^\\s]*";
|
||||
boolean isMatch = Pattern.matches(reg, url);
|
||||
if(isMatch){
|
||||
return isMatch;
|
||||
}
|
||||
return isMatch;
|
||||
}
|
||||
|
||||
public static String delete_profix(String base64){
|
||||
String delete = "data:image/jpg;base64,";
|
||||
String Base64 = base64;
|
||||
return(base64.replace(delete,""));
|
||||
}
|
||||
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
|
||||
// String text = "https://www.baidu.com"; //这里设置自定义网站url
|
||||
// String logoPath ="src/main/resources/static/logo/NAV.png";
|
||||
// String destPath = "src/main/resources/static/qr";
|
||||
|
Reference in New Issue
Block a user