| | |
| | | import com.google.gson.JsonSyntaxException; |
| | | import com.whyc.pojo.UserInf; |
| | | import org.apache.commons.codec.digest.DigestUtils; |
| | | import org.springframework.web.context.ContextLoader; |
| | | import org.springframework.web.context.request.RequestContextHolder; |
| | | import org.springframework.web.context.request.ServletRequestAttributes; |
| | | import sun.misc.BASE64Decoder; |
| | |
| | | import java.text.SimpleDateFormat; |
| | | import java.util.Calendar; |
| | | import java.util.Date; |
| | | import java.util.Locale; |
| | | |
| | | public class ActionUtil{ |
| | | |
| | | public static String time_yyyyMMddHHmmss = "yyyy-MM-dd HH:mm:ss"; |
| | | public static SimpleDateFormat sdfwithOutday=new SimpleDateFormat("yyyy_MM"); |
| | | public static String time_yyyyMMdd = "yyyy-MM-dd"; |
| | | public static SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); |
| | | public static SimpleDateFormat sdfwithOutday = new SimpleDateFormat("yyyy_MM"); |
| | | public static SimpleDateFormat sdfwithday = new SimpleDateFormat("yyyy-MM-dd"); |
| | | |
| | | /* |
| | | * 获取HttpServletRequest |
| | |
| | | * @return 返回application |
| | | */ |
| | | public static ServletContext getApplication(){ |
| | | ServletContext servletContext = ContextLoader.getCurrentWebApplicationContext().getServletContext(); |
| | | return servletContext; |
| | | return getSession().getServletContext(); |
| | | } |
| | | //获取application中互斥上传的标志位flag |
| | | public static int getFlag(){ |
| | |
| | | a.roll(Calendar.DATE, -1); |
| | | int maxDate = a.get(Calendar.DATE); |
| | | return maxDate; |
| | | } |
| | | |
| | | } |
| | | |
| | | /** |
| | | * |
| | | * @return 获取当前session 中的用户对象 |
| | |
| | | Object obj=session.getAttribute("user"); |
| | | UserInf userInf = new UserInf(); |
| | | if(obj==null){ |
| | | userInf.setUName("superuser"); |
| | | userInf.setUId(1002L); |
| | | userInf.setURole(1); |
| | | userInf.setUName("未登录的用户账号"); |
| | | userInf.setUId(0L); |
| | | userInf.setURole(0); |
| | | }else{ |
| | | userInf=(UserInf) session.getAttribute("user"); |
| | | } |
| | |
| | | * @return |
| | | */ |
| | | public static boolean generateImage(String imgStr, String path) { |
| | | if (imgStr == null) |
| | | return false; |
| | | if (imgStr == null) { |
| | | return false; |
| | | } |
| | | BASE64Decoder decoder = new BASE64Decoder(); |
| | | try { |
| | | // 解密 |
| | |
| | | } |
| | | return sb.toString(); |
| | | } |
| | | |
| | | /** |
| | | * 使用timestamp+盐方式,进行签名验证 |
| | | * 当前时间戳为13位数 |
| | | */ |
| | | public static boolean checkSignMD5(String time,String randomStr,String sign){ |
| | | String usefulNum = randomStr; |
| | | //加盐方式,根据末尾的值进行不同的加密规则 |
| | | char lastChar = time.charAt(12); |
| | | int lastNum = Integer.parseInt(String.valueOf(lastChar)); |
| | | switch (lastNum){ |
| | | //在第一位加字符串 rd@c3doed |
| | | case 0: usefulNum += time.replace(String.valueOf(lastChar),"rd@c3dozero");break; |
| | | case 1: usefulNum += time.replace(String.valueOf(lastChar),"rd@c3doenoe");break; |
| | | case 2: usefulNum += time.replace(String.valueOf(lastChar),"rd@c3doktwo");break; |
| | | case 3: usefulNum += time.replace(String.valueOf(lastChar),"rd@c3dolthree");break; |
| | | case 4: usefulNum += time.replace(String.valueOf(lastChar),"rd@c3doexfour");break; |
| | | case 5: usefulNum += time.replace(String.valueOf(lastChar),"rd@c3doedefive");break; |
| | | case 6: usefulNum += time.replace(String.valueOf(lastChar),"rd@c3doedhsix");break; |
| | | case 7: usefulNum += time.replace(String.valueOf(lastChar),"rd@c3doedtseven");break; |
| | | case 8: usefulNum += time.replace(String.valueOf(lastChar),"rd@c3doedbeight");break; |
| | | case 9: usefulNum += time.replace(String.valueOf(lastChar),"rd@c3doedrnine");break; |
| | | } |
| | | //MD5加密后 |
| | | String signNow = (String) EncryptionMD5(usefulNum); |
| | | StringBuilder sb = new StringBuilder(); |
| | | for (int i = 0; i < 10; i++) { |
| | | sb.append(signNow.charAt(i * 2)); |
| | | } |
| | | String signResult = sb.append(signNow).toString(); |
| | | return sign.equals(signResult); |
| | | } |
| | | |
| | | //获取当前系统的语言环境 |
| | | public static String getLang() { |
| | | Locale locale = Locale.getDefault();//对Locale类实例化定义 |
| | | String lang = locale.getLanguage(); |
| | | String str = (String) ActionUtil.getSession().getAttribute("lang"); |
| | | if (str != null) { |
| | | lang = str; |
| | | } |
| | | return lang; |
| | | } |
| | | } |