标签:mini cal ida www link str type 界面 set
基于html5 plus
http://www.html5plus.org/doc/zh_cn/audio.html
栗子:
自定义:
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
后端存储数据
@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)
这样,用户就可以查看他绑定的机器人啦
后端生成对话文件
@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"
标签:mini cal ida www link str type 界面 set
原文地址:https://www.cnblogs.com/qq849784670/p/10306360.html