uniapp实现通话录音实时上传、后端php-安卓手机
时间:2021-05-30
本文章向大家介绍uniapp实现通话录音实时上传、后端php-安卓手机,主要包括uniapp实现通话录音实时上传、后端php-安卓手机使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。
<template> <view class="content"> <view class="header"> <image src="../../static/shilu-login/logo.png"></image> </view> <view class="list"> <view class="list-call"> <image class="img" src="/static/shilu-login/1.png"></image> <input class="sl-input" v-model="phone" type="number" maxlength="11" placeholder="输入当前手机号" /> </view> <view class="list-call"> <image class="img" src="/static/shilu-login/4.png"></image> <input class="sl-input" v-model="username" type="text" maxlength="32" placeholder="输入您的姓名" username="true" /> </view> </view> <view class="button-login" hover-class="button-hover" @tap="start"> <text>保存</text> </view> <view class="list"> <view class="list-call"> 手机号:{{this.phone}} </view> <view class="list-call"> 姓名:{{this.username}} </view> <view class="list-call"> 手机型号:{{this.phone_model}} </view> <view class="list-call"> 设备号:{{this.phone_uuid}} </view> </view> </view> </template> <script> export default { onLoad() { this.phone_uuid = plus.device.uuid; this.phone_model = plus.device.model; }, data() { return { nowTime:'', phone: '', username: '', phone_model:'', phone_uuid:'', // luyin_dir:'/sdcard/Record/Call/', //这里是vivo的 luyin_dir:'/storage/emulated/0/MIUI/sound_recorder/call_rec/', //这里是小米手机的通话录音路径 luyin_prefix:'mp3', //指定录音的后缀格式 // luyin_prefix:'amr', bak_dir:'bak_luyin', post_url:'http://www.xxxxxx.com/api/uploadluyin', }; }, methods: { getDirFile(){ // this.mkbakdir(); console.log('getDirFile') var filePath = this.luyin_dir; var fileSuffix = this.luyin_prefix; var that = this; //这是获取目录下的文件 plus.io.resolveLocalFileSystemURL( filePath, //指定的目录 function(entry) { var directoryReader = entry.createReader(); //获取读取目录对象 directoryReader.readEntries( function(entries) { //历遍子目录即可 console.log(entries.length) for (var i = 0; i < entries.length; i++) { console.log(entries[i]) // entries[i].remove(); //这是删除指定的文件 // entries[i].copyTo() var suffix = entries[i].name.split('.').pop().toLowerCase(); if (suffix == fileSuffix) { var uploadFilePath = filePath+entries[i].name console.log("文件路径:"+filePath+entries[i].name) that.checkFileSizeIsChange(uploadFilePath,entries[i]); } } }, function(err) { console.log("访问目录失败"); }); }, function(err) { console.log("访问指定目录失败:" + err.message); }); }, checkFileSizeIsChange(file_path_name,file){ var that = this; plus.io.getFileInfo( {filePath:file_path_name, success: function( fs ) { var new_size = fs.size; var old_size = uni.getStorageSync(file.name) console.log('之前的大小:'+old_size); console.log('现在的大小'+new_size); //有上次记录的大小 if (old_size != '') { if (old_size == new_size) { //这样才上传 console.log('两次的size大小相等,可以上传'); var upload_status = uni.getStorageSync(file.name+'upload_status') if (upload_status == 1) { console.log(file.name+'在上传中'); } else { console.log(file.name+'可以上传了'); that.uploadLuYinFile(file_path_name,file); } } else { console.log('两次的size大小不相等,暂时不可以上传'); uni.setStorageSync(file.name,new_size) } } else { console.log('暂时没有设置size 大小'); uni.setStorageSync(file.name,new_size) } }, fail : function ( e ) { console.log("获取文件信息错误"); console.log(e.message); } }); }, uploadLuYinFile(uploadFilePath,file_obj){ uni.setStorageSync(file_obj.name+'upload_status',1) var that = this var username = this.username var phone = this.phone //上传文件方法2 console.log('upload_function_start') var request_url = this.post_url; var task = plus.uploader.createUpload( request_url, { method:"POST",priority:100 }, function ( t, status ) { // 上传完成 console.log(t) console.log(status) if ( status == 200 ) { var response = JSON.parse(JSON.parse(JSON.stringify(t.responseText))) if(response.code == 1) { console.log('上传成功了') file_obj.remove(); //这是删除指定的文件 console.log('删除成功') // that.mkbakdir(); uni.removeStorageSync(file_obj.name) uni.removeStorageSync(file_obj.name+'upload_status') // file_obj.copyTo() } else { console.log('失败') } console.log( "Upload success: " + t.url ); } else { console.log( "Upload failed: " + status ); } }); task.addFile( uploadFilePath, {key:"upfile"} ); task.addData( "username", this.username); task.addData( "phone", this.phone); task.start(); console.log('upload_function_end-----------') }, mkbakdir(){ var dir = new Date().getFullYear() + "-" + (new Date().getMonth() + 1) + "-" + new Date().getDate() + "-" + new Date().getHours() + "-" + new Date().getMinutes() + "-" + new Date().getSeconds(); var that = this console.log('mkdir') plus.io.resolveLocalFileSystemURL( that.luyin_dir, function(entry){ entry.getDirectory(dir, {create:true,exclusive:false},function(entry){ console.log('创建或打开成功') that.moveFile() },function(){ console.log('创建或者打开子目录失败') }) }, function(e){ console.log('获取io操作对象失败') } ) }, getfileAndUpload(){ console.log('getfileAndUpload') setInterval(this.getDirFile,5000); }, start() { if (this.phone == '') { uni.showToast({ icon: 'none', title: '请输入手机号' }); return; } if (this.phone.length != 11) { uni.showToast({ icon: 'none', title: '手机号不正确' }); return; } if (this.username.length < 2) { uni.showToast({ icon: 'none', title: '请正确输入姓名' }); return; } this.getfileAndUpload(); } } } </script> <style> .content { display: flex; flex-direction: column; justify-content: center; } .header { width: 161rpx; height: 161rpx; background: rgba(63, 205, 235, 1); box-shadow: 0rpx 12rpx 13rpx 0rpx rgba(63, 205, 235, 0.47); border-radius: 50%; margin-top: 30rpx; margin-left: auto; margin-right: auto; } .header image { width: 161rpx; height: 161rpx; border-radius: 50%; } .list { display: flex; flex-direction: column; padding-top: 50rpx; padding-left: 70rpx; padding-right: 70rpx; } .list-call { display: flex; flex-direction: row; justify-content: space-between; align-items: center; height: 100rpx; color: #333333; border-bottom: 0.5px solid #e2e2e2; } .list-call .img { width: 40rpx; height: 40rpx; } .list-call .sl-input { flex: 1; text-align: left; font-size: 32rpx; margin-left: 16rpx; } .button-login { color: #FFFFFF; font-size: 34rpx; width: 470rpx; height: 100rpx; background: linear-gradient(-90deg, rgba(63, 205, 235, 1), rgba(188, 226, 158, 1)); box-shadow: 0rpx 0rpx 13rpx 0rpx rgba(164, 217, 228, 0.2); border-radius: 50rpx; line-height: 100rpx; text-align: center; margin-left: auto; margin-right: auto; margin-top: 100rpx; } .button-hover { background: linear-gradient(-90deg, rgba(63, 205, 235, 0.8), rgba(188, 226, 158, 0.8)); } .agreenment { display: flex; flex-direction: row; justify-content: center; align-items: center; font-size: 30rpx; margin-top: 80rpx; color: #FFA800; text-align: center; height: 40rpx; line-height: 40rpx; } .agreenment text { font-size: 24rpx; margin-left: 15rpx; margin-right: 15rpx; } </style>
//php代码 public function uploadluyin(Request $request){ if(empty($_FILES)){ \Log::info('upload_luyin',['没有录音文件']); return ; } $file = $_FILES['upfile']; $file_name = $file['name']; $username = $_POST['username']; $app_phone = $_POST['phone']; $luyin_info = explode(' ', $file_name); $luyin_phone = $luyin_info[0]; $save_file_name = implode('-',$luyin_info); $file_type = 'audio/mp3'; if($file["type"] == $file_type) { $destinationPath = public_path('uploads/luyin_dir/'); $time = time(); $filePath = $destinationPath . $time . '-' . $save_file_name; $bool = move_uploaded_file($file["tmp_name"], $filePath);//将临时地址移动到指定地址 if ($bool) { \Log::info('upload_luyin',['业务员:【'.$username.'--'.$app_phone.'】与客户:'.$luyin_phone.'通话文件上传成功']); } else { \Log::info('upload_luyin',['业务员:【'.$username.'--'.$app_phone.'】与客户:'.$luyin_phone.'通话文件上传失败']); $res = array('code' => '-1', 'msg' => '上传失败'); return json_encode($res); } $fileUrl = 'uploads/luyin_dir/' . $time . '-' . $save_file_name; $getID3 = new getID3; $ThisFileInfo = $getID3->analyze($fileUrl); $fileduration = $ThisFileInfo['playtime_seconds']; //这个获得的便是音频文件的时长 $seconds = ceil($fileduration); //秒 $shichang = $this->secondTime($seconds); $LuyinModel = new Luyin(); $params = array( 'app_phone' => $app_phone, 'luyin_phone' => $luyin_phone, 'username' => $username, 'seconds' => $seconds, 'shichang' => $shichang, 'add_time' => time(), 'file_path' => 'http://'.$_SERVER['HTTP_HOST'] . '/' . $fileUrl ); $id = $LuyinModel->addLuyin($params); if ($id) { \Log::info('upload_luyin',['业务员:【'.$username.'--'.$app_phone.'】与客户:【'.$luyin_phone.'】通话入库成功:'.$id]); $res = array('code' => '1', 'msg' => '上传失败'); return json_encode($res); } else { \Log::info('upload_luyin',['业务员:【'.$username.'--'.$app_phone.'】与客户:'.$luyin_phone.'通话入库失败']); $res = array('code' => '-1', 'msg' => '上传失败'); return json_encode($res); } } }
原文地址:https://www.cnblogs.com/wt645631686/p/14827477.html
- 我所理解的 PHP Trait
- 算法 | 数据结构常见的八大排序算法
- 高通量数据下载还能这样操作?
- ofbiz实体引擎(八) 创建表
- ofbiz实体引擎(七) 检查数据源
- ofbiz实体引擎(六) GenericHelper的初始化创建
- ofbiz实体引擎(五) ModelGroupReader
- HBitcoin:C#高级比特币钱包库 - 保护您的财产安全
- ofbiz实体引擎(四) ModelReader的作用
- ofbiz实体引擎(三) GenericDelegator实例化的具体过程
- 机器学习实战 | 第五章:模型保存(持久化)
- Python编程任务 | 斯坦福CS231n-深度学习与计算机视觉课程
- ofbiz实体引擎(二) delegator实例化具体方式
- ofbiz实体引擎(一) 获取Delegator
- php概述
- php教程
- php环境搭建
- PHP书写格式
- php变量
- php常量
- PHP注释
- php数组
- php字符串 string
- PHP整型 integer
- PHP浮点型 float
- php布尔型
- php数据类型之数组
- php数据类型之对象
- php数据类型之null
- php数据类型之间的转换
- php运算符
- php表达式
- PHP循环控制
- PHP流程控制
- php函数
- php全局变量
- PHP魔术变量
- php命名空间
- php 日期
- PHP包含文件
- php文件
- PHP 文件上传
- php Cookies
- php Sessions
- php email
- php安全email
- php错误处理
- PHP异常处理
- php过滤器
- PHP 高级过滤器
- php json
- php 表单
- PHP MySQL 简介
- PHP 连接 MySQL
- php创建数据库
- php 创建表
- php mysq 插入数据
- PHP MySQL 插入多条数据
- PHP MySQL 预处理语句
- php mysql 读取数据
- php mysql where
- PHP MySQL Order By
- PHP MySQL Update
- PHP MySQL Delete
- php ODBC
- Java点餐系统+扫码点餐小程序部署文档(2020版)
- Android开发实现各种图形绘制功能示例
- Android webview手动校验https证书(by 星空武哥)
- AndroidStudio Gradle第三依赖统一管理的实现方法
- 小程序上传多张图片到springboot后台,返回可供访问的图片链接
- AndroidStudio Gradle基于友盟的多渠道打包方法
- Android开发之全屏与非全屏的切换设置方法小结
- Android使用GridView实现日历的方法
- Android控件AppWidgetProvider使用方法详解
- R语言使用链梯法Chain Ladder和泊松定律模拟和预测未来赔款数据
- Android ViewPager实现左右滑动的实例
- R语言通过伽玛与对数正态分布假设下的广义线性模型对大额索赔进行评估预测
- R语言中回归模型预测的不同类型置信区间应用比较分析
- 第06期:Prometheus 存储
- 新特性解读 | 数组范围遍历功能