app开发-3
Posted 被嫌弃的胖子
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了app开发-3相关的知识,希望对你有一定的参考价值。
一.Audio 模块实现开启手机摄像头
基于html5 plus
http://www.html5plus.org/doc/zh_cn/audio.html
栗子:
View Code
自定义:
scanQR.HTML
<!doctype html> <html lang="en"> <head> <meta charset="UTF-8" /> <title>Document</title> <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" /> <link rel="stylesheet" type="text/css" href="css/mui.css"/> </head> <body> <header class="mui-bar mui-bar-nav"> <a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a> <h1 class="mui-title">扫描玩具二维码</h1> </header> <div class="mui-content"> <div id="bcid" style="width: 100%;height: 750px;"></div> </div> <script src="js/mui.js" type="text/javascript" charset="utf-8"></script> <script type="text/javascript"> mui.init(); var scan = null; mui.plusReady(function () { scan = new plus.barcode.Barcode("bcid"); scan.onmarked = inmarked; #识别二维码 scan.start(); #开启识别扫描 inmarked(0,"d602f74c6a60fc1e9f60b20a190eeed7"); #在不开启摄像头的情况下,扫描二维码的是内容存储的内容 }) function inmarked(type,code){ // alert(type +":"+ code) mui.post(window.serv+ ‘/validate_code‘,{ device_key:code #{"device_key":"1eae197f4f4abe105c40bcaa7438d1f2"}, },function(data){ if(data.code == 0){ //打开绑定玩具流程 创建玩具 mui.openWindow({ url:"bind_toy.html", id:"bind_toy.html", extras:data.data # 获取的数据 {"code":0,"data":{"device_key":"1eae197f4f4abe105c40bcaa7438d1f2"},"msg":"设备已授权,开启绑定"} }) }else if(data.code==2){ //扫描的二维码信息异常 mui.toast(data.msg); mui.back(); }else if(data.code==1){ //神秘代码 } },‘json‘ ); } </script> </body> </html>
在上一步扫码后,进入玩具的绑定界面
进行玩具信息录入
bind_toy.html
View Code
后端存储数据
@devices.route("/bind_toy",methods=[‘POST‘]) def bind_toy(): # 1.device_key 2.fromdata 3. who bind toy toy_info = request.form.to_dict() print(toy_info) chat_window = MongoDB.chats.insert_one({"user_list":[],"char_list":[]}) user_info = MongoDB.xujian.find_one({"_id":ObjectId(toy_info["user_id"])}) toy_info["bind_user"] = toy_info.pop("user_id") toy_info["avatar"] = "toy.jpg" toy_info["firend_list"] = [ { "firend_id":toy_info["bind_user"], "firend_name":user_info.get("nickname"), "firend_nick":toy_info.pop("remark"), "firend_avatar":user_info.get("avatar"), "firend_type":"app", "firend_chat":str(chat_window.inserted_id) } ] toy = MongoDB.toys.insert_one(toy_info) user_info["bind_boy"].append(str(toy.inserted_id)) user_add_toy={ "firend_id": str(toy.inserted_id), "firend_name": toy_info.get("toy_name"), "firend_nick": toy_info.get("baby_name"), "firend_avatar": toy_info.get("avatar"), "firend_type": "toy", "firend_chat": str(chat_window.inserted_id) } user_info["friend_list"].append(user_add_toy) MongoDB.xujian.update_one({"_id":ObjectId(toy_info["bind_user"])}, {"$set":user_info}) MongoDB.chats.update_one({"_id":chat_window.inserted_id},{"$set":{"user_list":[ str(toy.inserted_id),str(user_info.get("_id")) ]}}) RET["code"] = 0 RET["msg"] = "绑定玩具成功" RET[‘data‘] = {} return jsonify(RET)
绑定好用户的机器人后,在toy_manager.html显示
View Code
这样,用户就可以查看他绑定的机器人啦
进行用户间的聊天chats
View Code
后端生成对话文件
@gsa.route("/uploader",methods=["POST"]) def uploader(): audio = request.files.get("recorder") path = os.path.join(chats_path,audio.filename) audio.save(path) os.system(f"ffmpeg -i {path} {path}.mp3") #通过ffmpeg强制转变格式 return "123"
以上是关于app开发-3的主要内容,如果未能解决你的问题,请参考以下文章
[异常解决] Keil安装好nRF51822开发环境,运行DEMO报错:Error:“GPIOTE_CONFIG_NUM_OF_LOW_POWER_ENVENTS” is undefined(代码片段
javascript 用于在节点#nodejs #javascript内设置react app的代码片段