js获取get数据

js获取get数据,第1张

js获取get数据

如今前后端分离已经成为趋势,也就是说许多页面如果外部做链接 就需要 自定义 话的 页面进行参数设置,目前有效的办法就是get参数。通过自定义的get参数为封装的 vue等框架 提供页面变量标识! 当然也可以使用路由进行。

/ --------------------实现2(返回 $_GET 对象, 仿PHP模式)---------------------- /

使用蓝牙耳机的数据线,可以通过蓝牙耳机的驱动程序来读取数据。首先,你需要下载蓝牙耳机的驱动程序,然后安装驱动程序,接着连接蓝牙耳机到电脑,最后就可以使用驱动程序来读取蓝牙耳机的数据了。

电脑连蓝牙的方法如下:

电脑:联想thinkpad

系统:Win81

软件:蓝牙53

1、首先,点击任务栏的开始菜单,在出现的菜单中找到控制面板,然后点击控制面板进入控制面板的主页。

2、在控制面板主页面中找到网络和共享中心,点击进入。

3、进入网络和共享中心页面后,找到左上角的更改适配器设置,点击进入。

4、进入之后,找到Bluetooth网络连接,点击它就可以看到电脑上连接的蓝牙设备了。

5、最后,你的工具栏下方有蓝牙的图标,直接将鼠标移动到它上面然后右键,选择显示Bluetooth设备,也可以看到电脑上连接的蓝牙设备。

蓝牙的技术原理

蓝牙的波段为2400–24835MHz(包括防护频带),这是全球范围内无需取得执照(但并非无管制的)的工业、科学和医疗用(ISM)波段的24GHz短距离无线电频段。蓝牙是基于数据包、有着主从架构的协议,一个主设备至多可和同一微微网中的七个从设备通讯,所有设备共享主设备的时钟。

蓝牙使用跳频技术,将传输的数据分割成数据包,通过79个指定的蓝牙频道分别传输数据包,每个频道的频宽为1MHz。蓝牙40使用2MHz间距,可容纳40个频道。第一个频道始于2402MHz,每1MHz一个频道,至2480MHz,有了适配跳频功能,通常每秒跳1600次。

//indexjs

//获取应用实例

const app = getApp()

const util = require('//utils/utiljs')

const bletool = require('//utils/bletooljs')

