Browse Source

Merge branch 'master' of http://116.62.119.248:10082/cheng_zq/EffectDemo into lwz_

LAPTOP-K69FCNBP\crius 2 years ago
parent
commit
b591f876c1

BIN
app/bestvedu.jks


+ 7 - 0
app/build.gradle

@@ -166,4 +166,11 @@ dependencies {
     implementation 'com.shuyu:GSYVideoPlayer:8.1.2'
     implementation 'com.blankj:utilcodex:1.31.0'
     implementation 'com.github.CymChad:BaseRecyclerViewAdapterHelper:3.0.3'
+
+    //网络请求
+    //RxJava
+    implementation 'io.reactivex.rxjava2:rxandroid:2.1.1'
+    implementation 'io.reactivex.rxjava2:rxjava:2.2.8'
+    implementation 'com.zhy:okhttputils:2.6.2'
+    implementation 'com.squareup.okhttp3:okhttp:4.2.2'
 }

+ 25 - 0
app/src/main/java/com/xunao/effectdemo/activity/MapChallengeActivity.java

@@ -5,10 +5,17 @@ import androidx.appcompat.app.AppCompatActivity;
 import android.app.Activity;
 import android.content.Intent;
 import android.os.Bundle;
+import android.util.Log;
 import android.view.View;
 import android.widget.Button;
 
 import com.xunao.effectdemo.R;
+import com.xunao.effectdemo.net.ApiHttpClient;
+import com.xunao.effectdemo.net.ApiUrl;
+import com.xunao.effectdemo.net.CSMHttpCallback;
+
+import java.util.HashMap;
+import java.util.Map;
 
 /**
  * 地图闯关
@@ -18,6 +25,9 @@ public class MapChallengeActivity extends Activity {
 
     Intent intent;
 
+    private String name = "13004166772";
+    private String pwd = "123890";
+
     @Override
     protected void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
@@ -45,4 +55,19 @@ public class MapChallengeActivity extends Activity {
         btnMap6 = findViewById(R.id.btn_map_6);
     }
 
+    void login(){
+        Map<String, String> params = new HashMap<>();
+        ApiHttpClient.get(ApiUrl.login, new CSMHttpCallback() {
+            @Override
+            protected void onSuccess(String jsonStr) {
+
+            }
+
+            @Override
+            protected void onFail(String msg) {
+
+            }
+        });
+    }
+
 }

+ 279 - 0
app/src/main/java/com/xunao/effectdemo/net/ApiHttpClient.java

@@ -0,0 +1,279 @@
+package com.xunao.effectdemo.net;
+
+import android.content.Context;
+import android.util.Base64;
+import android.util.Log;
+
+import com.google.gson.Gson;
+import com.google.gson.reflect.TypeToken;
+import com.xunao.effectdemo.App;
+import com.xunao.effectdemo.utils.EncryptUtil;
+import com.zhy.http.okhttp.OkHttpUtils;
+import com.zhy.http.okhttp.builder.PostStringBuilder;
+import com.zhy.http.okhttp.callback.BitmapCallback;
+import com.zhy.http.okhttp.callback.StringCallback;
+import com.zhy.http.okhttp.cookie.CookieJarImpl;
+import com.zhy.http.okhttp.cookie.store.PersistentCookieStore;
+
+import java.io.File;
+import java.io.IOException;
+import java.net.URLEncoder;
+import java.util.Comparator;
+import java.util.HashMap;
+import java.util.Locale;
+import java.util.Map;
+import java.util.TreeMap;
+import java.util.concurrent.TimeUnit;
+
+import okhttp3.Callback;
+import okhttp3.FormBody;
+import okhttp3.MediaType;
+import okhttp3.OkHttpClient;
+import okhttp3.Request;
+import okhttp3.Response;
+
+
+public class ApiHttpClient {
+    private static String API_URL = "";
+
+    public static OkHttpClient client;
+    public static HashMap<String, String> headers = new HashMap<>();
+    public static HashMap<String, String> bodys = new HashMap<>();
+
+    public static final String MEDIA_TYPE_JSON = "application/json; charset=utf-8";
+
+    public static Context mContext;
+
+    public ApiHttpClient() {
+
+    }
+
+    public static OkHttpClient getHttpClient() {
+        return client;
+    }
+
+    public static void init() {
+        mContext = App.getInstance();
+
+        CookieJarImpl cookieJar = new CookieJarImpl(new PersistentCookieStore(mContext));
+        OkHttpClient client = new OkHttpClient.Builder()
+                .connectTimeout(30, TimeUnit.SECONDS)
+                .writeTimeout(30, TimeUnit.SECONDS)
+                .readTimeout(30, TimeUnit.SECONDS)
+                .followRedirects(true)
+                .cookieJar(cookieJar)
+                .retryOnConnectionFailure(true)
+                .build();
+        OkHttpUtils.initClient(client);
+
+        addHeader("Accept-Language", Locale.getDefault().toString());
+        addHeader("Accept", MEDIA_TYPE_JSON);
+    }
+
+    public static String getAbsoluteApiUrl(String partUrl) {
+//        String url = String.format(API_URL, partUrl);
+        return partUrl;
+    }
+
+    public static void get(String partUrl, CSMHttpCallback callback) {
+        OkHttpUtils
+                .get()
+                .url(getAbsoluteApiUrl(partUrl))
+                .headers(headers)
+                .build()
+                .execute(callback);
+    }
+
+    public static void get(String partUrl, Map<String, String> params,CSMHttpCallback callback) {
+        OkHttpUtils
+                .get()
+                .url(getAbsoluteApiUrl(partUrl))
+                .headers(headers)
+                .build()
+                .execute(callback);
+    }
+
+    public static void post(String partUrl, CSMHttpCallback callback) {
+        OkHttpUtils
+                .post()
+                .url(getAbsoluteApiUrl(partUrl))
+                .headers(headers)
+                .build()
+                .execute(callback);
+    }
+
+    public static void post(String partUrl, Map<String, String> params, CSMHttpCallback callback) {
+        try {
+//            params.put("app_type","android");
+//            params.put("app_version",BmonsterApplication.version);
+            addHeader("param", generateSignStr(params));//
+            String jsonParam = new Gson().toJson(params);
+            params = new Gson().fromJson(jsonParam, new TypeToken<HashMap<String, String>>(){}.getType());
+            OkHttpUtils
+                    .post()
+                    .url(getAbsoluteApiUrl(partUrl))
+                    .headers(headers)
+                    .params(params)
+                    .build()
+                    .execute(callback);
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+    }
+
+    public static void post2(String partUrl, Map<String, String> params,Map<String,String> map, CSMHttpCallback callback) {
+        try {
+//            params.put("app_type","android");
+//            params.put("app_version",BmonsterApplication.version);
+//            addHeader("post", generateSignStr(params));//
+            String jsonParam = new Gson().toJson(params);
+            params = new Gson().fromJson(jsonParam, new TypeToken<HashMap<String, String>>(){}.getType());
+            FormBody.Builder formBody = new FormBody.Builder();//创建表单请求体
+//            formBody.add("username","zhangsan");//传递键值对参数
+            OkHttpUtils
+                    .post()
+                    .url(getAbsoluteApiUrl(partUrl))
+                    .headers(headers)
+                    .params(params)
+                    .build()
+                    .execute(callback);
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+    }
+
+    public static void postBody(String partUrl, Map<String, String> params, MapBodyBean bean, Callback callback){
+
+        try {
+
+            Gson gson = new Gson();
+            //  转换层json字符串
+            final String s = gson.toJson(bean);
+            //  创建  RequestBody
+            String msg = generateSignStr(params);
+
+//            RequestBody requestBody = RequestBody.create(MediaType.parse("application/json"), s);
+//            Request request = new Request.Builder().url(partUrl).header("param", msg)
+//                    .post(requestBody).build();
+
+            FormBody.Builder formBody = new FormBody.Builder();//创建表单请求体
+            formBody.add("speed_list",bean.getSpeed_list());//传递键值对参数
+            formBody.add("height_list",bean.getHeight_list());//传递键值对参数
+            formBody.add("location_list",bean.getLocation_list());//传递键值对参数
+            Request request = new Request.Builder()//创建Request 对象。
+                    .url(partUrl)
+                    .header("param", msg)
+                    .post(formBody.build())//传递请求体
+                    .build();
+
+            OkHttpClient okHttpClient1 = OkHttpUtils.getInstance().getOkHttpClient();
+            okHttpClient1.newCall(request).enqueue(callback);
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+
+    }
+
+
+
+    public static void post(String partUrl, Map<String, String> params, String fileParamName, File file, CSMHttpCallback callback) {
+        try {
+            OkHttpUtils
+                    .post()
+                    .url(getAbsoluteApiUrl(partUrl))
+                    .headers(headers)
+                    .params(params)
+                    .addFile(fileParamName, file.getName(), file)
+                    .build()
+                    .execute(callback);
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+    }
+
+    public static void postJson(String partUrl, String json, CSMHttpCallback callback) {
+
+        OkHttpUtils
+                .postString()
+                .url(getAbsoluteApiUrl(partUrl))
+                .content(json)
+                .mediaType(MediaType.parse(MEDIA_TYPE_JSON))
+                .headers(headers)
+                .build()
+                .execute(callback);
+    }
+
+    public static void postJsonAsync(String partUrl, String json, BitmapCallback callback) {
+        PostStringBuilder builder = OkHttpUtils
+                .postString()
+                .url(partUrl)
+                .mediaType(MediaType.parse(MEDIA_TYPE_JSON));
+        if (json != null) {
+            builder.content(json);
+        }
+        builder.build().execute(callback);
+    }
+
+    public static Response getFormSync(String partUrl) {
+        try {
+            Response response = OkHttpUtils
+                    .get()
+                    .url(partUrl)
+                    .build()
+                    .execute();
+            return response;
+        } catch (IOException e) {
+            return null;
+        }
+    }
+
+    public static void getAsync(String partUrl, StringCallback callback) {
+        OkHttpUtils
+                .get()
+                .url(partUrl)
+                .build()
+                .execute(callback);
+    }
+
+    public static void addHeader(String key, String value) {
+        if (headers.containsKey(key)) {
+            headers.remove(key);
+        }
+        headers.put(key, value);
+    }
+
+    public static void addBodys(String key, String value) {
+        if (bodys.containsKey(key)) {
+            bodys.remove(key);
+        }
+        bodys.put(key, value);
+    }
+
+    private static String generateSignStr(Map<String, String> params) {
+        //1、将请求数据按照key字典序排序后的数组
+        Map<String, String> sortMap = new TreeMap((Comparator<String>) (s, t1) -> s.compareTo(t1));
+        sortMap.putAll(params);
+        //2、将所有的请求数据拼接为字符串
+        StringBuilder sb = new StringBuilder();
+        for (String value:sortMap.values()) {
+            sb.append(value);
+        }
+        //3、将 $str urlencode 加密
+        String encodeStr = URLEncoder.encode(sb.toString());
+        //4、将上面加密的字符串转化为小写
+        encodeStr = encodeStr.toLowerCase();
+        //5、转化为小写之后再进行md5加密
+        String md5Str = EncryptUtil.md5(encodeStr);
+        //生成signStr之后的请求参数数组
+        Map<String, Object> map = new HashMap();
+        map.put("params", sortMap);
+        map.put("signStr", md5Str);
+        //6、将请求数组转化为json格式
+        String json = new Gson().toJson(map);
+        //将上一步生成的json数据转化为 base64 格式数据
+        Log.d("json", json);
+        Log.d("base64", Base64.encodeToString(json.getBytes(), Base64.NO_WRAP));
+        return Base64.encodeToString(json.getBytes(), Base64.NO_WRAP);
+    }
+}
+

+ 14 - 0
app/src/main/java/com/xunao/effectdemo/net/ApiUrl.java

@@ -0,0 +1,14 @@
+package com.xunao.effectdemo.net;
+
+
+public class ApiUrl {
+
+
+    /**
+     *测试环境
+     */
+    public static final String url = "http://stuapi.kidcastle.cn/";
+
+    public static final String login = url+"Base/Login";
+
+}

+ 51 - 0
app/src/main/java/com/xunao/effectdemo/net/BaseBean.java

@@ -0,0 +1,51 @@
+package com.xunao.effectdemo.net;
+
+import com.google.gson.Gson;
+import com.xunao.effectdemo.utils.StringUtil;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.Serializable;
+
+
+public class BaseBean implements Serializable {
+
+    public static BaseBean parse(InputStream inputStream) throws IOException {
+        String jsonStr = StringUtil.inputStream2String(inputStream, "utf-8");
+        return parse(jsonStr);
+    }
+
+    public static BaseBean parse(String jsonStr) {
+        Gson gson = new Gson();
+        BaseBean baseBean = gson.fromJson(jsonStr, BaseBean.class);
+        return baseBean;
+    }
+
+    private String retCode;
+    private String retMsgJp;
+    private String retMsgEn;
+
+    public String getRetCode() {
+        return retCode;
+    }
+
+    public void setRetCode(String retCode) {
+        this.retCode = retCode;
+    }
+
+    public String getRetMsgJp() {
+        return retMsgJp;
+    }
+
+    public void setRetMsgJp(String retMsgJp) {
+        this.retMsgJp = retMsgJp;
+    }
+
+    public String getRetMsgEn() {
+        return retMsgEn;
+    }
+
+    public void setRetMsgEn(String retMsgEn) {
+        this.retMsgEn = retMsgEn;
+    }
+}

+ 68 - 0
app/src/main/java/com/xunao/effectdemo/net/CSMHttpCallback.java

