diff --git a/README.md b/README.md index 3b38217..d58cad7 100644 --- a/README.md +++ b/README.md @@ -7,8 +7,10 @@ - 个人类小程序不支持 web-view - wx.shareFileMessage 可以直接分享文件 -- [ ] 内容安全问题处理 +- [x] 内容安全问题处理 - https://developers.weixin.qq.com/miniprogram/dev/api-backend/open-api/sec-check/security.msgSecCheck.html - [ ] 从列表页返回后应该关闭正在播放的列表页语音 +- [ ] 时间长了本地缓存文件失效后应当清除对应播放列表 + diff --git a/app.js b/app.js index f87c389..84ce811 100644 --- a/app.js +++ b/app.js @@ -1,9 +1,94 @@ //app.js App({ - onLaunch () { - + async onLaunch () { + this.login(); + }, + // 将登录态封装进去 + // todo: 多个请求同时发起,且登录态都失效时,ssid 会相互覆盖 + async request(config){ + let ssid = wx.getStorageSync('ssid'); + if(!ssid){ + ssid = await this.login(); + } + const initialSuccess = config.success; + config.data = { + ...config.data, + ssid + }; + config.success = async resp => { + if(resp.data.code === 5001000){ + wx.setStorageSync('ssid', ''); + delete config.ssid; + this.request(config); + } + else{ + initialSuccess(resp); + } + }; + config = { + header: { + 'content-type': 'application/json' + }, + dataType: 'json', + method: 'POST', + ...config + }; + return wx.request(config); + }, + login(){ + let ssid = wx.getStorageSync('ssid'); + if(ssid){ + return ssid; + } + wx.showLoading({ + title: '登录中...', + mask: true + }); + return new Promise((resolve, reject) => { + wx.login({ + success: res => { + wx.request({ + url: `${this.globalData.domain}/open-api/login`, + data: { + code: res.code, + appid: 'wx330e54aa6000516d' + }, + header: { + 'content-type': 'application/json' + }, + dataType: 'json', + method: 'POST', + success: resp => { + const { + ssid, + openid + } = resp.data?.data?.user; + wx.setStorageSync('ssid', ssid); + wx.setStorageSync('openid', openid); + resolve(resp.data?.data?.user); + }, + fail: resp => { + wx.showModal({ + title: '提示', + content: '登录失败,点击确定重试', + showCancel: false, + success: res => { + this.login(); + } + }); + reject(resp.errMsg); + }, + complete: () => { + wx.hideLoading(); + } + }); + } + }); + }); }, globalData: { + // domain: 'http://localhost:3001', + domain: 'https://jilegeji.xwenliang.cn', getTypeList(){ return [ { diff --git a/pages/index/index.js b/pages/index/index.js index 354802d..ddbf3dd 100644 --- a/pages/index/index.js +++ b/pages/index/index.js @@ -19,9 +19,41 @@ Page({ inputText(e){ this.data.text = e.detail.value; }, - play(){ + async play(){ const text = this.data.text || this.data.placeholder; const url = this.data.type[this.data.selectedIndex].createUrl(text); + wx.showLoading({ + title: '正在合成语音...', + mask: true + }); + // 检查文本是否合规 + const result = await new Promise((resolve, reject) => { + app.request({ + url: `${app.globalData.domain}/open-api/wechat-msg-sec-check`, + data: { + appid: 'wx330e54aa6000516d', + content: text, + openid: wx.getStorageSync('openid') + }, + success(res){ + resolve(JSON.parse(res.data?.data)?.result); + }, + fail(err){ + reject(err); + } + }); + }); + wx.hideLoading(); + // 不合规结束 + if(result.suggest !== 'pass'){ + return wx.showToast({ + title: '内容不合规', + icon: 'error', + mask: true, + duration: 2000 + }); + } + this.resetAudio(); audio = wx.createInnerAudioContext({useWebAudioImplement: true}); audio.autoplay = true; diff --git a/project.config.json b/project.config.json index 898b037..35ec1af 100644 --- a/project.config.json +++ b/project.config.json @@ -39,23 +39,16 @@ "useCompilerPlugins": false }, "compileType": "miniprogram", - "libVersion": "1.9.93", + "libVersion": "2.21.3", "appid": "wx330e54aa6000516d", "projectname": "%E8%AF%AD%E9%9F%B3%E5%8A%A9%E6%89%8B", - "isGameTourist": false, - "condition": { - "search": { - "list": [] - }, - "conversation": { - "list": [] - }, - "game": { - "currentL": -1, - "list": [] - }, - "miniprogram": { - "list": [] - } + "condition": {}, + "packOptions": { + "ignore": [], + "include": [] + }, + "editorSetting": { + "tabIndent": "insertSpaces", + "tabSize": 2 } } \ No newline at end of file