fdfs防盗链配置及java开发

在上篇文章技术上:http://blog.csdn.net/www_wangzheguilai/article/details/76647443

1、修改配置文件

配置防盗链功能,其实配置端相当简单,如下:

cd /etc/fdfs

vim http.conf

#true-开启防盗链检查,false-关闭防盗链

http.anti_steal.check_token=true

#防盗链密钥

http.anti_steal.secret_key=FastDFS1234567890

#每次生成的访问链的有效时间,单位S

http.anti_steal.token_ttl=900

#校验失败,访问的图片

http.anti_steal.token_check_fail=/etc/fdfs/account_order.png

2、java端

修改java端的fdfs_client.conf文件

http.anti_steal_token = true
http.secret_key = FastDFS1234567890

tracker_server = 10.80.103.63:22122

生成防盗链连接的java代码块如下:

String[] results = new String[2];
		int errno = StorageClient1.split_file_id(fileId, results);
		if(errno != 0){
			throw new MyException("fileId格式错误!");
		}
		int ts = (int) (System.currentTimeMillis()/1000);
		
		String token = ProtoCommon.getToken(results[1], ts, ClientGlobal.getG_secret_key());
		
		return serverAddr + "/" + fileId + "?token=" + token + "&ts=" + ts;

生成防盗链地址:

http://10.80.103.63:9999/group1/M00/00/00/ClBnP1mD8NqAe-VeAABdrZgsqUU923_big.jpg?token=bcf7ed89b01ee6d72010d70eda63e0e8&ts=1501821311


你可能感兴趣的:(fastdfs)