打卡判断,增加前端浏览器mac获取,当mac获取为空时不判断
| | |
| | | } |
| | | |
| | | #region 考勤打卡 |
| | | |
| | | public ResultEntity save(string id, int signinType) |
| | | { |
| | | ResultEntity resultEntity = new ResultEntity(); |
| | |
| | | using Microsoft.AspNetCore.Http; |
| | | using Newtonsoft.Json.Linq; |
| | | using System.Transactions; |
| | | using System.Runtime.InteropServices; |
| | | |
| | | namespace zhengcaioa.Controllers.AdmManagement |
| | | { |
| | |
| | | /// <param name="signinType">10早上上班 11早上下班 20下午上班 21下午下班 30加班上班 31加班下班</param> |
| | | /// <returns></returns> |
| | | [CheckLogin] |
| | | public string Save(string id,int signinType) |
| | | { |
| | | ResultEntity resultEntity = _signinService.save(id, signinType); |
| | | public string Save(string id,int signinType,string mac) |
| | | { |
| | | ResultEntity resultEntity = new ResultEntity(); |
| | | resultEntity.Result = false; |
| | | try |
| | | { |
| | | if (string.IsNullOrEmpty(mac)) |
| | | { |
| | | resultEntity = _signinService.save(id, signinType); |
| | | } |
| | | else |
| | | { |
| | | var curentuser = JsonConvert.DeserializeObject<PltUser>(HttpContext.Session.GetString("User")); |
| | | if(curentuser.IpMac == mac) |
| | | { |
| | | //var mac = GetClientMAC(GetClientIP()); |
| | | |
| | | } |
| | | else |
| | | { |
| | | resultEntity.Message = "打卡电脑检查不匹配。"; |
| | | } |
| | | } |
| | | } |
| | | catch(Exception er) |
| | | { } |
| | | return JsonConvert.SerializeObject(resultEntity); |
| | | } |
| | | |
| | | |
| | | |
| | | [DllImport("Iphlpapi.dll")] |
| | | private static extern int SendARP(Int32 dest, Int32 host, ref Int64 mac, ref Int32 length); |
| | | |
| | | [DllImport("Ws2_32.dll")] |
| | | private static extern Int32 inet_addr(string ip); |
| | | |
| | | private string GetClientIP() |
| | | { |
| | | HttpContextAccessor context = new HttpContextAccessor(); |
| | | var ip = context.HttpContext?.Connection.RemoteIpAddress.ToString(); |
| | | var mac = GetClientMAC(ip); |
| | | var str = "IP:" + ip + " ,MAC:" + mac; |
| | | return str; |
| | | } |
| | | |
| | | private string GetClientMAC(string ip) |
| | | { |
| | | string mac_dest = string.Empty; |
| | | try |
| | | { |
| | | Int32 ldest = inet_addr(ip); //目的地的ip |
| | | Int32 lhost = inet_addr(""); //服务器的ip |
| | | Int64 macinfo = new Int64(); |
| | | Int32 len = 6; |
| | | int res = SendARP(ldest, 0, ref macinfo, ref len); |
| | | string mac_src = macinfo.ToString("X"); |
| | | while (mac_src.Length < 12) |
| | | { |
| | | mac_src = mac_src.Insert(0, "0"); |
| | | } |
| | | for (int i = 0; i < 11; i++) |
| | | { |
| | | if (0 == (i % 2)) |
| | | { |
| | | if (i == 10) |
| | | { |
| | | mac_dest = mac_dest.Insert(0, mac_src.Substring(i, 2)); |
| | | } |
| | | else |
| | | { |
| | | mac_dest = "-" + mac_dest.Insert(0, mac_src.Substring(i, 2)); |
| | | } |
| | | |
| | | } |
| | | } |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | throw ex; |
| | | } |
| | | return mac_dest; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 取得今天签到信息 |
| | | /// </summary> |
| | |
| | | options.CheckConsentNeeded = context => true; |
| | | options.MinimumSameSitePolicy = SameSiteMode.None; |
| | | }); |
| | | services.AddSingleton<IHttpContextAccessor, HttpContextAccessor>(); |
| | | |
| | | var connectionString = Configuration.GetConnectionString("DefaultConnection"); |
| | | services.AddDbContext<zhengcaioaContext>(options => |
| | |
| | | <div class="clearfix layer-area" style="padding-bottom:15px;"> |
| | | <label class="text-right col-sm-1 col-md-1 control-label">上午</label> |
| | | |
| | | <a class="btn btn-success" href="javascript:void(0)" onclick="saveSignin(10);" style="margin-left:4px; border-radius:4px;"> |
| | | <a class="btn btn-success" href="javascript:void(0)" onclick="networkInfo()" style="margin-left:4px; border-radius:4px;"> |
| | | <span class="bold">上班打卡</span> |
| | | </a> |
| | | |
| | | @*saveSignin(10);*@ |
| | | |
| | | |
| | | <a class="btn btn-success" href="javascript:void(0)" onclick="saveSignin(11);" style="margin-left:4px; border-radius:4px;"> |
| | |
| | | |
| | | |
| | | var record; |
| | | var mac; |
| | | $(function () { |
| | | $.ajax({ |
| | | type: "GET", |
| | |
| | | } |
| | | }) |
| | | |
| | | |
| | | mac = networkInfo(); |
| | | }); |
| | | |
| | | var _SigninList = function () { |
| | |
| | | // 保存打卡信息 |
| | | function saveSignin(signinType ) { |
| | | |
| | | |
| | | $.ajax({ |
| | | type: "POST", |
| | | url: "/Signin/Save", |
| | |
| | | global: false, |
| | | data: {id: record.Id ,signinType: signinType},// $('form').serializeArray(), |
| | | success: function (data) { |
| | | toastr.success("打卡成功"); |
| | | if (data.Result) { |
| | | toastr.success("打卡成功"); |
| | | } |
| | | else { |
| | | toastr.success("打卡失败"); |
| | | } |
| | | }, |
| | | error: function () { |
| | | toastr.error("打卡失败"); |
| | |
| | | return false; |
| | | } |
| | | |
| | | function networkInfo() { |
| | | |
| | | var wmi = new ActiveXObject("WbemScripting.SWbemLocator"); |
| | | var service = wmi.ConnectServer("."); |
| | | e = new Enumerator(service.ExecQuery("SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled = True")); |
| | | for (; !e.atEnd(); e.moveNext()) { |
| | | var s = e.item(); |
| | | var macAddress = unescape(s.MACAddress); |
| | | } |
| | | return macAddress; |
| | | } |
| | | |
| | | </script> |
| | | </body> |
| | | </html> |
| | |
| | | <script type="text/javascript"> |
| | | var year = '@Html.Raw(Newtonsoft.Json.JsonConvert.SerializeObject(ViewBag.year))'; |
| | | var month = '@Html.Raw(Newtonsoft.Json.JsonConvert.SerializeObject(ViewBag.month))'; |
| | | |
| | | var myDate = new Date(); |
| | | //获取当前年 |
| | | var searchyear = myDate.getFullYear(); |
| | | //获取当前月 |
| | | var searchmonth = myDate.getMonth() + 1; |
| | | |
| | | dataCol = [ |
| | | { label: 'id', name: 'Id', labtype: 'txt', hidden: true }, |
| | | { |
| | |
| | | //?userId=" + "@ViewBag.userId"; |
| | | searchCol = [ |
| | | |
| | | { label: '查询时间:年', name: 'Year', labtype: 'combox', hidden: false, defultvalue: JSON.parse(year)[1].code , data: JSON.parse(year), cwidth: '5%', cccwidth: '9%' }, |
| | | { label: '月', name: 'Month', labtype: 'combox', hidden: false, data: JSON.parse(month), cwidth: '1%', cccwidth: '7%' } |
| | | { label: '查询时间:年', name: 'Year', labtype: 'combox', hidden: false, defultvalue: searchyear , data: JSON.parse(year), cwidth: '5%', cccwidth: '9%' }, |
| | | { label: '月', name: 'Month', labtype: 'combox', hidden: false, defultvalue: searchmonth ,data: JSON.parse(month), cwidth: '1%', cccwidth: '7%' } |
| | | |
| | | ]; |
| | | |