@@ -0,0 +1,68 @@
+package com.xunao.effectdemo.net;
+
+import android.text.TextUtils;
+import android.util.Log;
+
+import com.xunao.effectdemo.utils.StringUtil;
+import com.zhy.http.okhttp.callback.Callback;
+
+import java.io.ByteArrayInputStream;
+
+import okhttp3.Call;
+import okhttp3.Response;
+
+public abstract class CSMHttpCallback extends Callback<String> {
+
+    private final static String TAG = CSMHttpCallback.class.getName();
+
+    protected abstract void onSuccess(String jsonStr);
+
+    protected abstract void onFail(String msg);
+
+    @Override
+    public boolean validateReponse(Response response, int id) {
+        return true;
+    }
+
+    @Override
+    public String parseNetworkResponse(Response response, int id) throws Exception {
+        String url = response.request().url().toString();
+        String responseStr = StringUtil.inputStream2String(new ByteArrayInputStream(response.body().bytes()), "utf-8");
+
+        switch (response.code()) {
+            case 200:
+                return responseStr;
+            case 401:
+                break;
+            default:
+        }
+        return "";
+    }
+
+    @Override
+    public void onError(Call call, Exception exception, int id) {
+        exception.printStackTrace();
+    }
+
+    @Override
+    public void onResponse(String response, int id) {
+        Log.i(TAG, "response==>" + response);
+        if (!TextUtils.isEmpty(response)) {
+            if (response.contains("retCode")){
+                BaseBean baseBean = BaseBean.parse(response);
+                if (baseBean.getRetCode().equals("1000")) {
+                    onSuccess(response);
+                }else if(baseBean.getRetCode().equals("1007")||baseBean.getRetCode().equals("1005")){
+                    onFail("1007");
+
+                } else {
+                    onFail("请求报错");
+                }
+            }else{
+                onSuccess(response);
+            }
+        } else {
+//            onFail(BmonsterApplication.resources().getString(R.string.net_error));
+        }
+    }
+}

+ 32 - 0
app/src/main/java/com/xunao/effectdemo/net/MapBodyBean.java

@@ -0,0 +1,32 @@
+package com.xunao.effectdemo.net;
+
+public class MapBodyBean {
+
+    private String speed_list;
+    private String height_list;
+    private String location_list;
+
+    public String getSpeed_list() {
+        return speed_list;
+    }
+
+    public void setSpeed_list(String speed_list) {
+        this.speed_list = speed_list;
+    }
+
+    public String getHeight_list() {
+        return height_list;
+    }
+
+    public void setHeight_list(String height_list) {
+        this.height_list = height_list;
+    }
+
+    public String getLocation_list() {
+        return location_list;
+    }
+
+    public void setLocation_list(String location_list) {
+        this.location_list = location_list;
+    }
+}

+ 30 - 0
app/src/main/java/com/xunao/effectdemo/utils/EncryptUtil.java

@@ -0,0 +1,30 @@
+package com.xunao.effectdemo.utils;
+
+import java.io.UnsupportedEncodingException;
+import java.security.MessageDigest;
+import java.security.NoSuchAlgorithmException;
+
+/**
+ * Created by chris on 15/5/21.
+ */
+public class EncryptUtil {
+
+    public static String md5(String string) {
+        byte[] hash;
+        try {
+            hash = MessageDigest.getInstance("MD5").digest(string.getBytes("UTF-8"));
+        } catch (NoSuchAlgorithmException e) {
+            throw new RuntimeException("Huh, MD5 should be supported?", e);
+        } catch (UnsupportedEncodingException e) {
+            throw new RuntimeException("Huh, UTF-8 should be supported?", e);
+        }
+
+        StringBuilder hex = new StringBuilder(hash.length * 2);
+        for (byte b : hash) {
+            if ((b & 0xFF) < 0x10) hex.append("0");
+            hex.append(Integer.toHexString(b & 0xFF));
+        }
+        return hex.toString();
+    }
+
+}

+ 777 - 0
app/src/main/java/com/xunao/effectdemo/utils/StringUtil.java