Page({

data: {

// lists: [{ 'order_no': '1111', 'car_no': '321', 'car_type': '尚好捷', 'order_date': '2018-01-02 08:00', 'order_money': '1600', 'order_time': '4' }],

car_no: '',

order_no: '',

lists: [],

bleList: [], //蓝牙设备数组

serviceId: '',//592B3370-3900-9A71-4535-35D4212D2837

serviceMac: '',//C9:9B:4C:E7:DE:10

service_psd: '',//855525B837253705595800000329

service_uuid: '',

deviceId:'',

characteristics:[] //特征值

},

onLoad: function (options) {

thisinitBle();

},

onReady: function () {

// 页面渲染完成

},

onShow: function () {

if (appglobalDatacar_nolength>0){

thisgetDeviceInfo();

}

},

onHide: function () {

// 页面隐藏

},

onUnload: function () {

// 页面关闭

appglobalDatacar_no=''

},

//蓝牙相关

//初始化蓝牙

initBle: function () {

var that = this;

wxonBluetoothAdapterStateChange(function (res) {

consolelog('adapterState changed, now is', res)

appglobalDatable_state = resavailable;

if (resavailable) {

thatinitBle();

} else {

utilshowToast('手机蓝牙已关闭');

appglobalDatable_isonnectting = false;

}

})

//打开蓝牙适配器

wxopenBluetoothAdapter({

success: function (res) {

consolelog('打开蓝牙适配器成功');

thatgetBluetoothAdapterState();

appglobalDatable_state = true;

thatonBluetoothDeviceFound();

},

fail: function (res) {

// fail

consolelog(res)

utilshowToast('请打开手机蓝牙');

},

complete: function (res) {

// complete

}

})

},

onBluetoothDeviceFound:function(){

var that = this;

//监听扫描

wxonBluetoothDeviceFound(function (res) {

// res电脑模拟器返回的为数组;手机返回的为蓝牙设备对象

consolelog('监听搜索新设备:', res);

thatupdateBleList([res])

})

},

getBluetoothAdapterState: function () {

var that = this;

wxgetBluetoothAdapterState({

success: function (res) {

var available = resavailable;

var discovering = resdiscovering;

if (!available) {

utilshowToast('蓝牙不可用');

} else {

if (!discovering) {

// thatstartBluetoothDevicesDiscovery();

}

}

}

})

},

startBluetoothDevicesDiscovery: function () {

var that = this;

var services = [];

servicespush(thisdataserviceId);

wxshowLoading({

title: '设备搜索中'

});

setTimeout(function () {

wxhideLoading();

if (appglobalDatadeviceIdlength==0){

utilshowModal('设备搜索失败,请重试');

}

}, 10000)

if(bletoolisIOS()){

wxstartBluetoothDevicesDiscovery({

services: services,

allowDuplicatesKey: true,

success: function (res) {

consolelog('ios搜索成功');

consolelog(res);

},

fail: function (err) {

consolelog(err);

}

});

}else{

wxstartBluetoothDevicesDiscovery({

// services: services,

allowDuplicatesKey: true,

success: function (res) {

consolelog('Android搜索成功');

consolelog(res);

},

fail: function (err) {

consolelog(err);

wxhideLoading();

thatstartBluetoothDevicesDiscovery();

// thatgetBluetoothAdapterState();

utilshowToast('搜索失败');

}

});

}

},

startConnectDevices: function (ltype, array) {

var that = this;

clearTimeout(thatgetConnectedTimer);

thatgetConnectedTimer = null;

wxstopBluetoothDevicesDiscovery({

success: function (res) {

// success

}

})

appglobalDatable_isonnectting = true;

consolelog('连接前:'+thatdeviceId);

wxcreateBLEConnection({

deviceId: thatdeviceId,

success: function (res) {

if (reserrCode == 0) {

consolelog('连接成功:');

thatgetService(thatdeviceId);

}

},

fail: function (err) {

consolelog('连接失败:', err);

wxhideLoading();

utilshowModal('设备连接失败,请重试');

// if (ltype == 'loop') {

// thatconnectDeviceIndex += 1;

// thatloopConnect(array);

// } else {

// thatstartBluetoothDevicesDiscovery();

// thatgetConnectedBluetoothDevices();

// }

appglobalDatable_isonnectting = false;

},

complete: function () {

}

});

},

getService: function (deviceId) {

var that = this;

// 监听蓝牙连接

wxonBLEConnectionStateChange(function (res) {

consolelog(res);

appglobalDatable_isonnectting = resconnected

if (!resconnected) {

utilshowToast('连接断开');

}

});

// 获取蓝牙设备service值

wxgetBLEDeviceServices({

deviceId: deviceId,

success: function (res) {

consolelog('获取蓝牙设备service值');

consolelog(res);

thatgetCharacter(deviceId, resservices);

}

})

},

getCharacter: function (deviceId, services) {

var that = this;

servicesforEach(function (value, index, array) {

if (valueisPrimary) {

thatsetData({

service_uuid: valueuuid,

deviceId: deviceId

})

appglobalDataservice_uuid= valueuuid;

appglobalDatadeviceId=deviceId;

}

});

//监听通知

wxonBLECharacteristicValueChange(function (res) {

// callback

consolelog('value change', res)

const hex = bletoolbuf2char(resvalue)

consolelog('返回的数据:', hex)

//配对密码

if (hexindexOf('855800000106') != -1) {

wxhideLoading();

var charact_write = thatdatacharacteristics[1]

bletoolwriteDataToDevice(thatdatadeviceId, thatdataservice_uuid, charact_write, thatdataservice_psd);

wxshowToast({

title: '设备已连接',

icon: 'success',

duration: 3000

})

setTimeout(function () {

bletoolwriteDataToDevice(thatdatadeviceId, thatdataservice_uuid, charact_write, '235525B837253705590400000273');

}, 2000)

} else if (hexindexOf('23040000') != -1) {

//启动成功

thatstarRenting();

}

})

wxgetBLEDeviceCharacteristics({

deviceId: deviceId,

serviceId: thatgetServiceUUID(),

success: function (res) {

wxgetBLEDeviceCharacteristics({

deviceId: deviceId,

serviceId: thatgetServiceUUID(),

success: function (res) {

consolelog('特征', res)

thatsetData({

characteristics:rescharacteristics

})

appglobalDatacharacteristics = rescharacteristics;

var charact_read = rescharacteristics[0]

},

loopConnect: function (devicesId) {

var that = this;

var listLen = devicesIdlength;

if (devicesId[thisconnectDeviceIndex]) {

thisdeviceId = devicesId[thisconnectDeviceIndex];

thisstartConnectDevices('loop', devicesId);

} else {

consolelog('已配对的设备小程序蓝牙连接失败');

thatstartBluetoothDevicesDiscovery();

thatgetConnectedBluetoothDevices();

}

},

//更新数据 devices为数组类型

updateBleList: function (devices) {

consolelog('设备数据:',devices);

var newData = thisdatableList

var that = this

var tempDevice = null;

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

//ios设备

if (devices[i]devices != null) {

if (devices[i]deviceslength > 0) {

tempDevice = devices[i]devices[0];

}

else {

continue

}

}

//安卓

else {

tempDevice = devices[i];

}

if (!thisisExist(tempDevice)) {

newDatapush(tempDevice)

}

}

consolelog('数据:');

consolelog(newData)

thissetData({

bleList: newData

})

if (!appglobalDatable_isonnectting) {

var that = this;

thisdatableListforEach(function (value, index, array) {

//找到对应id的设备,ios判断服务id安卓判断mac地址

var deviceId = value['deviceId'];

if(bletoolisIOS()){

let advertisServiceUUID = value['advertisServiceUUIDs'][0];

if (advertisServiceUUID == thatdataserviceIdtoUpperCase()){

thatdeviceId = deviceId;

consolelog(thatdeviceId);

thatstartConnectDevices();

}

}else{

if (deviceId == thatdataserviceMac) {

thatdeviceId = deviceId;

consolelog(thatdeviceId);

thatstartConnectDevices();

}

}

});

}

},

//是否已存在 存在返回true 否则false

isExist: function (device) {

var tempData = thisdatableList

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

if (tempData[i]deviceId == devicedeviceId) {

return true

}

}

return false

},

//服务uuid

getServiceUUID: function () {

return bletoolstringTransition(thisdataservice_uuid);

},

getDeviceInfo: function () {

let car_no = appglobalDatacar_no;

var that = this;

wxrequest({

url: appglobalDataserverURL + 'c=car&a=getDeviceInfo&open_id=' + appglobalDataopen_id + '&car_no=' + car_no,

method: 'GET', // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT

header: { 'content-type': 'application/json' }, // 设置请求的 header

success: function (res) {

// success

var data = resdata;

consolelog(data);

if (dataresult == 1) {

appglobalDataserviceId = datadataservice_id;

appglobalDataserviceMac = datadataservice_mac,

appglobalDataservice_psd = '85' + datadataservice_psd + '5800000329';

thatsetData({

serviceId: datadataservice_id,

serviceMac: datadataservice_mac,

service_psd: '85' + datadataservice_psd+'5800000329',

})

appstartBluetoothDevicesDiscovery();

// thatonBLECharacteristicValueChange();

} else {

utilshowModal(datamsg);

}

},

fail: function () {

},

complete: function () {

// complete

}

});

},

})

以上就是关于js获取get数据全部的内容,包括:js获取get数据、怎么通过数据线读取蓝牙耳机的程序、电脑怎么连蓝牙等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!

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

原文地址: http://outofmemory.cn/web/10116330.html

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

发表评论

登录后才能评论

评论列表(0条)

保存