Commit b1ac4226 by yuananting

fix:企业微信api调试关闭

parent e220cf0c
/* /*
* @Author: wufan * @Author: wufan
* @Date: 2021-05-11 10:21:37 * @Date: 2021-05-11 10:21:37
* @LastEditors: yuananting * @LastEditors: fusanqiasng
* @LastEditTime: 2021-06-09 20:00:13 * @LastEditTime: 2021-06-22 16:52:48
* @Description: 企业微信api * @Description: 企业微信api
* @@Copyrigh: © 2020 杭州杰竞科技有限公司 版权所有 * @@Copyrigh: © 2020 杭州杰竞科技有限公司 版权所有
*/ */
import User from "@/common/js/user"; import User from '@/common/js/user';
import Service from "@/common/js/service"; import Service from '@/common/js/service';
import Platform from "@/core/platform"; import Platform from '@/core/platform';
export default class WechatApi { export default class WechatApi {
static async initConfig(params = { isAgentConfig: false, url: "" }) { static async initConfig(params = { isAgentConfig: false, url: '' }) {
return Service.Hades("anon/hades/getWxCorpJSAPISignature", { return Service.Hades('anon/hades/getWxCorpJSAPISignature', {
storeId: User.getStoreId(), storeId: User.getStoreId(),
url: params.url, url: params.url,
}).then((result) => { }).then((result) => {
const res = result.result; const res = result.result;
this.config({ this.config({
beta: true, // 必须这么写,否则wx.invoke调用形式的jsapi会有问题 beta: true, // 必须这么写,否则wx.invoke调用形式的jsapi会有问题
debug: true, // 开启调试模式,调用的所有api的返回值会在客户端alert出来,若要查看传入的参数,可以在pc端打开,参数信息会通过log打出,仅在pc端时才会打印。 debug: false, // 开启调试模式,调用的所有api的返回值会在客户端alert出来,若要查看传入的参数,可以在pc端打开,参数信息会通过log打出,仅在pc端时才会打印。
appId: res.appId, // 必填,企业微信的corpID appId: res.appId, // 必填,企业微信的corpID
timestamp: res.timestamp, // 必填,生成签名的时间戳 timestamp: res.timestamp, // 必填,生成签名的时间戳
nonceStr: res.nonceStr, // 必填,生成签名的随机串 nonceStr: res.nonceStr, // 必填,生成签名的随机串
signature: res.signature, // 必填,签名,见 附录-JS-SDK使用权限签名算法 signature: res.signature, // 必填,签名,见 附录-JS-SDK使用权限签名算法
jsApiList: [ jsApiList: ['chooseImage', 'shareToExternalContact', 'selectExternalContact', 'selectEnterpriseContact'],
"chooseImage",
"shareToExternalContact",
"selectExternalContact",
"selectEnterpriseContact",
"startRecord",
],
}); });
if (params.isAgentConfig) { if (params.isAgentConfig) {
return new Promise(async (resolve, reject) => { return new Promise(async (resolve, reject) => {
Service.Hades("anon/hades/getWxWorkJSAPISignature", { Service.Hades('anon/hades/getWxWorkJSAPISignature', {
storeId: User.getStoreId(), storeId: User.getStoreId(),
url: params.url, url: params.url,
}).then((result2) => { }).then((result2) => {
...@@ -47,21 +41,14 @@ export default class WechatApi { ...@@ -47,21 +41,14 @@ export default class WechatApi {
timestamp: res2.timestamp, // 必填,生成签名的时间戳 timestamp: res2.timestamp, // 必填,生成签名的时间戳
nonceStr: res2.nonceStr, // 必填,生成签名的随机串 nonceStr: res2.nonceStr, // 必填,生成签名的随机串
signature: res2.signature, // 必填,签名,见附录-JS-SDK使用权限签名算法 signature: res2.signature, // 必填,签名,见附录-JS-SDK使用权限签名算法
jsApiList: [ jsApiList: ['selectExternalContact', 'getCurExternalContact', 'getContext', 'shareToExternalContact', 'sendChatMessage', 'shareToExternalChat'],
"selectExternalContact",
"getCurExternalContact",
"getContext",
"shareToExternalContact",
"sendChatMessage",
"shareToExternalChat",
],
success: (res) => { success: (res) => {
console.log(res, "res-agentconfig"); console.log(res, 'res-agentconfig');
console.info("window.WWOpenData", window.WWOpenData); console.info('window.WWOpenData', window.WWOpenData);
resolve(res); resolve(res);
}, },
fail: (err) => { fail: (err) => {
console.log(err, "err-agentconfig"); console.log(err, 'err-agentconfig');
reject(err); reject(err);
}, },
}); });
...@@ -73,16 +60,16 @@ export default class WechatApi { ...@@ -73,16 +60,16 @@ export default class WechatApi {
static async config(config) { static async config(config) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
console.info("wx.config", config); console.info('wx.config', config);
wx.config(config); wx.config(config);
wx.ready(resolve); wx.ready(resolve);
wx.error(reject); wx.error(reject);
}).then( }).then(
() => { () => {
console.info("wx.ready"); console.info('wx.ready');
}, },
(error) => { (error) => {
console.error("wx.error", error); console.error('wx.error', error);
throw error; throw error;
} }
); );
...@@ -90,15 +77,15 @@ export default class WechatApi { ...@@ -90,15 +77,15 @@ export default class WechatApi {
static async agentConfig(config) { static async agentConfig(config) {
return new Promise((success, fail) => { return new Promise((success, fail) => {
console.info("wx.agentConfig", config); console.info('wx.agentConfig', config);
wx.agentConfig({ ...config, success, fail }); wx.agentConfig({ ...config, success, fail });
}).then( }).then(
(res) => { (res) => {
console.info("wx.agentConfig success", res); console.info('wx.agentConfig success', res);
return res; return res;
}, },
(error) => { (error) => {
console.error("wx.agentConfig fail", error); console.error('wx.agentConfig fail', error);
throw error; throw error;
} }
); );
...@@ -107,8 +94,8 @@ export default class WechatApi { ...@@ -107,8 +94,8 @@ export default class WechatApi {
static getCurExternalContact() { static getCurExternalContact() {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
wx.ready(() => { wx.ready(() => {
wx.invoke("getCurExternalContact", {}, function (res) { wx.invoke('getCurExternalContact', {}, function (res) {
if (res.err_msg == "getCurExternalContact:ok") { if (res.err_msg == 'getCurExternalContact:ok') {
resolve(res.userId); //返回当前外部联系人userId resolve(res.userId); //返回当前外部联系人userId
} else { } else {
reject(res.err_msg); //错误处理 reject(res.err_msg); //错误处理
...@@ -121,8 +108,8 @@ export default class WechatApi { ...@@ -121,8 +108,8 @@ export default class WechatApi {
static getContext() { static getContext() {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
wx.ready(() => { wx.ready(() => {
wx.invoke("getContext", {}, function (res) { wx.invoke('getContext', {}, function (res) {
if (res.err_msg == "getContext:ok") { if (res.err_msg == 'getContext:ok') {
resolve(res.entry); //返回进入H5页面的入口类型,目前有normal、contact_profile、single_chat_tools、group_chat_tools、chat_attachment resolve(res.entry); //返回进入H5页面的入口类型,目前有normal、contact_profile、single_chat_tools、group_chat_tools、chat_attachment
} else { } else {
reject(res.err_msg); //错误处理 reject(res.err_msg); //错误处理
...@@ -131,10 +118,4 @@ export default class WechatApi { ...@@ -131,10 +118,4 @@ export default class WechatApi {
}); });
}); });
} }
static startRecord() {
if (Platform.isWorkWx()) {
wx.startRecord();
}
}
} }
/* /*
* @Author: 吴文洁 * @Author: 吴文洁
* @Date: 2020-03-18 10:01:28 * @Date: 2020-03-18 10:01:28
* @LastEditors: yuananting * @LastEditors: fusanqiasng
* @LastEditTime: 2021-06-09 19:59:27 * @LastEditTime: 2021-06-22 16:52:13
* @Description: 录音组件 * @Description: 录音组件
*/ */
import React, { Component } from "react"; import React, { Component } from 'react';
import { Button, Modal } from "antd"; import { Button, Modal } from 'antd';
import UploadOss from "@/core/upload"; import UploadOss from '@/core/upload';
import { RECORD_ERROR } from "@/common/constants/academic"; import { RECORD_ERROR } from '@/common/constants/academic';
import AudioRecorder from "../components/audioRecord"; import AudioRecorder from '../components/audioRecord';
import Platform from '@/core/platform'; 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 { class XMRecord extends Component {
constructor(props) { constructor(props) {
...@@ -35,7 +35,7 @@ class XMRecord extends Component { ...@@ -35,7 +35,7 @@ class XMRecord extends Component {
componentDidMount() { componentDidMount() {
// 获取录音设备 // 获取录音设备
this.getAudioRecorderDevice(); this.getAudioRecorderDevice();
WechatApi.initConfig({ isAgentConfig: false, url: window.location.href.split('#')[0] }) WechatApi.initConfig({ isAgentConfig: false, url: window.location.href.split('#')[0] });
} }
componentWillUnmount() {} componentWillUnmount() {}
...@@ -52,15 +52,10 @@ class XMRecord extends Component { ...@@ -52,15 +52,10 @@ class XMRecord extends Component {
if (navigator.mediaDevices.getUserMedia === undefined) { if (navigator.mediaDevices.getUserMedia === undefined) {
navigator.mediaDevices.getUserMedia = function (constraints) { navigator.mediaDevices.getUserMedia = function (constraints) {
// 首先,如果有getUserMedia的话,就获得它 // 首先,如果有getUserMedia的话,就获得它
var getUserMedia = var getUserMedia = navigator.getUserMedia || navigator.webkitGetUserMedia || navigator.mozGetUserMedia;
navigator.getUserMedia ||
navigator.webkitGetUserMedia ||
navigator.mozGetUserMedia;
// 一些浏览器根本没实现它 - 那么就返回一个error到promise的reject来保持一个统一的接口 // 一些浏览器根本没实现它 - 那么就返回一个error到promise的reject来保持一个统一的接口
if (!getUserMedia) { if (!getUserMedia) {
return Promise.reject( return Promise.reject(new Error('getUserMedia is not implemented in this browser'));
new Error("getUserMedia is not implemented in this browser")
);
} }
// 否则,为老的navigator.getUserMedia方法包裹一个Promise // 否则,为老的navigator.getUserMedia方法包裹一个Promise
...@@ -72,12 +67,11 @@ class XMRecord extends Component { ...@@ -72,12 +67,11 @@ class XMRecord extends Component {
}; };
openDeviceFailure = (reason) => { openDeviceFailure = (reason) => {
const { title = "麦克风调用错误", content = "请检查麦克风是否可用" } = const { title = '麦克风调用错误', content = '请检查麦克风是否可用' } = RECORD_ERROR[reason.name] || {};
RECORD_ERROR[reason.name] || {};
Modal.info({ Modal.info({
title, title,
content, content,
okText: "我知道了", okText: '我知道了',
}); });
}; };
...@@ -87,18 +81,6 @@ class XMRecord extends Component { ...@@ -87,18 +81,6 @@ class XMRecord extends Component {
}; };
handleStartRecord = () => { 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({ .getUserMedia({
audio: true, audio: true,
...@@ -108,7 +90,6 @@ class XMRecord extends Component { ...@@ -108,7 +90,6 @@ class XMRecord extends Component {
this.mMediaRecorder.start(); this.mMediaRecorder.start();
this.handleCountTime(); this.handleCountTime();
}, this.openDeviceFailure); }, this.openDeviceFailure);
}
}; };
onProcessData = (audioData) => { onProcessData = (audioData) => {
...@@ -138,8 +119,7 @@ class XMRecord extends Component { ...@@ -138,8 +119,7 @@ class XMRecord extends Component {
this.mMediaRecorder.stop(); this.mMediaRecorder.stop();
} }
const blob = this.mMediaRecorder.upload(); const blob = this.mMediaRecorder.upload();
UploadOss.uploadBlobToOSS(blob, window.random_string(16) + ".wav").then( UploadOss.uploadBlobToOSS(blob, window.random_string(16) + '.wav').then((mp3URL) => {
(mp3URL) => {
const { recordTime } = this.state; const { recordTime } = this.state;
this.props.onFinish(mp3URL, recordTime * 1000); this.props.onFinish(mp3URL, recordTime * 1000);
this.setState({ this.setState({
...@@ -147,8 +127,7 @@ class XMRecord extends Component { ...@@ -147,8 +127,7 @@ class XMRecord extends Component {
isFinished: true, isFinished: true,
}); });
window.clearInterval(this.timer); window.clearInterval(this.timer);
} });
);
}; };
// 格式化当前录音时长 // 格式化当前录音时长
...@@ -182,36 +161,27 @@ class XMRecord extends Component { ...@@ -182,36 +161,27 @@ class XMRecord extends Component {
const { isFinished, recordTime } = this.state; const { isFinished, recordTime } = this.state;
const { visible, maxTime = 180 } = this.props; const { visible, maxTime = 180 } = this.props;
return ( return (
<div className={`xm-record ${visible ? "visible" : "hidden"}`}> <div className={`xm-record ${visible ? 'visible' : 'hidden'}`}>
<div className="record-left"> <div className='record-left'>
<div className="text"> <div className='text'>
{isFinished ? ( {isFinished ? (
<img <img style={{ width: 14, height: 14 }} src='https://image.xiaomaiketang.com/xm/xCahGm2Q2J.png' />
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>} {isFinished ? <span>录音</span> : <span>录音中...</span>}
</div> </div>
<div className="time">{`${this.formatRecordTime( <div className='time'>{`${this.formatRecordTime(recordTime)}/${this.formatRecordTime(maxTime)}`}</div>
recordTime
)}/${this.formatRecordTime(maxTime)}`}</div>
</div> </div>
<div className="btn-wrapper"> <div className='btn-wrapper'>
<Button onClick={this.handleCancel}>取消</Button> <Button onClick={this.handleCancel}>取消</Button>
{isFinished ? ( {isFinished ? (
<Button type="primary" onClick={this.handleStartRecord}> <Button type='primary' onClick={this.handleStartRecord}>
开始 开始
</Button> </Button>
) : ( ) : (
<Button <Button type='primary' className='finish' onClick={this.handleFinishRecord}>
type="primary"
className="finish"
onClick={this.handleFinishRecord}
>
完成 完成
</Button> </Button>
)} )}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment