H5用户在手机浏览器访问网站页面,如何获取用户当前设备的信息uuid

H5用户在手机浏览器访问网站页面,如何获取用户当前设备的信息uuid,第1张

无法做到,包括后端语言也无法在 Web 中获取 UUID。

基于安全问题,JavaScript 无法获取到设备的 UUID,也没有接口可以获取 UUID。

如果 JavaScript 可以轻松做到,安卓设备的 APP 权限岂不是花瓶?!

用户在微信“周边”tab里,摇到“未能识别周围有效信息”原因:

1、可能是设备ID配置问题。该设备UUID配置有效,但Major或Minor配置有误;

2、可能在“页面信息“设置了时间或地域限制。在设定时间或地域之外,用户收不到有效信息。

//初始化蓝牙

initBlue() {

var that = this;

wxopenBluetoothAdapter({ //调用微信小程序api 打开蓝牙适配器接口

success: function (res) {

consolelog('1初始化蓝牙成功')

},

//监听手机蓝牙的开关

monitorTheBlue:function(){

var that =this;

wxonBluetoothAdapterStateChange(function(res){

})

},

//开始获取附近的蓝牙设备

// 获取到附近的蓝牙数组 通过蓝牙特定的名称获取自己想要连接的蓝牙设备

// 获取附近蓝牙设备的数组

findBlue() {

consolelog(new Date())

var that = this

wxstartBluetoothDevicesDiscovery({

allowDuplicatesKey: false,

interval: 0,

success: function (res) {

consolelog('2正在搜索设备')

if (thatdataisFirestShow) {

wxshowLoading({

title: '正在搜索设备'

})

}

},

//搜索获取附近的所有蓝牙设备 获取附近所有的蓝牙设备的相关信息 获取需要连接蓝牙设备的deviceID

// 通过bluetoothDeviceName 和 localName 来确定制定蓝牙

// 一般根据制定设备的名字去连接 设备的名字 是出产厂家设定

getBlue() {

var that = this

wxgetBluetoothDevices({

success: function (res) {

consolelog('3找到设备列表')

wxhideLoading()

// return false

var index = 10

for (var i = 0; i < resdeviceslength; i++) {

if (resdevices[i]name && resdevices[i]localName) {

var arr = resdevices[i]namesplit("-")

var secArr = resdevices[i]localNamesplit("-")

if (arr[0] == thatdatabluetoothDeviceName || secArr[0] == thatdatabluetoothDeviceName) {

},

//连接蓝牙设备

//通过deviceId 连接蓝牙

/

},

//6 连接上需要的蓝牙设备之后,获取这个蓝牙设备的服务uuid

//获取设备的uuid

getServiceId() {

var that = this

wxgetBLEDeviceServices({

// 这里的 deviceId 需要已经通过 createBLEConnection 与对应设备建立链接

deviceId: thatdatadeviceId,

success: function (res) {

var model = resservices[1]

thatsetData({

servicesUUID: modeluuid

})

consolelog('7获取设备 uuid 成功')

thatgetCharacteId() //60

}

})

},

//7 如果一个蓝牙设备需要进行数据的写入以及数据传输,就必须具有某些特征值,所以通过上面步骤获取的id可以查看当前蓝牙设备的特征值

//notify write read 当只有 notify为true的时候才能 接收蓝牙设备传来的数据,

//write 为true 才能传入数据

//read 为true 才能读取设备数据

getCharacteId() {

var that = this

wxgetBLEDeviceCharacteristics({

// 这里的 deviceId 需要已经通过 createBLEConnection 与对应设备建立链接

deviceId: thatdatadeviceId,

// 这里的 serviceId 需要在上面的 getBLEDeviceServices 接口中获取

serviceId: thatdataservicesUUID,

success: function (res) {

for (var i = 0; i < rescharacteristicslength; i++) { //2个值

var model = rescharacteristics[i]

if (modelpropertiesnotify == true) {

thatsetData({

characteristicId: modeluuid //监听的值

})

consolelog('8modelpropertiesnotify == true')

thatstartNotice(modeluuid) //70

}

// if (modelpropertiesread == true) {

// thatreadData(modeluuid)

// }

// if (modelpropertieswrite == true) {

// thatsetData({

// writeId: modeluuid//用来写入的值

// })

// }

}

}

})

},

fordateTime1(){

let now = new Date(),hour = nowgetHours()

consolelog(hour)

let str = ''

if(hour < 7){str = '早餐前'}

else if ((7< hour) && (hour<= 9)){str = '早餐后'}

else if ((9< hour) && (hour<= 11)){str = '午餐前'}

else if ((11< hour) && (hour<= 13)){str = '午餐后'}

else if ((13< hour) && (hour<= 17)){str = '晚餐前'}

else if ((17< hour) && (hour<= 19)){str = '晚餐后'}

else if ((19< hour) && (hour<= 24)){str = '睡觉前'}

return str

},

//8 如果一个蓝牙设备需要进行数据的写入以及数据传输,就必须具有某些特征值,所以通过上面步骤获取的id可以查看当前蓝牙设备的特征值

//开启设备数据监听 监听蓝牙设备返回来的数据

startNotice(uuid) {

var that = this;

wxnotifyBLECharacteristicValueChanged({

state: true, // 启用 notify 功能

deviceId: thatdatadeviceId,

serviceId: thatdataservicesUUID,

characteristicId: uuid, //第一步 开启监听 notityid 第二步发送指令 write

success: function (res) {

// thatcloseConnect(thatdatadeviceId)

// 设备返回的方法

let tip = 0

wxonBLECharacteristicValueChange(res1 => {

},

/

//监听蓝牙设备是否会异常断开

getTheBlueDisConnectWithAccident() {

},

// 断开设备连接

closeConnect: function(v) {

var that = this

if (v) {

wxcloseBLEConnection({

deviceId: v,

success: function(res) {

consolelog("蓝牙断开连接")

thatcloseBluetoothAdapter()

},

fail(res) {

}

})

} else {

thatcloseBluetoothAdapter()

}

},

// 关闭蓝牙模块

closeBluetoothAdapter:function () {

wxcloseBluetoothAdapter({

success: function(res) {

consolelog("关闭蓝牙模块")

},

fail: function(err) {

}

})

},

方法一:通过Windows下的iTunes

1、数据线连接iPhone手机,在Windows下打开iTunes,在 iPhone 管理界面下点击“序列号”查看自己的 UUID 标识符。

2、此时点击菜单-编辑->复制

3、新建一个文档或文本文件,粘贴就会出现类似于3cfe09dc0a545766ed912db6c32a65b37cc06ae5这就是iPhone手机的UUID

方法二:通过XCode的Organizer

1、点击XCode的菜单-Windows->Organizer,会出现如此界面

2、直接复制、粘贴就可以了

方法三:通过代码实现

对于IOS开发者通过以下代码实现

-(NSString) uuid {

  CFUUIDRef puuid = CFUUIDCreate( nil );

  CFStringRef uuidString = CFUUIDCreateString( nil, puuid );

  NSString result = (NSString )CFStringCreateCopy( NULL, uuidString);

  CFRelease(puuid);

  CFRelease(uuidString);

  return [result autorelease];

}

#使用mpvue 开发小程序过程中 简单介绍一下微信小程序蓝牙连接过程

#在蓝牙连接的过程中部分api需要加定时器延时1秒到2秒左右再执行,原因为何不知道,小程序有这样的要求

#1首先是要初始化蓝牙:openBluetoothAdapter()

```js

if (wxopenBluetoothAdapter) {

wxopenBluetoothAdapter({

        success: function(res) {

            / 获取本机的蓝牙状态 /

            setTimeout(() => {

                getBluetoothAdapterState()

            }, 1000)

        },

        fail: function(err) {

            // 初始化失败

        }

    })

    } else {    

    }

```

#2检测本机蓝牙是否可用:

#  要在上述的初始化蓝牙成功之后回调里调用

```js

getBluetoothAdapterState() {

    var that= this;

    thattoastTitle= '检查蓝牙状态'

wxgetBluetoothAdapterState({

        success: function(res) {

startBluetoothDevicesDiscovery()

},

        fail(res) {

            consolelog(res)

}

})

}

```

#3 开始搜索蓝牙设备:

```js

startBluetoothDevicesDiscovery() {

    var that= this;

    setTimeout(() => {

wxstartBluetoothDevicesDiscovery({

            success: function(res) {

/ 获取蓝牙设备列表 /

                thatgetBluetoothDevices()

},

            fail(res) {

}

})

}, 1000)

}

```

#4 获取搜索到的蓝牙设备列表

# / thatdeviceName 是获取到的蓝牙设备的名称, 因为蓝牙设备在安卓和苹果手机上搜到的蓝牙地址显示是不一样的,所以根据设备名称匹配蓝牙/

```js

getBluetoothDevices() {

    var that= this;

    setTimeout(() => {

wxgetBluetoothDevices({

            services: [],

            allowDuplicatesKey: false,

            interval: 0,

            success: function(res) {

                if (resdeviceslength> 0) {

                    if (JSONstringify(resdevices)indexOf(thatdeviceName) !== -1) {

                        for (let i = 0; i < resdeviceslength; i++) {

                            if (thatdeviceName === resdevices[i]name) {

/ 根据指定的蓝牙设备名称匹配到deviceId /

                                thatdeviceId = thatdevices[i]deviceId;

                                setTimeout(() => {

                                    thatconnectTO();

}, 2000);

};

};

} else {

}

} else {

}

},

            fail(res) {

                consolelog(res, '获取蓝牙设备列表失败=====')

}

})

}, 2000)

},

```

#5连接蓝牙

# 匹配到的蓝牙设备ID 发送连接蓝牙的请求, 连接成功之后 应该断开蓝牙搜索的api,然后去获取所连接蓝牙设备的service服务

```js

connectTO() {

wxcreateBLEConnection({

        deviceId: deviceId,

        success: function(res) {

            thatconnectedDeviceId = deviceId;

/ 4获取连接设备的service服务 /

thatgetBLEDeviceServices();

wxstopBluetoothDevicesDiscovery({

                success: function(res) {

                    consolelog(res, '停止搜索')

},

                fail(res) {

}

})

},

        fail: function(res) {

}

})

}

```

#6 获取蓝牙设备的service服务,获取的serviceId有多个要试着连接最终确定哪个是稳定版本的service 获取服务完后获取设备特征值

```js

getBLEDeviceServices() {

    setTimeout(() => {

wxgetBLEDeviceServices({

            deviceId: thatconnectedDeviceId,

            success: function(res) {

                thatservices= resservices

/ 获取连接设备的所有特征值 /

thatgetBLEDeviceCharacteristics()

},

            fail: (res) => {

}

})

}, 2000)

},

```

#7获取蓝牙设备特征值

# 获取到的特征值有多个,最后要用的事能读,能写,能监听的那个值的uuid作为特征值id,

```js

getBLEDeviceCharacteristics() {

            setTimeout(() => {

wxgetBLEDeviceCharacteristics({

                    deviceId: connectedDeviceId,

                    serviceId: services[2]uuid,

                    success: function(res) {

                        for (var i = 0; i < rescharacteristicslength; i++) {

                            if ((rescharacteristics[i]propertiesnotify || rescharacteristics[i]propertiesindicate) &&

                                (rescharacteristics[i]propertiesread && rescharacteristics[i]propertieswrite)) {

                                consolelog(rescharacteristics[i]uuid, '蓝牙特征值 ==========')

/ 获取蓝牙特征值 /

                                thatnotifyCharacteristicsId = rescharacteristics[i]uuid

// 启用低功耗蓝牙设备特征值变化时的 notify 功能

thatnotifyBLECharacteristicValueChange()

}

}

},

                    fail: function(res) {

}

})

}, 1000)

},

```

#8启动notify 蓝牙监听功能 然后使用 wxonBLECharacteristicValueChange用来监听蓝牙设备传递数据

#接收到的数据和发送的数据必须是二级制数据, 页面展示的时候需要进行转换

```js

notifyBLECharacteristicValueChange() { // 启用低功耗蓝牙设备特征值变化时的 notify 功能

            var that= this;

            consolelog('6启用低功耗蓝牙设备特征值变化时的 notify 功能')

wxnotifyBLECharacteristicValueChange({

                state: true,

                deviceId: thatconnectedDeviceId,

                serviceId: thatnotifyServicweId,

                characteristicId: thatnotifyCharacteristicsId,

                complete(res) {

/用来监听手机蓝牙设备的数据变化/

wxonBLECharacteristicValueChange(function(res) {

//

                        thatbalanceData += thatbuf2string(resvalue)

                        thathexstr += thatreceiveData(resvalue)

})

},

                fail(res) {

                    consolelog(res, '启用低功耗蓝牙设备监听失败')

                    thatmeasuringTip(res)

}

})

},

/转换成需要的格式/

buf2string(buffer) {

                    var arr = Arrayprototypemapcall(new Uint8Array(buffer), x => x)

                    return arrmap((char, i) => {

                        return StringfromCharCode(char);

                    })join('');

},

receiveData(buf) {

return thishexCharCodeToStr(thisab2hex(buf))

},

/转成二进制/

ab2hex (buffer) {

              var hexArr = Arrayprototypemapcall(

                  new Uint8Array(buffer), function (bit) {

                      return ('00' + bittoString(16))slice(-2)

}

)

              return hexArrjoin('')

},

/转成可展会的文字/

hexCharCodeToStr(hexCharCodeStr) {

              var trimedStr = hexCharCodeStrtrim();

              var rawStr = trimedStrsubstr(0, 2)toLowerCase() === '0x' trimedStrsubstr(2) : trimedStr;

              var len = rawStrlength;

              var curCharCode;

              var resultStr= [];

              for (var i = 0; i < len; i = i+ 2) {

                  curCharCode = parseInt(rawStrsubstr(i, 2), 16);

                  resultStrpush(StringfromCharCode(curCharCode));

}

              return resultStrjoin('');

},

```

# 向蓝牙设备发送数据

```js

sendData(str) {

    let that= this;

    let dataBuffer = new ArrayBuffer(strlength)

    let dataView = new DataView(dataBuffer)

    for (var i = 0; i < strlength; i++) {

        dataViewsetUint8(i, strcharAt(i)charCodeAt())

}

    let dataHex = thatab2hex(dataBuffer);

    thiswriteDatas = thathexCharCodeToStr(dataHex);

wxwriteBLECharacteristicValue({

        deviceId: thatconnectedDeviceId,

        serviceId: thatnotifyServicweId,

        characteristicId: thatnotifyCharacteristicsId,

        value: dataBuffer,

        success: function (res) {

            consolelog('发送的数据:' + thatwriteDatas)

            consolelog('message发送成功')

},

        fail: function (res) {

},

        complete: function (res) {

}

})

},

```

# 当不需要连接蓝牙了后就要关闭蓝牙,并关闭蓝牙模块

```js

// 断开设备连接

closeConnect() {

if (thatconnectedDeviceId) {

wxcloseBLEConnection({

            deviceId: thatconnectedDeviceId,

            success: function(res) {

thatcloseBluetoothAdapter()

},

            fail(res) {

}

})

} else {

thatcloseBluetoothAdapter()

}

},

// 关闭蓝牙模块

closeBluetoothAdapter() {

wxcloseBluetoothAdapter({

        success: function(res) {

},

        fail: function(err) {

}

})

},

```

#在向蓝牙设备传递数据和接收数据的过程中,并未使用到read的API 不知道有没有潜在的问题,目前线上运行为发现任何的问题

#今天的蓝牙使用心得到此结束,谢谢

并不能获得。

如果是在app内加载页面,可以让后端在加载页面的时候传递到前端,也可以由app内置js协议获取。

如果是在微信里,可以考虑用微信的唯一标识openId

概述

IMEI(International Mobile Equipment Identity)是国际移动设备识别码的缩写。俗称“手机串号”、“手机串码”、“手机序列号”,用于在GSM移动网络中识别每一部独立的手机,相当于手机的身份z号码。IMEI码适用于GSM和WCDMA制式的移动电话和铱星卫星电话,而CDMA手机采用MEID码,与IMEI码有所区别。全球每部通过正规渠道销售的GSM手机均有唯一的IMEI码。IMEI码由GSMA协会统一规划,并授权各地区组织进行分配,在中国由工业和信息化部电信终端测试技术协会(TAF)负责国内手机的入网认证,其他分配机构包括英国BABT、美国CTIA等。

简介

国际移动设备识别码(IMEI:International Mobile Equipment Identification Number)是区别移动设备的标志,储存在移动设备中,可用于监控被窃或无效的移动设备。IMEI可用移动终端设备通过键入"#06#"查得(不同厂商的手机所需输入的内容不同,同一厂商不同手机所需输入的内容也可能不同)。其总长为15位,每位数字仅使用0~9的数字。

IMEI分配

IMEI码由GSMA协会统一规划,并授权各地区组织进行分配,在中国由工业和信息化部电信终端测试技术协会(TAF)负责国内手机的入网认证,其他分配机构包括英国BABT、美国CTIA等。

以上就是关于H5用户在手机浏览器访问网站页面,如何获取用户当前设备的信息uuid全部的内容,包括:H5用户在手机浏览器访问网站页面,如何获取用户当前设备的信息uuid、用户在微信“周边”tab里,为什么摇到“未能识别周围有效信息”、小程序 蓝牙连接等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/web/10148189.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-05
下一篇 2023-05-05

发表评论

登录后才能评论

评论列表(0条)

保存