Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
X
xiaomai-cloud-class-web
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
xiaomai-cloud-class
xiaomai-cloud-class-web
Commits
b1ac4226
Commit
b1ac4226
authored
Jun 22, 2021
by
yuananting
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix:企业微信api调试关闭
parent
e220cf0c
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
57 additions
and
106 deletions
+57
-106
src/common/js/wechatApi.js
+24
-43
src/modules/teach-tool/components/XMRecord.jsx
+33
-63
No files found.
src/common/js/wechatApi.js
View file @
b1ac4226
/*
* @Author: wufan
* @Date: 2021-05-11 10:21:37
* @LastEditors:
yuananti
ng
* @LastEditTime: 2021-06-
09 20:00:13
* @LastEditors:
fusanqias
ng
* @LastEditTime: 2021-06-
22 16:52:48
* @Description: 企业微信api
* @@Copyrigh: © 2020 杭州杰竞科技有限公司 版权所有
*/
import
User
from
"@/common/js/user"
;
import
Service
from
"@/common/js/service"
;
import
Platform
from
"@/core/platform"
;
import
User
from
'@/common/js/user'
;
import
Service
from
'@/common/js/service'
;
import
Platform
from
'@/core/platform'
;
export
default
class
WechatApi
{
static
async
initConfig
(
params
=
{
isAgentConfig
:
false
,
url
:
""
})
{
return
Service
.
Hades
(
"anon/hades/getWxCorpJSAPISignature"
,
{
static
async
initConfig
(
params
=
{
isAgentConfig
:
false
,
url
:
''
})
{
return
Service
.
Hades
(
'anon/hades/getWxCorpJSAPISignature'
,
{
storeId
:
User
.
getStoreId
(),
url
:
params
.
url
,
}).
then
((
result
)
=>
{
const
res
=
result
.
result
;
this
.
config
({
beta
:
true
,
// 必须这么写,否则wx.invoke调用形式的jsapi会有问题
debug
:
tru
e
,
// 开启调试模式,调用的所有api的返回值会在客户端alert出来,若要查看传入的参数,可以在pc端打开,参数信息会通过log打出,仅在pc端时才会打印。
debug
:
fals
e
,
// 开启调试模式,调用的所有api的返回值会在客户端alert出来,若要查看传入的参数,可以在pc端打开,参数信息会通过log打出,仅在pc端时才会打印。
appId
:
res
.
appId
,
// 必填,企业微信的corpID
timestamp
:
res
.
timestamp
,
// 必填,生成签名的时间戳
nonceStr
:
res
.
nonceStr
,
// 必填,生成签名的随机串
signature
:
res
.
signature
,
// 必填,签名,见 附录-JS-SDK使用权限签名算法
jsApiList
:
[
"chooseImage"
,
"shareToExternalContact"
,
"selectExternalContact"
,
"selectEnterpriseContact"
,
"startRecord"
,
],
jsApiList
:
[
'chooseImage'
,
'shareToExternalContact'
,
'selectExternalContact'
,
'selectEnterpriseContact'
],
});
if
(
params
.
isAgentConfig
)
{
return
new
Promise
(
async
(
resolve
,
reject
)
=>
{
Service
.
Hades
(
"anon/hades/getWxWorkJSAPISignature"
,
{
Service
.
Hades
(
'anon/hades/getWxWorkJSAPISignature'
,
{
storeId
:
User
.
getStoreId
(),
url
:
params
.
url
,
}).
then
((
result2
)
=>
{
...
...
@@ -47,21 +41,14 @@ export default class WechatApi {
timestamp
:
res2
.
timestamp
,
// 必填,生成签名的时间戳
nonceStr
:
res2
.
nonceStr
,
// 必填,生成签名的随机串
signature
:
res2
.
signature
,
// 必填,签名,见附录-JS-SDK使用权限签名算法
jsApiList
:
[
"selectExternalContact"
,
"getCurExternalContact"
,
"getContext"
,
"shareToExternalContact"
,
"sendChatMessage"
,
"shareToExternalChat"
,
],
jsApiList
:
[
'selectExternalContact'
,
'getCurExternalContact'
,
'getContext'
,
'shareToExternalContact'
,
'sendChatMessage'
,
'shareToExternalChat'
],
success
:
(
res
)
=>
{
console
.
log
(
res
,
"res-agentconfig"
);
console
.
info
(
"window.WWOpenData"
,
window
.
WWOpenData
);
console
.
log
(
res
,
'res-agentconfig'
);
console
.
info
(
'window.WWOpenData'
,
window
.
WWOpenData
);
resolve
(
res
);
},
fail
:
(
err
)
=>
{
console
.
log
(
err
,
"err-agentconfig"
);
console
.
log
(
err
,
'err-agentconfig'
);
reject
(
err
);
},
});
...
...
@@ -73,16 +60,16 @@ export default class WechatApi {
static
async
config
(
config
)
{
return
new
Promise
((
resolve
,
reject
)
=>
{
console
.
info
(
"wx.config"
,
config
);
console
.
info
(
'wx.config'
,
config
);
wx
.
config
(
config
);
wx
.
ready
(
resolve
);
wx
.
error
(
reject
);
}).
then
(
()
=>
{
console
.
info
(
"wx.ready"
);
console
.
info
(
'wx.ready'
);
},
(
error
)
=>
{
console
.
error
(
"wx.error"
,
error
);
console
.
error
(
'wx.error'
,
error
);
throw
error
;
}
);
...
...
@@ -90,15 +77,15 @@ export default class WechatApi {
static
async
agentConfig
(
config
)
{
return
new
Promise
((
success
,
fail
)
=>
{
console
.
info
(
"wx.agentConfig"
,
config
);
console
.
info
(
'wx.agentConfig'
,
config
);
wx
.
agentConfig
({
...
config
,
success
,
fail
});
}).
then
(
(
res
)
=>
{
console
.
info
(
"wx.agentConfig success"
,
res
);
console
.
info
(
'wx.agentConfig success'
,
res
);
return
res
;
},
(
error
)
=>
{
console
.
error
(
"wx.agentConfig fail"
,
error
);
console
.
error
(
'wx.agentConfig fail'
,
error
);
throw
error
;
}
);
...
...
@@ -107,8 +94,8 @@ export default class WechatApi {
static
getCurExternalContact
()
{
return
new
Promise
((
resolve
,
reject
)
=>
{
wx
.
ready
(()
=>
{
wx
.
invoke
(
"getCurExternalContact"
,
{},
function
(
res
)
{
if
(
res
.
err_msg
==
"getCurExternalContact:ok"
)
{
wx
.
invoke
(
'getCurExternalContact'
,
{},
function
(
res
)
{
if
(
res
.
err_msg
==
'getCurExternalContact:ok'
)
{
resolve
(
res
.
userId
);
//返回当前外部联系人userId
}
else
{
reject
(
res
.
err_msg
);
//错误处理
...
...
@@ -121,8 +108,8 @@ export default class WechatApi {
static
getContext
()
{
return
new
Promise
((
resolve
,
reject
)
=>
{
wx
.
ready
(()
=>
{
wx
.
invoke
(
"getContext"
,
{},
function
(
res
)
{
if
(
res
.
err_msg
==
"getContext:ok"
)
{
wx
.
invoke
(
'getContext'
,
{},
function
(
res
)
{
if
(
res
.
err_msg
==
'getContext:ok'
)
{
resolve
(
res
.
entry
);
//返回进入H5页面的入口类型,目前有normal、contact_profile、single_chat_tools、group_chat_tools、chat_attachment
}
else
{
reject
(
res
.
err_msg
);
//错误处理
...
...
@@ -131,10 +118,4 @@ export default class WechatApi {
});
});
}
static
startRecord
()
{
if
(
Platform
.
isWorkWx
())
{
wx
.
startRecord
();
}
}
}
src/modules/teach-tool/components/XMRecord.jsx
View file @
b1ac4226
/*
* @Author: 吴文洁
* @Date: 2020-03-18 10:01:28
* @LastEditors:
yuananti
ng
* @LastEditTime: 2021-06-
09 19:59:27
* @LastEditors:
fusanqias
ng
* @LastEditTime: 2021-06-
22 16:52:13
* @Description: 录音组件
*/
import
React
,
{
Component
}
from
"react"
;
import
{
Button
,
Modal
}
from
"antd"
;
import
React
,
{
Component
}
from
'react'
;
import
{
Button
,
Modal
}
from
'antd'
;
import
UploadOss
from
"@/core/upload"
;
import
{
RECORD_ERROR
}
from
"@/common/constants/academic"
;
import
AudioRecorder
from
"../components/audioRecord"
;
import
UploadOss
from
'@/core/upload'
;
import
{
RECORD_ERROR
}
from
'@/common/constants/academic'
;
import
AudioRecorder
from
'../components/audioRecord'
;
import
Platform
from
'@/core/platform'
;
import
WechatApi
from
"@/common/js/wechatApi"
;
import
WechatApi
from
'@/common/js/wechatApi'
;
import
"./XMRecord.less"
;
import
'./XMRecord.less'
;
class
XMRecord
extends
Component
{
constructor
(
props
)
{
...
...
@@ -35,7 +35,7 @@ class XMRecord extends Component {
componentDidMount
()
{
// 获取录音设备
this
.
getAudioRecorderDevice
();
WechatApi
.
initConfig
({
isAgentConfig
:
false
,
url
:
window
.
location
.
href
.
split
(
'#'
)[
0
]
})
WechatApi
.
initConfig
({
isAgentConfig
:
false
,
url
:
window
.
location
.
href
.
split
(
'#'
)[
0
]
})
;
}
componentWillUnmount
()
{}
...
...
@@ -52,15 +52,10 @@ class XMRecord extends Component {
if
(
navigator
.
mediaDevices
.
getUserMedia
===
undefined
)
{
navigator
.
mediaDevices
.
getUserMedia
=
function
(
constraints
)
{
// 首先,如果有getUserMedia的话,就获得它
var
getUserMedia
=
navigator
.
getUserMedia
||
navigator
.
webkitGetUserMedia
||
navigator
.
mozGetUserMedia
;
var
getUserMedia
=
navigator
.
getUserMedia
||
navigator
.
webkitGetUserMedia
||
navigator
.
mozGetUserMedia
;
// 一些浏览器根本没实现它 - 那么就返回一个error到promise的reject来保持一个统一的接口
if
(
!
getUserMedia
)
{
return
Promise
.
reject
(
new
Error
(
"getUserMedia is not implemented in this browser"
)
);
return
Promise
.
reject
(
new
Error
(
'getUserMedia is not implemented in this browser'
));
}
// 否则,为老的navigator.getUserMedia方法包裹一个Promise
...
...
@@ -72,12 +67,11 @@ class XMRecord extends Component {
};
openDeviceFailure
=
(
reason
)
=>
{
const
{
title
=
"麦克风调用错误"
,
content
=
"请检查麦克风是否可用"
}
=
RECORD_ERROR
[
reason
.
name
]
||
{};
const
{
title
=
'麦克风调用错误'
,
content
=
'请检查麦克风是否可用'
}
=
RECORD_ERROR
[
reason
.
name
]
||
{};
Modal
.
info
({
title
,
content
,
okText
:
"我知道了"
,
okText
:
'我知道了'
,
});
};
...
...
@@ -87,19 +81,7 @@ class XMRecord extends Component {
};
handleStartRecord
=
()
=>
{
alert
(
"是企微"
,
Platform
.
isWorkWx
())
if
(
Platform
.
isWorkWx
())
{
// 企业微信
alert
(
"进入"
)
WechatApi
.
startRecord
({
success
:
function
(
res
)
{
alert
(
"开始录音"
,
res
)
},
fail
:
function
(
res
)
{
alert
(
"未开始录音"
,
res
)
}
});
}
else
{
navigator
.
mediaDevices
navigator
.
mediaDevices
.
getUserMedia
({
audio
:
true
,
})
...
...
@@ -108,7 +90,6 @@ class XMRecord extends Component {
this
.
mMediaRecorder
.
start
();
this
.
handleCountTime
();
},
this
.
openDeviceFailure
);
}
};
onProcessData
=
(
audioData
)
=>
{
...
...
@@ -138,17 +119,15 @@ class XMRecord extends Component {
this
.
mMediaRecorder
.
stop
();
}
const
blob
=
this
.
mMediaRecorder
.
upload
();
UploadOss
.
uploadBlobToOSS
(
blob
,
window
.
random_string
(
16
)
+
".wav"
).
then
(
(
mp3URL
)
=>
{
const
{
recordTime
}
=
this
.
state
;
this
.
props
.
onFinish
(
mp3URL
,
recordTime
*
1000
);
this
.
setState
({
recordTime
:
0
,
isFinished
:
true
,
});
window
.
clearInterval
(
this
.
timer
);
}
);
UploadOss
.
uploadBlobToOSS
(
blob
,
window
.
random_string
(
16
)
+
'.wav'
).
then
((
mp3URL
)
=>
{
const
{
recordTime
}
=
this
.
state
;
this
.
props
.
onFinish
(
mp3URL
,
recordTime
*
1000
);
this
.
setState
({
recordTime
:
0
,
isFinished
:
true
,
});
window
.
clearInterval
(
this
.
timer
);
});
};
// 格式化当前录音时长
...
...
@@ -182,36 +161,27 @@ class XMRecord extends Component {
const
{
isFinished
,
recordTime
}
=
this
.
state
;
const
{
visible
,
maxTime
=
180
}
=
this
.
props
;
return
(
<
div
className=
{
`xm-record ${visible ?
"visible" : "hidden"
}`
}
>
<
div
className=
"record-left"
>
<
div
className=
"text"
>
<
div
className=
{
`xm-record ${visible ?
'visible' : 'hidden'
}`
}
>
<
div
className=
'record-left'
>
<
div
className=
'text'
>
{
isFinished
?
(
<
img
style=
{
{
width
:
14
,
height
:
14
}
}
src=
"https://image.xiaomaiketang.com/xm/xCahGm2Q2J.png"
/>
<
img
style=
{
{
width
:
14
,
height
:
14
}
}
src=
'https://image.xiaomaiketang.com/xm/xCahGm2Q2J.png'
/>
)
:
(
<
img
src=
"https://xiaomai-image.oss-cn-hangzhou.aliyuncs.com/1584607726775.png"
/>
<
img
src=
'https://xiaomai-image.oss-cn-hangzhou.aliyuncs.com/1584607726775.png'
/>
)
}
{
isFinished
?
<
span
>
录音
</
span
>
:
<
span
>
录音中...
</
span
>
}
</
div
>
<
div
className=
"time"
>
{
`${this.formatRecordTime(
recordTime
)}/${this.formatRecordTime(maxTime)}`
}
</
div
>
<
div
className=
'time'
>
{
`${this.formatRecordTime(recordTime)}/${this.formatRecordTime(maxTime)}`
}
</
div
>
</
div
>
<
div
className=
"btn-wrapper"
>
<
div
className=
'btn-wrapper'
>
<
Button
onClick=
{
this
.
handleCancel
}
>
取消
</
Button
>
{
isFinished
?
(
<
Button
type=
"primary"
onClick=
{
this
.
handleStartRecord
}
>
<
Button
type=
'primary'
onClick=
{
this
.
handleStartRecord
}
>
开始
</
Button
>
)
:
(
<
Button
type=
"primary"
className=
"finish"
onClick=
{
this
.
handleFinishRecord
}
>
<
Button
type=
'primary'
className=
'finish'
onClick=
{
this
.
handleFinishRecord
}
>
完成
</
Button
>
)
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment