com.xnx3.Lang Java Examples

The following examples show how to use com.xnx3.Lang. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Com.java    From xnx3 with Apache License 2.0 6 votes vote down vote up
/**
 * 版本检测
 */
private void versionCheck(){
	new Thread(new Runnable() {
		public void run() {
			HttpUtil http=new HttpUtil();
			String content=http.get("http://www.xnx3.com/down/java/j2se/version.html").getContent();
			if(content==null||content.length()==0){
				System.out.println("连接服务器进行版本检测失败");
			}else{
				float version=Lang.stringToFloat(content, 1.0f);
				if(version-Lang.version>0.0005){
					System.out.println("发现新版本:"+version+",请及时更新最新版本");
				}
			}
		}
	}).start();
}
 
Example #2
Source File: IpUtil.java    From xnx3 with Apache License 2.0 6 votes vote down vote up
/**
 * 获取IP地址,只会返回一个IP
 * @param request
 * @return <li>成功:返回一个ip
 * 			<li>失败:返回null
 */
public static String getIpAddress(HttpServletRequest request) {  
    String ip = request.getHeader("x-forwarded-for");  
    if(ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {  
        ip = request.getHeader("Proxy-Client-IP");  
    }  
    if(ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {  
        ip = request.getHeader("WL-Proxy-Client-IP");  
    }  
    if(ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {  
        ip = request.getRemoteAddr();  
    }  
    
    //如果有多个ip,拿最前面的
    if(ip.indexOf(",")>0){
    	ip=Lang.subString(ip, null, ",", 2);
    }
    
    if(ip.equals("0:0:0:0:0:0:0:1")){
    	ip = "127.0.0.1";
    }
    return ip;  
}
 
Example #3
Source File: StringDiff.java    From templatespider with Apache License 2.0 6 votes vote down vote up
public String previewChangDiff(){
	Map<Integer, String> map = new HashMap<Integer, String>();
	for (Map.Entry<Integer, String> entry : this.equalMap.entrySet()) {
		String html = entry.getValue().replaceAll("<", "&lt;").replaceAll(">", "&gt;");
		map.put(entry.getKey(), html);
	}
	
	Pattern pattern = Pattern.compile("\\{xnx3=([0-9]*)\\}");
	Matcher matcher = pattern.matcher(chang);
	String changStr = this.chang+" ";
	changStr = changStr.replaceAll("<", "&lt;").replaceAll(">", "&gt;");
	System.out.println("------changStr");
	System.out.println(changStr);
	while (matcher.find()) {
       	String m = matcher.group(1);	//模版变量的id
       	int key = Lang.stringToInt(m, -1);
       	String k = "{xnx3="+key+"}";
       	changStr = changStr.replace(k, "<font color=\"#dddddd;\">"+map.get(key)+"</font>");
	}
	return changStr;
}
 
Example #4
Source File: StringDiff.java    From templatespider with Apache License 2.0 6 votes vote down vote up
public String previewDuanDiff(){
	Map<Integer, String> map = new HashMap<Integer, String>();
	for (Map.Entry<Integer, String> entry : this.equalMap.entrySet()) {
		String html = entry.getValue().replaceAll("<", "&lt;").replaceAll(">", "&gt;");
		map.put(entry.getKey(), html);
	}
	
	Pattern pattern = Pattern.compile("\\{xnx3=([0-9]*)\\}");
	Matcher matcher = pattern.matcher(duan);
	String duanStr = this.duan+" ";
	duanStr = duanStr.replaceAll("<", "&lt;").replaceAll(">", "&gt;");
	while (matcher.find()) {
       	String m = matcher.group(1);	//模版变量的id
       	int key = Lang.stringToInt(m, -1);
       	String k = "{xnx3="+key+"}";
       	duanStr = duanStr.replace(k, "<font color=\"#dddddd;\">"+map.get(key)+"</font>");
	}
	return duanStr;
}
 
Example #5
Source File: Page.java    From xnx3 with Apache License 2.0 6 votes vote down vote up
/**
 * 传入当前页面的完整url(会自动过滤掉当前第几页的参数,以方便生成上一页、下一页等等链接)
 * <br/>若是bs应用,可直接使用 {@link #setUrl(HttpServletRequest)} 传入request,会全自动生成
 * @param url 生成的首页、上一页等链接地址的URL前缀,如 http://aaa.xnx3.com/index.php?id=3&pageCurrent=5&status=4
 */
public void setUrlByStringUrl(String url) {
	String ur = null;
	if(url!=null&&url.indexOf(CURRENTPAGENAME)>0){
		//传入的参数有当前页,需要吧currentPage这个参数给过滤掉
		ur = com.xnx3.Lang.subString(url, CURRENTPAGENAME, "&", 2);
		if(ur==null||ur.length()==0){
			ur=com.xnx3.Lang.subString(url, CURRENTPAGENAME, null, 2);
		}
		if(ur==null||ur.length()==0){
			ur = url;
		}else{
			String cp = ur;
			ur = url.replace("?"+CURRENTPAGENAME+cp, "");
			ur = ur.replace("&"+CURRENTPAGENAME+cp, "");
		}
		url =ur;
	}
	this.url = url;
}
 
Example #6
Source File: Sql.java    From xnx3 with Apache License 2.0 6 votes vote down vote up
/**
 * 传入组合的列名,如 >create_date  或 =id
 * @param groupColumn 
 */
public SqlColumn(String groupColumn){
	for (int i = 0; i < Sql.COLUMN_GROUP.length; i++) {
		if(groupColumn.indexOf(Sql.COLUMN_GROUP[i])>0){
			this.operators = Sql.COLUMN_GROUP[i];
			this.columnName = groupColumn.replace(this.operators, "");
			break;
		}
	}
	
	if(this.operators==null){
		this.columnName = groupColumn;
	}
	
	/**
	 * 时间判断筛选
	 */
	boolean isDateToInt = this.columnName.indexOf("date")>0;	//判断是否需要进行时间戳转换
	if(isDateToInt){
		this.dateFormat = Lang.subString(columnName, "(date:", ")",2);
		this.columnName = this.columnName.replace("(date:"+this.dateFormat+")", "");
	}
}
 
Example #7
Source File: MessageServiceImpl.java    From wangmarket with Apache License 2.0 5 votes vote down vote up
public BaseVO sendMessage(HttpServletRequest request) {
	BaseVO baseVO = new BaseVO();
	int recipientid = Lang.stringToInt(request.getParameter("recipientid"), 0);
	String content = request.getParameter("content");
	
	return sendMessage(recipientid, content);
}
 
Example #8
Source File: Resource.java    From templatespider with Apache License 2.0 5 votes vote down vote up
/**
	 * @param refererPagePath 来源页面的路径所在。如 www.baidu.com/a/b/c.html 那么这里便是 www.baidu.com/a/b/ 此项的作用,是当 originalUrl 是相对路径时,进行自动补齐其路径
	 */
	public Resource(String baseUri, String originalUrl) {
		this.originalUrl = originalUrl;
		if(baseUri.lastIndexOf("/") < baseUri.length() - 1){
			this.baseUri = Lang.subString(baseUri, "/", null, 3);
		}else{
			this.baseUri = baseUri;
		}
		
		//原始url
		if(originalUrl == null || originalUrl.length() < 2){
			return;
		}
		
		//资源在网络的绝对地址
		if(originalUrl.indexOf("http://") == 0 || originalUrl.indexOf("https://") == 0 || originalUrl.indexOf("//") == 0){
			//传入的是绝对url
			this.netUrl = originalUrl;
		}else{
			//传入的是相对路径,计算出绝对路径。
			if(originalUrl.indexOf("./") == 0){
				//是资源文件饮用
				this.netUrl = this.baseUri + originalUrl.substring(2, originalUrl.length());
			}else if (originalUrl.indexOf("../") == 0) {
				//上级文件,针对此项目,那应该就是html文件了
//				this.netUrl = Lang.subString(this.baseUri.substring(0, this.baseUri.length() - 1), "/", null, 3) + originalUrl.substring(3, originalUrl.length());
				//需要找baseUri的上一级目录
				this.netUrl = this.baseUri.substring(0, this.baseUri.substring(0, this.baseUri.length()-1).lastIndexOf("/")+1) + originalUrl.substring(3, originalUrl.length());
			}else if (originalUrl.indexOf("/") == 0) {
				//是根目录
				System.out.println("根目录");
			}else{
				//什么也没有,直接跟在后面即可
				this.netUrl = this.baseUri + originalUrl;
			}
		}
		
		jisuanLocalFile();
	}
 
Example #9
Source File: UserServiceImpl.java    From wangmarket with Apache License 2.0 5 votes vote down vote up
/**
	 * 注册成功后下线充值奖励
	 * @param user 要充值的下线user
	 * @param addCurrency_ 增加的货币值
	 * @param regUser 注册的用户的用户名
	 */
	private void referrerAddAward(User user,String addCurrency_,User regUser){
		int addCurrency = Lang.stringToInt(addCurrency_, 0);
		if(addCurrency>0){
			user.setCurrency(user.getCurrency()+addCurrency);
			sqlDAO.save(user);
//			logDao.insert(regUser.getId(), "USER_INVITEREG_AWARD", addCurrency+"");
		}
	}
 
Example #10
Source File: UserServiceImpl.java    From wangmarket with Apache License 2.0 5 votes vote down vote up
/**
 * 注册
 * @param user {@link User} 
 * 		<br/>表单的用户名(username)、 密码(password)为必填项
 * @param request {@link HttpServletRequest}
 * @return {@link BaseVO}
 */
public void regInit(HttpServletRequest request) {
	String inviteid_ = request.getParameter("inviteid");
	if(inviteid_!=null&&inviteid_.length()>0){
		int inviteid = Lang.stringToInt(inviteid_, 0);
		
		User user = sqlDAO.findById(User.class, inviteid);
		if(user!=null){
			request.getSession().setAttribute("inviteid", inviteid); 	//邀请人id
		}
	}
}
 
Example #11
Source File: UserServiceImpl.java    From wangmarket with Apache License 2.0 5 votes vote down vote up
public UploadFileVO updateHeadByOSS(MultipartFile head) {
		UploadFileVO uploadFileVO = new UploadFileVO();
		if(head == null || head.isEmpty()){
			uploadFileVO.setBaseVO(BaseVO.FAILURE, Language.show("user_uploadHeadImageNotFind"));
			return uploadFileVO;
		}
		
		User user = ShiroFunc.getUser();
		String fileSuffix = "png";
		fileSuffix = Lang.findFileSuffix(Safety.filter(head.getOriginalFilename()));
		String newHead = Lang.uuid()+"."+fileSuffix;
		try {
			uploadFileVO = AttachmentFile.put(Global.get("USER_HEAD_PATH")+newHead, head.getInputStream());
		} catch (IOException e) {
			e.printStackTrace();
			uploadFileVO.setBaseVO(BaseVO.FAILURE, e.getMessage());
			return uploadFileVO;
		}
		
		User u = sqlDAO.findById(User.class, user.getId());
		//删除之前的头像
		if(u.getHead() != null && u.getHead().length() > 0 && !u.getHead().equals("default.png")){
			AttachmentFile.deleteObject("image/head/"+u.getHead());
		}
		
		u.setHead(newHead);
		sqlDAO.save(u);
		ShiroFunc.getUser().setHead(newHead);
		
//		logDao.insert("USER_UPDATEHEAD");
		
		return uploadFileVO;
	}
 
Example #12
Source File: Com.java    From xnx3 with Apache License 2.0 5 votes vote down vote up
/**
 * 需要是jre1.7版本,检测版本
 */
private void initCheckJreVersion(){
	String version=System.getProperty("java.version");
	if(version.indexOf("1.7")>-1){
		//通过
		this.createSuccess=true;
	}else{
		this.createSuccess=false;
		if(UI.showConfirmDialog("运行请使用 JRE 1.7 版本!<br/>当前版本:"+version+"<br/>当前JRE路径:"+Lang.getCurrentJrePath()+"<br/>JRE1.7下载地址:http://www.xnx3.com/doc/jre1.7.html<br/>只有开发者可见此提示<br/><br/>是否下载?")==Lang.CONFIRM_YES){
			SystemUtil.openUrl("http://www.xnx3.com/doc/jre1.7.html");
		}
		System.err.println("运行请使用 JRE 1.7 版本!下载地址: http://www.xnx3.com/doc/jre1.7.html");
	}
}
 
Example #13
Source File: OSS.java    From wangmarket with Apache License 2.0 5 votes vote down vote up
/**
 * SpringMVC 上传图片文件,配置允许上传的文件后缀再 systemConfig.xml 的OSS节点
 * @param filePath 上传后的文件所在OSS的目录、路径,如 "jar/file/"
 * @param multipartFile SpringMVC接收的 {@link MultipartFile},若是有上传图片文件,会自动转化为{@link MultipartFile}保存
 * @param maxWidth 上传图片的最大宽度,若超过这个宽度,会对图片进行等比缩放为当前宽度。
 * @return {@link UploadFileVO} 若成功,则上传了文件并且上传成功
 */
public static UploadFileVO uploadImageByMultipartFile(String filePath, MultipartFile multipartFile, int maxWidth) {
	UploadFileVO vo = new UploadFileVO();
	
	if(multipartFile == null){
		vo.setBaseVO(UploadFileVO.FAILURE, Language.show("oss_pleaseSelectUploadFile"));
		return vo;
	}
	InputStream inputStream = null;
	try {
		inputStream = multipartFile.getInputStream();
	} catch (IOException e) {
		e.printStackTrace();
	}
	if(inputStream == null){
		vo.setBaseVO(UploadFileVO.FAILURE, Language.show("oss_pleaseSelectUploadFile"));
		return vo;
	}
	
	//获取上传的文件的后缀
	String fileSuffix = null;
	fileSuffix = Lang.findFileSuffix(Safety.filter(multipartFile.getOriginalFilename()));
	
	if(!imageAllowUpload(fileSuffix)){
		vo.setBaseVO(UploadFileVO.FAILURE, Language.show("oss_uploadFileNotInSuffixList"));
		return vo;
	}
	
	vo = uploadImageByInputStream(filePath, inputStream, fileSuffix, maxWidth);
	return vo;
}
 
Example #14
Source File: OSS.java    From wangmarket with Apache License 2.0 5 votes vote down vote up
/**
 * 创建 授权于OSS GetObject、PutObject 权限的临时账户(此只是针对 {@link OSSUtil#createSTS(String, String)}的简化 )
 * @return {@link Credentials}
 */
public static CredentialsVO createGetAndPutObjectSTS() {
	String policy = "{\n" +
			"    \"Version\": \"1\", \n" +
			"    \"Statement\": [\n" +
			"        {\n" +
			"            \"Action\": [\n" +
			"                \"oss:PutObject\", \n" +
			"                \"oss:GetObject\" \n" +
			"            ], \n" +
			"            \"Resource\": [\n" +
			"                \"acs:oss:*:*:*\"\n" +
			"            ], \n" +
			"            \"Effect\": \"Allow\"\n" +
			"        }\n" +
			"    ]\n" +
			"}";
	String id = "";
	if(ShiroFunc.getUser() == null){
		id = Lang.uuid();
	}else{
		id = "user"+ShiroFunc.getUser().getId();
	}
	
	Credentials credentials = OSSUtil.createSTS(id, policy);
	CredentialsVO cVO = new CredentialsVO();
	if(credentials == null){
		cVO.setBaseVO(com.xnx3.BaseVO.FAILURE, "创建失败");
	}else{
		cVO.setAccessKeyId(credentials.getAccessKeyId());
		cVO.setAccessKeySecret(credentials.getAccessKeySecret());
		cVO.setExpiration(credentials.getExpiration());
		cVO.setSecurityToken(credentials.getSecurityToken());
	}
	
	return cVO;
}
 
Example #15
Source File: AttachmentFile.java    From wangmarket with Apache License 2.0 5 votes vote down vote up
/**
 * 获取当前限制的上传文件最大的大小限制。单位是KB
 * @return 单位KB
 */
public static int getMaxFileSizeKB(){
	if(maxFileSizeKB == -1){
		//未初始化,那么进行初始化
		maxFileSize = getMaxFileSize();
		
		if(maxFileSize.indexOf("KB") > 0){
			//使用KB单位
			maxFileSizeKB = Lang.stringToInt(maxFileSize.replace("KB", "").trim(), 0);
			if(maxFileSizeKB == 0){
				Log.error("application.properties --> spring.servlet.multipart.max-file-size use KB, but !!! string to int failure !");
			}
		}else if (maxFileSize.indexOf("MB") > 0) {
			//使用MB
			maxFileSizeKB = Lang.stringToInt(maxFileSize.replace("MB", "").trim(), 0) * 1024;
			if(maxFileSizeKB == 0){
				Log.error("application.properties --> spring.servlet.multipart.max-file-size use MB, but !!! string to int failure !");
			}
		}else if (maxFileSize.indexOf("GB") > 0) {
			//使用 GB
			maxFileSizeKB = Lang.stringToInt(maxFileSize.replace("GB", "").trim(), 0) * 1024 * 1024;
			if(maxFileSizeKB == 0){
				Log.error("application.properties --> spring.servlet.multipart.max-file-size use GB, but !!! string to int failure !");
			}
		}else{
			//没有找到合适单位,报错
			Log.error("application.properties --> spring.servlet.multipart.max-file-size not find unit,your are KB ? MB ? GB ? Please use one of them");
		}
	}
	return maxFileSizeKB;
}
 
Example #16
Source File: AttachmentFile.java    From wangmarket with Apache License 2.0 5 votes vote down vote up
/**
 * SpringMVC 上传文件,配置允许上传的文件后缀再 systemConfig.xml 的attachmentFile.allowUploadSuffix.suffix节点
 * @param filePath 上传后的文件所在目录、路径,如 "jar/file/"
 * @param multipartFile SpringMVC接收的 {@link MultipartFile},若是有上传文件,会自动转化为{@link MultipartFile}保存
 * @return {@link UploadFileVO} 若成功,则上传了文件并且上传成功
 */
public static UploadFileVO uploadFileByMultipartFile(String filePath, MultipartFile multipartFile) {
	UploadFileVO vo = new UploadFileVO();
	
	if(multipartFile == null){
		vo.setBaseVO(UploadFileVO.FAILURE, Language.show("oss_pleaseSelectUploadFile"));
		return vo;
	}
	
	InputStream inputStream = null;
	try {
		inputStream = multipartFile.getInputStream();
	} catch (IOException e) {
		e.printStackTrace();
	}
	if(inputStream == null){
		vo.setBaseVO(UploadFileVO.FAILURE, Language.show("oss_pleaseSelectUploadFile"));
		return vo;
	}
	
	//获取上传的文件的后缀
	String fileSuffix = null;
	fileSuffix = Lang.findFileSuffix(multipartFile.getOriginalFilename());
	
	if(!allowUploadSuffix(fileSuffix)){
		vo.setBaseVO(UploadFileVO.FAILURE, Language.show("oss_uploadFileNotInSuffixList"));
		return vo;
	}
	
	vo = uploadFileByInputStream(filePath, inputStream, fileSuffix);
	return vo;
}
 
Example #17
Source File: AttachmentFile.java    From wangmarket with Apache License 2.0 5 votes vote down vote up
/**
 * SpringMVC 上传图片文件,配置允许上传的文件后缀再 systemConfig.xml 的attachmentFile.allowUploadSuffix.suffix节点
 * @param filePath 上传后的文件所在目录、路径,如 "jar/file/"
 * @param multipartFile SpringMVC接收的 {@link MultipartFile},若是有上传图片文件,会自动转化为{@link MultipartFile}保存
 * @param maxWidth 上传图片的最大宽度,若超过这个宽度,会对图片进行等比缩放为当前宽度。若传入0.则不启用此功能
 * @return {@link UploadFileVO} 若成功,则上传了文件并且上传成功
 */
public static UploadFileVO uploadImageByMultipartFile(String filePath, MultipartFile multipartFile, int maxWidth) {
	UploadFileVO vo = new UploadFileVO();
	
	if(multipartFile == null){
		vo.setBaseVO(UploadFileVO.FAILURE, Language.show("oss_pleaseSelectUploadFile"));
		return vo;
	}
	
	InputStream inputStream = null;
	try {
		inputStream = multipartFile.getInputStream();
	} catch (IOException e) {
		e.printStackTrace();
	}
	if(inputStream == null){
		vo.setBaseVO(UploadFileVO.FAILURE, Language.show("oss_pleaseSelectUploadFile"));
		return vo;
	}
	
	//获取上传的文件的后缀
	String fileSuffix = null;
	fileSuffix = Lang.findFileSuffix(multipartFile.getOriginalFilename());
	
	if(!allowUploadSuffix(fileSuffix)){
		vo.setBaseVO(UploadFileVO.FAILURE, Language.show("oss_uploadFileNotInSuffixList"));
		return vo;
	}
	
	vo = uploadImageByInputStream(filePath, inputStream, fileSuffix, maxWidth);
	return vo;
}
 
Example #18
Source File: AttachmentFile.java    From wangmarket with Apache License 2.0 5 votes vote down vote up
/**
 * 上传文件
 * @param filePath 上传后的文件所在的目录、路径,如 "jar/file/"
 * @param fileName 上传的文件名,如“xnx3.jar”;主要拿里面的后缀名。也可以直接传入文件的后缀名如“.jar。新的文件名会是自动生成的 uuid+后缀”
 * @param inputStream {@link InputStream}
 * @return {@link PutResult} 若失败,返回null
 */
public static UploadFileVO put(String filePath,String fileName,InputStream inputStream){
	UploadFileVO vo = new UploadFileVO();
	
	//进行文件后缀校验
	if(fileName == null || fileName.indexOf(".") == -1){
		vo.setBaseVO(UploadFileVO.FAILURE, "上传的文件名(后缀)校验失败!传入的为:"+fileName+",允许传入的值如:a.jpg或.jpg");
		return vo;
	}
	
	String fileSuffix = StringUtil.subString(fileName, ".", null, 3);	//获得文件后缀,以便重命名
       String name=Lang.uuid()+"."+fileSuffix;
       String path = filePath+name;
       return put(path, inputStream);
}
 
Example #19
Source File: Log.java    From wangmarket with Apache License 2.0 5 votes vote down vote up
/**
 * log.type 值-描述 缓存
 */
public void type(List<String> list){
	createCacheObject("type");
	
	for (int i = 0; i < list.size(); i++) {
   		String[] array = list.get(i).split("#");
   		String name = array[0];
   		Short value = (short) Lang.stringToInt(array[1], 0);
   		String description = array[2];
   		cacheAdd(value, description);
	}
	generateCacheFile();
}
 
Example #20
Source File: Color.java    From xnx3 with Apache License 2.0 5 votes vote down vote up
/**
 * 判断2个16进制数据的差是否在指定范围内
 * @param color1 颜色值,如 FFFFFF
 * @param color2 
 * @param param 两者差距的颜色值,如 303030
 * @return boolean
 */
public boolean compareColor(String color1,String color2,String param){
	boolean xnx3_result=false;
	if(color1==null||color1.length()!=6||color2==null||color2.length()!=6||param==null||param.length()!=6){
		//false
		log.debug(this,"compareColor","颜色值传入不正确,请传入6位16进制颜色值");
	}else{
		try {
			int color1_12=Lang.Integer_(color1.substring(0, 2), 0, 16);
			int color1_34=Lang.Integer_(color1.substring(2, 4), 0, 16);
			int color1_56=Lang.Integer_(color1.substring(4, 6), 0, 16);

			int color2_12=Lang.Integer_(color2.substring(0, 2), 9, 16);
			int color2_34=Lang.Integer_(color2.substring(2, 4), 9, 16);
			int color2_56=Lang.Integer_(color2.substring(4, 6), 9, 16);
			
			int param_12=Lang.Integer_(param.substring(0, 2), 5, 16);
			int param_34=Lang.Integer_(param.substring(2, 4), 5, 16);
			int param_56=Lang.Integer_(param.substring(4, 6), 5, 16);
			
			if(Math.abs(color1_12-color2_12)<param_12&&Math.abs(color1_34-color2_34)<param_34&&Math.abs(color1_56-color2_56)<param_56){
				xnx3_result=true;
			}else{
				xnx3_result=false;
			}
			
		} catch (Exception e) {
			e.printStackTrace();
			log.debug(this,"compareColor","16进制判断异常捕获:"+e.getMessage());
		}
	}
	
	return xnx3_result;
}
 
Example #21
Source File: WebSocketServer.java    From wangmarket with Apache License 2.0 5 votes vote down vote up
/**
 * 初始化当前链接socket的用户信息,取出get传递过来的一些用户数据
 *  @param get传递过来的参数
 */
public void initUserInfo(){
	Map<String, List<String>> param = session.getRequestParameterMap();
	if(param != null && param.size() > 0){
		if(param.get("password") != null && param.get("password").size() > 0){
			this.password = param.get("password").toArray()[0].toString();
		}else{
			this.password = "";
		}
		if(param.get("id") != null && param.get("id").size() > 0){
			this.id = Lang.stringToLong(param.get("id").toArray()[0].toString(), 0);
		}else{
			this.id = 0L;
		}
		//当前登录用户的昵称,若是登录用户,会覆盖掉get传入的值
		if(param.get("username") != null && param.get("username").size() > 0){
			this.username = param.get("username").toArray()[0].toString();
		}
		//当前登录用户的头像,若是登录用户,会覆盖掉get传入的值
		if(param.get("avatar") != null && param.get("avatar").size() > 0){
			this.avatar = param.get("avatar").toArray()[0].toString();
		}else{
			this.avatar = "http://res.weiunity.com/image/imqq.jpg";
		}
		//用户的签名
		if(param.get("sign") != null && param.get("sign").size() > 0){
			this.sign = param.get("sign").toArray()[0].toString();
		}else{
			this.sign = "";
		}
		
	}
}
 
Example #22
Source File: FastDFSUtil.java    From xnx3 with Apache License 2.0 5 votes vote down vote up
/**
 * 文件上传
 * @param local_filename 要上传的本地文件绝对路径
 * <ul>
 * 	<li>使用之前需先开启,调用 {@link #open()}
 * </ul>
 * @return {@link UploadBean}
 * 		<ul>
 * 			<li>{@link UploadBean#isSuccess()}:判断是否上传成功
 * 		</ul>
 */
public UploadBean upload(String local_filename) {
	String[] results=null;
	try {
		String suffix = com.xnx3.Lang.findFileSuffix(local_filename);
		if(suffix==null){
			suffix=ClientGlobal.defaultSuffix;
		}
		results = client.upload_file(local_filename, suffix, meta_list);
	} catch (IOException | MyException e) {
		e.printStackTrace();
	}

	return trimUploadBean(results);
}
 
Example #23
Source File: OSSUtils.java    From xnx3 with Apache License 2.0 5 votes vote down vote up
/**
 * 上传文件
 * @param filePath 上传后的文件所在OSS的目录、路径,如 "jar/file/"
 * @param fileName 上传的文件名,如“xnx3.jar”;主要拿里面的后缀名。也可以直接传入文件的后缀名如“.jar”
 * @param inputStream {@link InputStream}
 * @return {@link PutResult} 若失败,返回null
 */
public PutResult put(String filePath,String fileName,InputStream inputStream){
	String fileSuffix=com.xnx3.Lang.subString(fileName, ".", null, 3);	//获得文件后缀,以便重命名
       String name=Lang.uuid()+"."+fileSuffix;
       String path = filePath+name;
       PutObjectResult pr = getOSSClient().putObject(bucketName, path, inputStream);
	return new PutResult(name, path,url+path);
}
 
Example #24
Source File: RabbitUtil.java    From wangmarket with Apache License 2.0 5 votes vote down vote up
public RabbitUtil() {
	String host = ApplicationProperties.getProperty("spring.rabbitmq.host");
	if(host == null){
		isUse = false;
		return;
	}
	int port = Lang.stringToInt(ApplicationProperties.getProperty("spring.rabbitmq.port"), 5672);
	String username = ApplicationProperties.getProperty("spring.rabbitmq.username");
	String password = ApplicationProperties.getProperty("spring.rabbitmq.password");
	
	rabbitMQTopicUtil = new RabbitMQTopicUtil(host, username, password, port);
	isUse = true;
}
 
Example #25
Source File: OSSUtils.java    From xnx3 with Apache License 2.0 5 votes vote down vote up
/**
 * 上传图片,将网上的图片复制到OSS里 如果获取不到后缀,默认用 jpg
 * @param filePath 上传图片的OSS地址,如 image/124  后面会自动拼接上图片的后缀名,上传成功后为image/124.png
 * @param imageUrl 网上图片的地址
 * @return {@link PutResult}
 */
public PutResult putImageByUrl(String filePath, String imageUrl){
	if(imageUrl == null){
		return null;
	}
	String suffix = Lang.findFileSuffix(imageUrl);	//取图片后缀名
	BufferedImage bufferedImage = ImageUtil.getBufferedImageByUrl(imageUrl);
	if(suffix == null){
		suffix = "jpg";
	}
	
   	return put(filePath+"."+suffix, ImageUtil.bufferedImageToInputStream(bufferedImage, suffix));
}
 
Example #26
Source File: Template.java    From wangmarket with Apache License 2.0 5 votes vote down vote up
/**
 * 获取HTML注释中的指定配置名的文本内容,若没发现这个配置,返回""
 * @param sourceText 指定的HTML内容
 * @param configName 参数名
 * @return 值
 */
public static String getConfigValue(String sourceText,String configName){
	if(sourceText.indexOf("<!--"+configName+"=") > -1){
		return Lang.subString(sourceText, "<!--"+configName+"=", "-->",2);
	}else{
		return "";
	}
}
 
Example #27
Source File: OSSUtil.java    From xnx3 with Apache License 2.0 5 votes vote down vote up
/**
 * 上传文件
 * @param filePath 上传后的文件所在OSS的目录、路径,如 "jar/file/"
 * @param fileName 上传的文件名,如“xnx3.jar”;主要拿里面的后缀名。也可以直接传入文件的后缀名如“.jar”
 * @param inputStream {@link InputStream}
 * @return {@link PutResult} 若失败,返回null
 */
public static PutResult put(String filePath,String fileName,InputStream inputStream){
	String fileSuffix=com.xnx3.Lang.subString(fileName, ".", null, 3);	//获得文件后缀,以便重命名
       String name=Lang.uuid()+"."+fileSuffix;
       String path = filePath+name;
       PutObjectResult pr = getOSSClient().putObject(bucketName, path, inputStream);
	return new PutResult(name, path,url+path);
}
 
Example #28
Source File: OSSUtil.java    From xnx3 with Apache License 2.0 5 votes vote down vote up
/**
 * 上传图片,将网上的图片复制到OSS里 如果获取不到后缀,默认用 jpg
 * @param filePath 上传图片的OSS地址,如 image/124  后面会自动拼接上图片的后缀名,上传成功后为image/124.png
 * @param imageUrl 网上图片的地址
 * @return {@link PutResult}
 */
public static PutResult putImageByUrl(String filePath, String imageUrl){
	if(imageUrl == null){
		return null;
	}
	String suffix = Lang.findFileSuffix(imageUrl);	//取图片后缀名
	BufferedImage bufferedImage = ImageUtil.getBufferedImageByUrl(imageUrl);
	if(suffix == null){
		suffix = "jpg";
	}
	
   	return OSSUtil.put(filePath+"."+suffix, ImageUtil.bufferedImageToInputStream(bufferedImage, suffix));
}
 
Example #29
Source File: SiteController.java    From wangmarket with Apache License 2.0 5 votes vote down vote up
/**
 * 获取用户的OSS已用空间
 */
@RequestMapping(value="getOSSSize${url.suffix}", method = RequestMethod.POST)
@ResponseBody
public BaseVO getOSSSize(){
	//判断一下,如果是使用的阿里云OSS存储,但是没有配置,会拦截提示
	if(AttachmentFile.isMode(AttachmentFile.MODE_ALIYUN_OSS) && OSSUtil.getOSSClient() == null){
		return error("未开通阿里云OSS服务");
	}
	
	BaseVO vo = new BaseVO();
	//获取其下有多少网站
	List<Site> list = sqlService.findBySqlQuery("SELECT * FROM site WHERE userid = "+getUserId(), Site.class);
	//属于该用户的这些网站共占用了多少存储空间去
	long sizeB = 0;
	for (int i = 0; i < list.size(); i++) {
		sizeB += AttachmentFile.getDirectorySize("site/"+list.get(i).getId()+"/");
	}
	
	int kb = Math.round(sizeB/1024);
	String currentDate = DateUtil.currentDate("yyyyMMdd");
	sqlService.executeSql("UPDATE user SET oss_update_date = '"+currentDate+"' , oss_size = "+kb+" WHERE id = "+getUserId());
	vo.setBaseVO(BaseVO.SUCCESS, kb+"");
	
	AliyunLog.addActionLog(getSiteId(), "计算我当前网站使用了多少存储空间,已使用:"+Lang.fileSizeToInfo(sizeB));
	
	ShiroFunc.setUEditorAllowUpload(kb<ShiroFunc.getUser().getOssSizeHave()*1000);
	return vo;
}
 
Example #30
Source File: SendPhoneMsgUtil.java    From xnx3 with Apache License 2.0 4 votes vote down vote up
/**
 * 发送短信
 * @param phone 发送到的手机号
 * @param content 发送内容,编码为UTF-8编码,70个文字以内,超过70个字会发送多条信息
 * @return String <li>返回空字符null,为发送成功
 * 				  <li>返回字符串,非null,则发送失败,返回出错信息
 */
public static String send(String phone,String content){
	String result=null;
	
	if(passwordMd5 == null){
		System.out.println("请先执行  SendPhoneMsgUtil.setUserPassword(); 设置账号密码");
		return "请先执行  SendPhoneMsgUtil.setUserPassword(); 设置账号密码";
	}
	
	try {
		content=java.net.URLEncoder.encode(content, "utf-8");
	} catch (UnsupportedEncodingException e) {
		e.printStackTrace();
	}
	
	com.xnx3.net.HttpUtil httpUtil=new com.xnx3.net.HttpUtil();
	String url="http://"+requestIp+":9011/hy?uid="+uid+"&auth="+passwordMd5+"&mobile="+phone+"&msg="+content+"&encode=utf-8&expid=0";
	String requestResult=httpUtil.get(url).getContent();
	if(requestResult!=null&&requestResult.split(",")[0].equals("0")){
		result=null;
	}else{
		//send failure
		if(requestResult.indexOf("-")>0){
			int state=Lang.stringToInt(requestResult, 0);
			switch (state) {
				case 0:
					result=requestResult;
					break;
				case -1: 
					result="签权失败";
					break;
				case -2:
					result="未检索到被叫号码";
					break;
				case -3:
					result="被叫号码过多";
					break;
				case -4:
					result="内容未签名";
					break;
				case -5:
					result="内容过长";
					break;
				case -6:
					result="余额不足";
					break;
				case -7:
					result="暂停发送";
					break;
				case -8:
					result="保留";
					break;
				case -9:
					result="定时发送时间格式错误";
					break;
				case -10:
					result="下发内容为空";
					break;
				case -11:
					result="账户无效";
					break;
				case -12:
					result="Ip地址非法";
					break;
				case -13:
					result="操作频率快";
					break;
				case -14:
					result="'操作失败";
					break;
				case -15:
					result="拓展码无效(1-999)";
					break;
			default:
				result="未知错误";
				break;
			}
		}else{
			result=requestResult;
		}
	}
	
	httpUtil=null;
	return result;
}