微信后端代码
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

41 lines
1.0 KiB

package com.ynxbd.common.helper.common;
import jcifs.CIFSContext;
import jcifs.context.SingletonContext;
import jcifs.smb.NtlmPasswordAuthentication;
import jcifs.smb.SmbFile;
import jcifs.smb.SmbFileInputStream;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.io.IOUtils;
import java.io.InputStream;
/**
* @author 李进才
* @ClassName SmbHelper
* @Description description
* @date 2023/3/23 09:10
*/
@Slf4j
@AllArgsConstructor
public class SmbHelper {
private final String user;
private final String pass;
public byte[] smbGet(String shareUrl) throws Exception {
CIFSContext base = SingletonContext.getInstance();
CIFSContext auth = base.withCredentials(new NtlmPasswordAuthentication(base,null, user, pass));
SmbFile dir = new SmbFile(shareUrl, auth);
if (!dir.exists()) {
log.info("共享文件不存在");
return null;
}
InputStream is = new SmbFileInputStream(dir);
return IOUtils.toByteArray(is);
}
}