@@ -0,0 +1,777 @@
+package com.xunao.effectdemo.utils;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.math.BigDecimal;
+import java.text.DecimalFormat;
+import java.text.NumberFormat;
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.util.Calendar;
+import java.util.Date;
+import java.util.TimeZone;
+import java.util.regex.Pattern;
+
+public class StringUtil {
+
+    private final static String FSpliter = "##";
+    private final static String SSpliter = "||";
+
+    private final static Pattern PHONE = Pattern.compile("^((13[0-9])|(15[^4,\\D])|(18[0,5-9]))\\d{8}$");
+
+    private final static Pattern emailer = Pattern
+            .compile("\\w+([-+.]\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*");
+
+    private final static Pattern IMG_URL = Pattern
+            .compile(".*?(gif|jpeg|png|jpg|bmp)");
+
+    private final static Pattern URL = Pattern
+            .compile("^(https|http)://.*?$(net|com|.com.cn|org|me|)");
+
+    private final static ThreadLocal<SimpleDateFormat> dateFormater = new ThreadLocal<SimpleDateFormat>() {
+        @Override
+        protected SimpleDateFormat initialValue() {
+            return new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+        }
+    };
+
+    private final static ThreadLocal<SimpleDateFormat> dateFormater2 = new ThreadLocal<SimpleDateFormat>() {
+        @Override
+        protected SimpleDateFormat initialValue() {
+            return new SimpleDateFormat("yyyy-MM-dd");
+        }
+    };
+
+    /**
+     * 将字符串转位日期类型
+     *
+     * @param sdate
+     * @return
+     */
+    public static Date toDate(String sdate) {
+        return toDate(sdate, dateFormater.get());
+    }
+
+    public static Date toDate(String sdate, SimpleDateFormat dateFormater) {
+        try {
+            return dateFormater.parse(sdate);
+        } catch (ParseException e) {
+            return null;
+        }
+    }
+
+    public static String getDateString(Date date) {
+        return dateFormater.get().format(date);
+    }
+
+    /**
+     * 以友好的方式显示时间
+     *
+     * @param sdate
+     * @return
+     */
+    public static String friendly_time(String sdate) {
+        Date time = null;
+
+        if (TimeZoneUtil.isInEasternEightZones())
+            time = toDate(sdate);
+        else
+            time = TimeZoneUtil.transformTime(toDate(sdate),
+                    TimeZone.getTimeZone("GMT+08"), TimeZone.getDefault());
+
+        if (time == null) {
+            return "Unknown";
+        }
+        String ftime = "";
+        Calendar cal = Calendar.getInstance();
+
+        // 判断是否是同一天
+        String curDate = dateFormater2.get().format(cal.getTime());
+        String paramDate = dateFormater2.get().format(time);
+        if (curDate.equals(paramDate)) {
+            int hour = (int) ((cal.getTimeInMillis() - time.getTime()) / 3600000);
+            if (hour == 0)
+                ftime = Math.max(
+                        (cal.getTimeInMillis() - time.getTime()) / 60000, 1)
+                        + "分钟前";
+            else
+                ftime = hour + "小时前";
+            return ftime;
+        }
+
+        long lt = time.getTime() / 86400000;
+        long ct = cal.getTimeInMillis() / 86400000;
+        int days = (int) (ct - lt);
+        if (days == 0) {
+            int hour = (int) ((cal.getTimeInMillis() - time.getTime()) / 3600000);
+            if (hour == 0)
+                ftime = Math.max(
+                        (cal.getTimeInMillis() - time.getTime()) / 60000, 1)
+                        + "分钟前";
+            else
+                ftime = hour + "小时前";
+        } else if (days == 1) {
+            ftime = "昨天";
+        } else if (days == 2) {
+            ftime = "前天 ";
+        } else if (days > 2 && days < 31) {
+            ftime = days + "天前";
+        } else if (days >= 31 && days <= 2 * 31) {
+            ftime = "一个月前";
+        } else if (days > 2 * 31 && days <= 3 * 31) {
+            ftime = "2个月前";
+        } else if (days > 3 * 31 && days <= 4 * 31) {
+            ftime = "3个月前";
+        } else {
+            ftime = dateFormater2.get().format(time);
+        }
+        return ftime;
+    }
+
+    public static String friendly_time2(String sdate) {
+        String res = "";
+        if (isEmpty(sdate))
+            return "";
+
+        String[] weekDays = {"星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六"};
+        String currentData = StringUtil.getDataTime("MM-dd");
+        int currentDay = toInt(currentData.substring(3));
+        int currentMoth = toInt(currentData.substring(0, 2));
+
+        int sMoth = toInt(sdate.substring(5, 7));
+        int sDay = toInt(sdate.substring(8, 10));
+        int sYear = toInt(sdate.substring(0, 4));
+        Date dt = new Date(sYear, sMoth - 1, sDay - 1);
+
+        if (sDay == currentDay && sMoth == currentMoth) {
+            res = "今天 / " + weekDays[getWeekOfDate(new Date())];
+        } else if (sDay == currentDay + 1 && sMoth == currentMoth) {
+            res = "昨天 / " + weekDays[(getWeekOfDate(new Date()) + 6) % 7];
+        } else {
+            if (sMoth < 10) {
+                res = "0";
+            }
+            res += sMoth + "/";
+            if (sDay < 10) {
+                res += "0";
+            }
+            res += sDay + " / " + weekDays[getWeekOfDate(dt)];
+        }
+
+        return res;
+    }
+
+    /**
+     * 获取当前日期是星期几<br>
+     *
+     * @param dt
+     * @return 当前日期是星期几
+     */
+    public static int getWeekOfDate(Date dt) {
+        Calendar cal = Calendar.getInstance();
+        cal.setTime(dt);
+        int w = cal.get(Calendar.DAY_OF_WEEK) - 1;
+        if (w < 0)
+            w = 0;
+        return w;
+    }
+
+    /**
+     * 判断给定字符串时间是否为今日
+     *
+     * @param sdate
+     * @return boolean
+     */
+    public static boolean isToday(String sdate) {
+        boolean b = false;
+        Date time = toDate(sdate);
+        Date today = new Date();
+        if (time != null) {
+            String nowDate = dateFormater2.get().format(today);
+            String timeDate = dateFormater2.get().format(time);
+            if (nowDate.equals(timeDate)) {
+                b = true;
+            }
+        }
+        return b;
+    }
+
+    /**
+     * 返回long类型的今天的日期
+     *
+     * @return
+     */
+    public static long getToday() {
+        Calendar cal = Calendar.getInstance();
+        String curDate = dateFormater2.get().format(cal.getTime());
+        curDate = curDate.replace("-", "");
+        return Long.parseLong(curDate);
+    }
+
+    public static String getCurTimeStr() {
+        Calendar cal = Calendar.getInstance();
+        String curDate = dateFormater.get().format(cal.getTime());
+        return curDate;
+    }
+
+    /***
+     * 计算两个时间差,返回的是的秒s
+     *
+     * @param dete1
+     * @param date2
+     * @return
+     * @author 火蚁 2015-2-9 下午4:50:06
+     */
+    public static long calDateDifferent(String dete1, String date2) {
+
+        long diff = 0;
+
+        Date d1 = null;
+        Date d2 = null;
+
+        try {
+            d1 = dateFormater.get().parse(dete1);
+            d2 = dateFormater.get().parse(date2);
+
+            // 毫秒ms
+            diff = d2.getTime() - d1.getTime();
+
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+
+        return diff / 1000;
+    }
+
+    public static String getChineseForNum(int num) {
+        String chineseNum = "";
+        switch (num) {
+            case 0:
+                chineseNum = "零";
+                break;
+            case 1:
+                chineseNum = "一";
+                break;
+            case 2:
+                chineseNum = "二";
+                break;
+            case 3:
+                chineseNum = "三";
+                break;
+            case 4:
+                chineseNum = "四";
+                break;
+            case 5:
+                chineseNum = "五";
+                break;
+            case 6:
+                chineseNum = "六";
+                break;
+            case 7:
+                chineseNum = "七";
+                break;
+            case 8:
+                chineseNum = "八";
+                break;
+            case 9:
+                chineseNum = "九";
+                break;
+            case 10:
+                chineseNum = "十";
+                break;
+        }
+        return chineseNum;
+    }
+
+    /**
+     * 判断给定字符串是否空白串。 空白串是指由空格、制表符、回车符、换行符组成的字符串 若输入字符串为null或空字符串,返回true
+     *
+     * @param input
+     * @return boolean
+     */
+    public static boolean isEmpty(String input) {
+        if (input == null || "".equals(input))
+            return true;
+
+        for (int i = 0; i < input.length(); i++) {
+            char c = input.charAt(i);
+            if (c != ' ' && c != '\t' && c != '\r' && c != '\n') {
+                return false;
+            }
+        }
+        return true;
+    }
+
+    public static boolean isPhone(String phone) {
+        if (phone == null || phone.trim().length() == 0) {
+            return false;
+        }
+        return PHONE.matcher(phone).matches();
+    }
+
+    /**
+     * 判断是不是一个合法的电子邮件地址
+     *
+     * @param email
+     * @return
+     */
+    public static boolean isEmail(String email) {
+        if (email == null || email.trim().length() == 0)
+            return false;
+        return emailer.matcher(email).matches();
+    }
+
+    /**
+     * 判断一个url是否为图片url
+     *
+     * @param url
+     * @return
+     */
+    public static boolean isImgUrl(String url) {
+        if (url == null || url.trim().length() == 0)
+            return false;
+        return IMG_URL.matcher(url).matches();
+    }
+
+    /**
+     * 判断是否为一个合法的url地址
+     *
+     * @param str
+     * @return
+     */
+    public static boolean isUrl(String str) {
+        if (str == null || str.trim().length() == 0)
+            return false;
+        return URL.matcher(str).matches();
+    }
+
+    /**
+     * 字符串转整数
+     *
+     * @param str
+     * @param defValue
+     * @return
+     */
+    public static int toInt(String str, int defValue) {
+        try {
+            return Integer.parseInt(str);
+        } catch (Exception e) {
+        }
+        return defValue;
+    }
+
+    /**
+     * 对象转整数
+     *
+     * @param obj
+     * @return 转换异常返回 0
+     */
+    public static int toInt(Object obj) {
+        if (obj == null)
+            return 0;
+        return toInt(obj.toString(), 0);
+    }
+
+    /**
+     * 对象转整数
+     *
+     * @param obj
+     * @return 转换异常返回 0
+     */
+    public static long toLong(String obj) {
+        try {
+            return Long.parseLong(obj);
+        } catch (Exception e) {
+        }
+        return 0;
+    }
+
+    /**
+     * 字符串转布尔值
+     *
+     * @param b
+     * @return 转换异常返回 false
+     */
+    public static boolean toBool(String b) {
+        try {
+            return Boolean.parseBoolean(b);
+        } catch (Exception e) {
+        }
+        return false;
+    }
+
+    public static String getString(String s) {
+        return s == null ? "" : s;
+    }
+
+    /**
+     * 将一个InputStream流转换成字符串
+     *
+     * @param is
+     * @return
+     */
+    public static String toConvertString(InputStream is) {
+        StringBuffer res = new StringBuffer();
+        InputStreamReader isr = new InputStreamReader(is);
+        BufferedReader read = new BufferedReader(isr);
+        try {
+            String line;
+            line = read.readLine();
+            while (line != null) {
+                res.append(line + "<br>");
+                line = read.readLine();
+            }
+        } catch (IOException e) {
+            e.printStackTrace();
+        } finally {
+            try {
+                if (null != isr) {
+                    isr.close();
+                    isr.close();
+                }
+                if (null != read) {
+                    read.close();
+                    read = null;
+                }
+                if (null != is) {
+                    is.close();
+                    is = null;
+                }
+            } catch (IOException e) {
+            }
+        }
+        return res.toString();
+    }
+
+    /***
+     * 截取字符串
+     *
+     * @param start 从那里开始,0算起
+     * @param num   截取多少个
+     * @param str   截取的字符串
+     * @return
+     */
+    public static String getSubString(int start, int num, String str) {
+        if (str == null) {
+            return "";
+        }
+        int leng = str.length();
+        if (start < 0) {
+            start = 0;
+        }
+        if (start > leng) {
+            start = leng;
+        }
+        if (num < 0) {
+            num = 1;
+        }
+        int end = start + num;
+        if (end > leng) {
+            end = leng;
+        }
+        return str.substring(start, end);
+    }
+
+    /**
+     * 获取当前时间为每年第几周
+     *
+     * @return
+     */
+    public static int getWeekOfYear() {
+        return getWeekOfYear(new Date());
+    }
+
+    /**
+     * 获取当前时间为每年第几周
+     *
+     * @param date
+     * @return
+     */
+    public static int getWeekOfYear(Date date) {
+        Calendar c = Calendar.getInstance();
+        c.setFirstDayOfWeek(Calendar.MONDAY);
+        c.setTime(date);
+        int week = c.get(Calendar.WEEK_OF_YEAR) - 1;
+        week = week == 0 ? 52 : week;
+        return week > 0 ? week : 1;
+    }
+
+    public static int[] getCurrentDate() {
+        int[] dateBundle = new int[3];
+        String[] temp = getDataTime("yyyy-MM-dd").split("-");
+
+        for (int i = 0; i < 3; i++) {
+            try {
+                dateBundle[i] = Integer.parseInt(temp[i]);
+            } catch (Exception e) {
+                dateBundle[i] = 0;
+            }
+        }
+        return dateBundle;
+    }
+
+    /**
+     * 返回当前系统时间
+     */
+    public static String getDataTime(String format) {
+        SimpleDateFormat df = new SimpleDateFormat(format);
+        return df.format(new Date());
+    }
+
+    /**
+     * 将一个InputStream流转换成字符串,UTF-8
+     */
+    public static String inputStream2String(InputStream is, String code) throws IOException {
+
+        BufferedReader in = new BufferedReader(new InputStreamReader(is, code));
+
+        int i = -1;
+        char[] b = new char[1000];
+        StringBuffer sb = new StringBuffer();
+
+        while ((i = in.read(b)) != -1) {
+            sb.append(new String(b, 0, i));
+        }
+        String content = sb.toString();
+        return content;
+    }
+
+    /**
+     * 将一个替换一个字符串中的某几个字符
+     */
+    public static String replaceStringForPosition(String res, String str, int start, int end) {
+        String head = res.substring(0, start - 1);
+        String body = str;
+        String tail = res.substring(end - 1);
+        return head + body + tail;
+    }
+
+    public static String getWanMoney(double money) {
+        double tempDouble = money / 10000;
+        if (tempDouble < 1) {
+            return String.valueOf((int) money);
+        } else {
+            NumberFormat nf = new DecimalFormat("#.#");
+            String strMoney = nf.format(tempDouble) + "万";
+            return strMoney;
+        }
+    }
+
+    public static String getFormatMoney(double money) {
+        NumberFormat nf = new DecimalFormat(",###");
+        String strMoney = nf.format(money);
+        return strMoney;
+    }
+
+    public static String getFormatMoneyOnePoint(double money) {
+        DecimalFormat nf = new DecimalFormat("#.#");
+        String strMoney = nf.format(new BigDecimal(money));
+        String[] strsTmp = strMoney.split("\\.");
+        if (strsTmp.length < 2) {
+            strMoney = strMoney + ".0";
+        } else {
+            if (strsTmp[1].length() > 1) {
+                strsTmp[1] = strsTmp[1].substring(0, 1);
+            }
+            strMoney = strsTmp[0] + "." + strsTmp[1];
+        }
+
+        return strMoney;
+    }
+
+    public static String getFormatMoneyTwoPoint(double money) {
+        DecimalFormat nf = new DecimalFormat("#.##");
+        String strMoney = nf.format(new BigDecimal(money));
+
+        String[] strsTmp = strMoney.split("\\.");
+        if (strsTmp.length < 2) {
+            strMoney = strMoney + ".00";
+        } else {
+            if (strsTmp[1].length() == 1) {
+                strsTmp[1] = strsTmp[1] + "0";
+            }
+            if (strsTmp[1].length() > 2) {
+                strsTmp[1] = strsTmp[1].substring(0, 2);
+            }
+            strMoney = strsTmp[0] + "." + strsTmp[1];
+        }
+
+        return strMoney;
+    }
+
+    public static String getFormatMoneyTwoPointFen(long money) {
+        String strMoney = String.valueOf(money);
+        strMoney = strMoney.substring(0, strMoney.length() - 2) + "." + strMoney.substring(strMoney.length() - 2);
+        return strMoney;
+    }
+
+    public static String[] splitStringsWithSpace(String source) {
+        if (StringUtil.isEmpty(source)) {
+            return null;
+        }
+
+        source = source + " .";
+        String tempSource = source.replace("[", "").replace("]", "");
+        String[] tempStrs = tempSource.split(" ");
+        String[] strs = new String[tempStrs.length - 1];
+        for (int i = 0; i < strs.length; i++) {
+            strs[i] = tempStrs[i];
+        }
+        return strs;
+    }
+
+    public static int[] spliteIntWithSpace(String source) {
+        if (StringUtil.isEmpty(source)) {
+            return null;
+        }
+
+        String[] strings = splitStringsWithSpace(source);
+        int[] ints = new int[strings.length];
+        for (int i = 0; i < strings.length; i++) {
+            ints[i] = Integer.valueOf(strings[i]);
+        }
+        return ints;
+    }
+
+    /**
+     * 定义size位整数,如果位数达不到,前面用0补齐
+     * 如果超出位数,用规定位数最大数补齐
+     * */
+    public static String formatSizedNum(int num, int size) {
+        String strNum = String.valueOf(num);
+        if (strNum.length() < size) {
+            while(strNum.length() < size) {
+                strNum = "0" + strNum;
+            }
+        } else if (strNum.length() > size) {
+            strNum = "";
+            while(strNum.length() < size) {
+                strNum += "9";
+            }
+        }
+        return strNum;
+    }
+
+    /**
+     * 用##分割
+     */
+    public static String[] spliteStringWithFS(String source) {
+        if (StringUtil.isEmpty(source)) {
+            return null;
+        }
+
+        String[] strs = source.split(FSpliter);
+        return strs;
+    }
+
+    /**
+     * 用||分割
+     */
+    public static String[] spliteStringWithSS(String source) {
+        if (StringUtil.isEmpty(source)) {
+            return null;
+        }
+
+        String[] strs = source.split(SSpliter);
+        return strs;
+    }
+
+    public static boolean isSame(String source, String target) {
+        if (source == null && target != null) {
+            return false;
+        } else if (source != null && target == null) {
+            return false;
+        } else if (source == target) {
+            return true;
+        } else if (source.equals(target)) {
+            return true;
+        } else {
+            return false;
+        }
+    }
+
+    public static String encryptionPhone(String phone) {
+        StringBuilder builder = new StringBuilder(phone);
+        if (phone.length() >= 11) {
+            for (int i = 3; i < phone.length() - 4; i++) {
+                builder.setCharAt(i, '*');
+            }
+        } else {
+            for (int i = 2; i < phone.length() - 2; i++) {
+                builder.setCharAt(i, '*');
+            }
+        }
+        return builder.toString();
+    }
+
+    /**
+     * 将字符串中的Unicode编码转换成UTF-8
+     * */
+    public static String decodeUnicode(String theString) {
+        char aChar;
+        int len = theString.length();
+        StringBuffer outBuffer = new StringBuffer(len);
+        for (int x = 0; x < len;) {
+            aChar = theString.charAt(x++);
+            if (aChar == '\\') {
+                aChar = theString.charAt(x++);
+                if (aChar == 'u') {
+                    // Read the xxxx
+                    int value = 0;
+                    for (int i = 0; i < 4; i++) {
+                        aChar = theString.charAt(x++);
+                        switch (aChar) {
+                            case '0':
+                            case '1':
+                            case '2':
+                            case '3':
+                            case '4':
+                            case '5':
+                            case '6':
+                            case '7':
+                            case '8':
+                            case '9':
+                                value = (value << 4) + aChar - '0';
+                                break;
+                            case 'a':
+                            case 'b':
+                            case 'c':
+                            case 'd':
+                            case 'e':
+                            case 'f':
+                                value = (value << 4) + 10 + aChar - 'a';
+                                break;
+                            case 'A':
+                            case 'B':
+                            case 'C':
+                            case 'D':
+                            case 'E':
+                            case 'F':
+                                value = (value << 4) + 10 + aChar - 'A';
+                                break;
+                            default:
+                                throw new IllegalArgumentException(
+                                        "Malformed   \\uxxxx   encoding.");
+                        }
+
+                    }
+                    outBuffer.append((char) value);
+                } else {
+                    if (aChar == 't')
+                        aChar = '\t';
+                    else if (aChar == 'r')
+                        aChar = '\r';
+                    else if (aChar == 'n')
+                        aChar = '\n';
+                    else if (aChar == 'f')
+                        aChar = '\f';
+                    outBuffer.append(aChar);
+                }
+            } else
+                outBuffer.append(aChar);
+        }
+        return outBuffer.toString();
+    }
+}