编程开源技术交流,分享技术与知识

网站首页 > 开源技术 正文

共享茶室系统技术实现(共享茶室设备)

wxchong 2024-10-12 12:40:30 开源技术 13 ℃ 0 评论

实现场景介绍

打造24小时智能自助门店模式,场景流程如下:

1、进入小程序-->选择门店-->选择包间-->选择时间段-->预定茶室-->支付费用。

2、离到预定时间提前15分钟,可进入小程序-->点开门大厅与房间门-->预定的房间电源自动通电。

3、进入房间享受共享茶室体验。

4、离预定订单结束前15分钟,提醒续费,不续费时间到,订单结束,房间电源自动断电。

使用技术点介绍

1、基于当前流行技术组合的前后端分离技术:SpringBoot2+Jpa+MybatisPlus+SpringSecurity+jwt+redis+Vue的前后端分离的讯音共享空间系统。

2、后端使用技术点:

1.1 SpringBoot2 1.2 mybatis、MyBatis-Plus 1.3 SpringSecurity 1.4 Druid 1.5 Slf4j 1.7 Fastjson 1.8 JWT 1.9 Redis

1.10 Quartz 1.11 Mysql 1.12 swagger 1.13 WxJava 1.14 Lombok 1.15 Hutool 1.16 Mapstruct 1.17 Redisson

3、前端使用技术 Vue 全家桶、 Element。

4、用户前端使用微信原生开发。

技术实现流程\过程

这里主要描述如何结合硬件实现在小程序开门、订单到期自动断电实现过程

1、在小程序上给硬件发送开门指令

小程序前端实现:

1.1 根据订单Id与设备Id,使用http.requestPos方法调用后端服务接口,返回数据如果res.data.status为200,表示发送开门指令成功,门正常打开。

   http.requestPost("/device/openDoor", {
      orderId : e.currentTarget.dataset.orderid,
      switchid : e.currentTarget.dataset.switchid
    }, "post", true, false).then(res => {
      if (res.data.status == 200) {
        wx.showToast({
          title: '开门成功!',
          icon: 'none'
        })
      } else {
        wx.showToast({
          title: res.data.msg,
          icon: 'none'
        })
      }
    })

后端服务给硬件发送指令实现:

这里主要使用第三方硬件与接口(tuyaUrl +"/v1.0/iot-03/devices/),比较成熟完善了,没必要重新造轮。

如果你是技术实现智能物联控制也是很easy的,有兴趣自己可以买个硬件尝试一下,是很酷的事。

应该场景很广泛,比如:很容易根据原来的电器,电灯,窗帘等,接入硬件,就能很容易实现智能物联家居。

sendCommand(TDevice device, String command) { 
        Date date = new Date();
        String t = String.valueOf(date.getTime());
        Map<String, String> headerParam = new HashMap<>();
        String accessToken = TokenCache.getAccessTokenCache(tuyaClientId);
        headerParam.put("client_id", tuyaClientId );
        headerParam.put("access_token", accessToken);
        try {
            if("true".equals(command)) {
                Thread.sleep(1000);
            }
            headerParam.put("sign", SignUtil.HMACSHA256(tuyaClientId + accessToken + t, tuyaClientSecret));
        } catch (Exception e) {
            //logger.error("sign fail -> {}", e);
        }
        headerParam.put("t", t);
        headerParam.put("sign_method", "HMAC-SHA256");
        headerParam.put("Content-Type", "application/json");

        String jsonParamStr = "{\"commands\":[{\"code\": \"" + device.getMacAddr() + "\",\"value\":" + command + "}]}";

        String res = TuyaHttpClientUtil.doPostJson(tuyaUrl + "/v1.0/iot-03/devices/" + device.getDeviceNo() + "/commands", jsonParamStr, headerParam);
        //logger.info("sendCommand res ==>{}" , res);
        if(StringUtils.isEmpty(res)) {
            return false;
        }

        TDeviceLog deviceLog = new TDeviceLog();
        deviceLog.setDeviceNo(device.getDeviceNo());
        deviceLog.setCreateTime(new Date());
        // 通电
        deviceLog.setEvent((short)1);
        deviceLog.setRemark("开门-" + command + ";结果:" + res);
        tDeviceLogMapper.insert(deviceLog);
        JSONObject resJson = JSONObject.parseObject(res);
        if(resJson.getBoolean("success")) {
            if(resJson.getBoolean("result")) {
                return true;
            } else {
                return false;
            }
        } else {
            return false;
        } 
 }  

预定的房间电源自动通电、房间电源自动断电 实现过程发送指令是一样,不同之处在于后台定时器自动执行发送指令与传不同的设备Id,传参command,true表示开门或通电,false表示关门或断电。

如感兴趣可关注公众号或扫小程序二维码 可以体验共享茶室小程序。

共享茶室实现效果图如下:

Tags:

本文暂时没有评论,来添加一个吧(●'◡'●)

欢迎 发表评论:

最近发表
标签列表