Git Product home page Git Product logo

anti-fakegps's Introduction

Anti-FakeGPS

模拟定位检测工具(只适用于移动端,因为电脑一般没有 GPS 硬件)

NPM version Install size NPM bundle size NPM downloads

在线 Demo

手机扫下方二维码进行体验

安装

npm install anti-fakegps

使用

import { useAntiFakeGPS } from 'anti-fakegps'

/**
 * 当点击提交按钮时
 */
async function submit() {
  // 获取检测结果
  const checkResult = useAntiFakeGPS().check()

  // 根据检测结果,决定下一步操作
  switch (checkResult.status) {
    // 正在定位和正在检测时,提示用户正在定位,请稍等
    case CheckResult.POSITIONING: // 正在定位
    case CheckResult.CHECKING: // 正在检测
      showToast({ type: 'warning', message: '正在定位,请稍等...' })
      return
    // 定位失败时,提示用户打开手机定位开关,并允许网页定位
    case CheckResult.POSITION_FAILED: // 定位失败
      showToast({ type: 'warning', message: '请打开手机定位开关,并允许网页定位,再使用此功能' })
      return
    // 定位间隔超出正常范围时,视为正在使用模拟定位
    case CheckResult.LONG_TIME_NOT_UPDATE:
      // 在服务器记录违规行为
      // await saveCheatRecord({ uid: 'xxx' })

      showConfirmDialog({ title: '警告', message: '请勿使用模拟定位等作弊软件,本次行为已被记录,如果你确实在项目现场,可继续操作,公司会二次排查,确认要继续么?' })
      return
  }

  // 对于巡查定点拍照的场景,可以要求其停留在原地才能使用拍照功能,以应对 AnyGo 类软件
  // 判断手机正在移动,而不是停留在原地
  if (checkResult.pathMoved()) {
    showNotify({ type: 'warning', message: '请在原地稍等一会再拍照...' })
    return
  }

  // TODO 进行具体业务操作...
  // 可使用 checkResult.longitude 和 checkResult.latitude 获取经纬度

  showNotify({ type: 'success', message: '操作成功' })
}

检测原理

请参阅博客文章了解更多

TODO

  1. 拆分源代码到多个文件中,进一步完善各类文档说明等
  2. 测试 + 单元测试(Jest?)
  3. 更 typescript 一点

License

MIT

anti-fakegps's People

Contributors

cat7373 avatar

Stargazers

Master Panda avatar  avatar Yuchen avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.