Browse Source

Merge branch 'developer' of https://gitlab.com/Arisono/SkWeiChat-Baidu into csdn

Arison 9 years ago
parent
commit
a05dde4b79

+ 56 - 17
WeiChat/src/main/java/com/xzjmyk/pm/activity/ui/erp/activity/oa/ChangeMobileActivity.java

@@ -3,6 +3,7 @@ package com.xzjmyk.pm.activity.ui.erp.activity.oa;
 import android.os.Bundle;
 import android.os.Handler;
 import android.os.Message;
+import android.provider.Settings;
 import android.text.TextUtils;
 import android.view.View;
 import android.widget.Button;
@@ -23,9 +24,7 @@ import com.xzjmyk.pm.activity.ui.erp.util.StringUtils;
 import com.xzjmyk.pm.activity.util.TimeUtils;
 import com.xzjmyk.pm.activity.view.crouton.Crouton;
 
-import java.io.IOException;
-import java.io.InputStreamReader;
-import java.io.LineNumberReader;
+import java.io.FileInputStream;
 import java.util.HashMap;
 import java.util.LinkedHashMap;
 import java.util.Map;
@@ -93,7 +92,7 @@ public class ChangeMobileActivity extends BaseActivity {
     private void initView() {
         String mac = getMac();
         if (!StringUtils.isEmpty(mac))
-            mac_tv.setText(getMac());
+            mac_tv.setText(mac);
         exit_btn.setOnClickListener(new View.OnClickListener() {
             @Override
             public void onClick(View view) {
@@ -142,21 +141,61 @@ public class ChangeMobileActivity extends BaseActivity {
         ViewUtil.httpSendRequest(ct, url, param, handler, headers, 0x12, null, null, "get");
     }
 
-    public static String getMac() {
-        String macSerial = "";
+    public static String getLocalMacAddress() {
+        String mac = null;
         try {
-            Process pp = Runtime.getRuntime().exec("cat /sys/class/net/wlan0/address");
-            InputStreamReader ir = new InputStreamReader(pp.getInputStream());
-            LineNumberReader input = new LineNumberReader(ir);
-            String line;
-            while ((line = input.readLine()) != null) {
-                macSerial += line.trim();
+            String path = "sys/class/net/eth0/address";
+            FileInputStream fis_name = new FileInputStream(path);
+            byte[] buffer_name = new byte[8192];
+            int byteCount_name = fis_name.read(buffer_name);
+            if (byteCount_name > 0) {
+                mac = new String(buffer_name, 0, byteCount_name, "utf-8");
+            }
+            if (mac == null) {
+                fis_name.close();
+                return "";
+            }
+            fis_name.close();
+        } catch (Exception io) {
+            String path = "sys/class/net/wlan0/address";
+            FileInputStream fis_name;
+            try {
+                fis_name = new FileInputStream(path);
+                byte[] buffer_name = new byte[8192];
+                int byteCount_name = fis_name.read(buffer_name);
+                if (byteCount_name > 0) {
+                    mac = new String(buffer_name, 0, byteCount_name, "utf-8");
+                }
+                fis_name.close();
+            } catch (Exception e) {
+                // TODO Auto-generated catch block
+                e.printStackTrace();
             }
-
-            input.close();
-        } catch (IOException e) {
-            e.printStackTrace();
         }
-        return macSerial;
+        if (mac == null) {
+            return "";
+        } else {
+            return mac.trim();
+        }
+    }
+
+    public static String getMac() {
+        return Settings.Secure.getString(MyApplication.getInstance().getContentResolver(),
+                Settings.Secure.ANDROID_ID);
+//        String macSerial = "";
+//        try {
+//            Process pp = Runtime.getRuntime().exec("cat /sys/class/net/wlan0/address");
+//            InputStreamReader ir = new InputStreamReader(pp.getInputStream());
+//            LineNumberReader input = new LineNumberReader(ir);
+//            String line;
+//            while ((line = input.readLine()) != null) {
+//                macSerial += line.trim();
+//            }
+//
+//            input.close();
+//        } catch (IOException e) {
+//            e.printStackTrace();
+//        }
+//        return macSerial;
     }
 }

+ 67 - 21
WeiChat/src/main/java/com/xzjmyk/pm/activity/ui/erp/fragment/SigninFragment.java

@@ -6,6 +6,7 @@ import android.location.LocationManager;
 import android.os.Bundle;
 import android.os.Handler;
 import android.os.Message;
+import android.provider.Settings;
 import android.support.v7.app.ActionBar;
 import android.support.v7.widget.LinearLayoutManager;
 import android.support.v7.widget.RecyclerView;
@@ -47,9 +48,7 @@ import com.xzjmyk.pm.activity.util.TimeUtils;
 import com.xzjmyk.pm.activity.view.crouton.Crouton;
 import com.xzjmyk.pm.activity.view.wheel.OASigninPicker;
 
-import java.io.IOException;
-import java.io.InputStreamReader;
-import java.io.LineNumberReader;
+import java.io.FileInputStream;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.HashMap;
@@ -265,11 +264,17 @@ public class SigninFragment extends EasyFragment implements View.OnClickListener
                         Crouton.makeText(ct, "当前网络不可用,请检查网络连接");
                         return;
                     }
-                    if (isMacInNet) {
-                        validatorMac();
-                    } else {
-                        showFristMac();
-                    }
+                    CodeUtil.getInstance().getCode(ct, "CardLog", new CodeUtil.OnCodeLinstener() {
+                        @Override
+                        public void callBack(String code) {
+                            doSignin(code);
+                        }
+                    });
+//                    if (isMacInNet) {
+//                        validatorMac();
+//                    } else {
+//                        showFristMac();
+//                    }
                 }
                 break;
             case R.id.title:
@@ -380,7 +385,7 @@ public class SigninFragment extends EasyFragment implements View.OnClickListener
         listview.setAdapter(adapter);
         office_addr.setText(Html.fromHtml("<font color=\'#575757\'>当前位置  " + "</font><font color=\'#000000\'>" + addr + "</font>"));
         loadNetData(System.currentTimeMillis());//获取打卡班次信息
-        getMacByNet();
+//        getMacByNet();
         //判断是否有定位权限
         if (!isOpenGps()) {
             Crouton.makeText(ct, "为了更好体验,请打开GPS", 3000);
@@ -492,20 +497,61 @@ public class SigninFragment extends EasyFragment implements View.OnClickListener
     }
 
     public static String getMac() {
-        String macSerial = "";
+        return Settings.Secure.getString(MyApplication.getInstance().getContentResolver(),
+                Settings.Secure.ANDROID_ID);
+//        String macSerial = "";
+//        try {
+//            Process pp = Runtime.getRuntime().exec("cat /sys/class/net/wlan0/address");
+//            InputStreamReader ir = new InputStreamReader(pp.getInputStream());
+//            LineNumberReader input = new LineNumberReader(ir);
+//            String line;
+//            while ((line = input.readLine()) != null) {
+//                macSerial += line.trim();
+//            }
+//            input.close();
+//        } catch (IOException e) {
+//            e.printStackTrace();
+//        }
+//        return macSerial;
+    }
+
+
+    public static String getLocalMacAddress() {
+        String mac = null;
         try {
-            Process pp = Runtime.getRuntime().exec("cat /sys/class/net/wlan0/address");
-            InputStreamReader ir = new InputStreamReader(pp.getInputStream());
-            LineNumberReader input = new LineNumberReader(ir);
-            String line;
-            while ((line = input.readLine()) != null) {
-                macSerial += line.trim();
+            String path = "sys/class/net/eth0/address";
+            FileInputStream fis_name = new FileInputStream(path);
+            byte[] buffer_name = new byte[8192];
+            int byteCount_name = fis_name.read(buffer_name);
+            if (byteCount_name > 0) {
+                mac = new String(buffer_name, 0, byteCount_name, "utf-8");
             }
-            input.close();
-        } catch (IOException e) {
-            e.printStackTrace();
+            if (mac == null) {
+                fis_name.close();
+                return "";
+            }
+            fis_name.close();
+        } catch (Exception io) {
+            String path = "sys/class/net/wlan0/address";
+            FileInputStream fis_name;
+            try {
+                fis_name = new FileInputStream(path);
+                byte[] buffer_name = new byte[8192];
+                int byteCount_name = fis_name.read(buffer_name);
+                if (byteCount_name > 0) {
+                    mac = new String(buffer_name, 0, byteCount_name, "utf-8");
+                }
+                fis_name.close();
+            } catch (Exception e) {
+                // TODO Auto-generated catch block
+                e.printStackTrace();
+            }
+        }
+        if (mac == null) {
+            return "";
+        } else {
+            return mac.trim();
         }
-        return macSerial;
     }
 
     //前后90分钟,isU--是否是上班
@@ -704,7 +750,7 @@ public class SigninFragment extends EasyFragment implements View.OnClickListener
     private void validatorMac() {
         //获取网络数据
         String url = "mobile/addMobileMac.action";
-        String mac = getMac();
+        String mac = getLocalMacAddress();
         Map<String, Object> param = new HashMap<>();
         param.put("macAddress", mac);
         loadNet(url, param, 0x17);