You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
59 lines
1.7 KiB
59 lines
1.7 KiB
'use strict';
|
|
import superagent from "superagent"
|
|
import moment from "moment";
|
|
import { YingshiRequest } from './'
|
|
|
|
export const uploadVoice2Yingshi = async ({ voiceFile, accessToken, voiceName, }) => {
|
|
const fData = new FormData();
|
|
fData.append('voiceFile', voiceFile);
|
|
fData.append("accessToken", accessToken)
|
|
fData.append("voiceName", voiceName || moment().format("YYYYMMDDHHmmssSSS"))
|
|
fData.append("force", true)
|
|
|
|
// TODO 代理转发为什么不行捏
|
|
// const upRslt = await YingshiRequest.post('api/lapp/voice/upload', fData)
|
|
|
|
const upRslt = await
|
|
new Promise((resolve, reject) => {
|
|
superagent
|
|
//.post('/_yingshi/api/lapp/voice/upload')
|
|
.post('https://open.ys7.com/api/lapp/voice/upload')
|
|
.send(fData)
|
|
.end(function (err, res) {
|
|
if (err) {
|
|
reject(err)
|
|
} else {
|
|
resolve(res.body)
|
|
}
|
|
})
|
|
})
|
|
if (upRslt.code == 200) {
|
|
return upRslt.data
|
|
} else {
|
|
throw upRslt
|
|
}
|
|
}
|
|
|
|
export const sendVoice2YingshiCamera = async ({ accessToken, deviceSerial, channelNo = 1, fileUrl }) => {
|
|
const sendRslt = await
|
|
new Promise((resolve, reject) => {
|
|
superagent
|
|
.post('https://open.ys7.com/api/lapp/voice/send')
|
|
.send({
|
|
accessToken, deviceSerial, channelNo, fileUrl
|
|
})
|
|
.set('Content-Type', 'application/x-www-form-urlencoded')
|
|
.end(function (err, res) {
|
|
if (err) {
|
|
reject(err)
|
|
} else {
|
|
resolve(res.body)
|
|
}
|
|
})
|
|
})
|
|
if (sendRslt.code === 200) {
|
|
return sendRslt.data
|
|
} else {
|
|
throw sendRslt
|
|
}
|
|
}
|