import common from '../utils/util'; var app = getApp(); function getData(url, callback) { //console.log("加密前的结果为===", url); var url = common.Encrypt(url); //console.log("加密后的结果为===",url); wx.request({ url: app.globalData.serverUrl + url, success: function (res) { if (res.statusCode) common.checkError(res.statusCode); var data = res.data.result; callback(data); }, fail: function () { wx.redirectTo({ url: './error', }); }, }); } function postData(url, postData, callback) { var url = common.Encrypt(url); //console.log("加密后的结果为===",url); wx.request({ url: app.globalData.serverUrl + url, method: "POST", data: postData, success: function (res) { if (res.statusCode) common.checkError(res.statusCode); var data = res.data.result; callback(data); }, fail: function () { wx.showToast({ title: '服务器忙,请稍候再试!', duration: 3000 }); wx.redirectTo({ url: './error', }); }, }); } function getLocalHost(callback) { if (!app.globalData.IsProduction) { var url = common.Encrypt("Ping"); wx.request({ url: app.globalData.serverUrlLocalhost + url, success: function (res) { app.globalData.serverUrl = app.globalData.serverUrlLocalhost; callback(); }, fail: function () { app.globalData.serverUrl = app.globalData.serverUrlServer; callback(); }, }); } else { app.globalData.serverUrl = app.globalData.serverUrlServer; callback(); } } function shareGroup(shareTickets, isShared) { // 转发成功 console.log("shareTickets:" + shareTickets); if (shareTickets && shareTickets.length > 0) { var that = this; for (var i = 0; i < shareTickets.length; i++) { wx.getShareInfo({ shareTicket: shareTickets[i], success: function (groupInfo) { wx.login({ success: function (res0) { console.log("groupInfo:" + groupInfo); that.postData('AddSpatialIntelligenceGroup', { Code: res0.code, UserID: app.globalData.userInfo.UserID, GroupInfo: groupInfo, IsShared: isShared, }, function (data) { }); } }); }, fail: function (err) { console.log(err); }, }); } } } function payMoney(payType, money, callback) { console.log(money); //登录认证 wx.login({ success: function (res) { if (res.code) { console.log('获取用户登录态成功!' + res.code); //预支付 getData('PayLogin?code=' + res.code + '&payType=' + payType + '&money=' + money, function (data) { if (data && data.timeStamp) { //微信支付 wx.requestPayment({ 'timeStamp': data.timeStamp.toString(), 'nonceStr': data.nonceStr, 'package': data.package, 'signType': 'MD5', 'paySign': data.paySign, 'success': function (res3) { console.log("success:" + res3); callback(); }, 'fail': function (err) { if (err && err.errMsg && err.errMsg.indexOf("fail cancel")) { } else { wx.showToast({ title: '服务器忙,请稍候再试!', duration: 3000 }); wx.redirectTo({ url: './error', }); } } }); } }); } else { console.log('获取用户登录态失败!' + res.errMsg); } } }); } function getTimeFormat(duration) { //console.log("duration:" + duration); var arr = ['', '', ''] if (duration.indexOf("'") > 0) arr[0] = duration.substring(0, duration.indexOf("'")); if (duration.indexOf(".") > 0) { arr[1] = duration.substring(duration.indexOf("'") + 1, duration.indexOf(".") + 1); arr[2] = duration.substring(duration.indexOf(".") + 1, duration.indexOf('"')); } else { arr[1] = duration.substring(duration.indexOf("'") + 1, duration.indexOf('"')); } return arr; } function getWindowHeight() { var height = app.globalData.systemInfo.windowHeight; //console.log("app.globalData.systemInfo.windowHeight:" + app.globalData.systemInfo.windowHeight * 2); if (app.globalData.systemInfo.model) { if (height == 504 && ( app.globalData.systemInfo.model.indexOf("iPhone 6<") >= 0 || app.globalData.systemInfo.model.indexOf("iPhone 7<") >= 0 || app.globalData.systemInfo.model.indexOf("iPhone 6s<") >= 0 || app.globalData.systemInfo.model.indexOf("iPhone 5") >= 0 || app.globalData.systemInfo.model.indexOf("iPhone SE") >= 0 )) { height = 596; } } height = height * 2; if (app.globalData.systemInfo.system && app.globalData.systemInfo.system.indexOf("Android") >= 0) { height = height + 168; } else { height = height + 50; } //console.log("height:" + height); return height; } //获取存储数据,若不存在,则获得缺省值。 function getStorageValue(obj, name, defaultStatus, callback) { wx.getStorage({ key: name, success: function (res) { obj.data[name] = res.data; obj.setData(obj.data); callback(); }, fail: function (res) { obj.data[name] = defaultStatus; obj.setData(obj.data); callback(); }, }); } function getDifficulty(num) { switch (Number(num)) { case 3: case 4: case 5: return "EASY"; case 6: case 7: return "HARD"; case 8: case 9: return "SUPER"; } } function getProgramList() { return [ { id: 89, Name:"数学口算", appId: 'wx46a7b4c420e6d38f', path: 'pages/index/start?SourceID=' + app.globalData.ProgramID, imageName:"universalpic_product_kousuan_icon_size01", }, { id: 98, Name: "语文汉语拼音", appId: 'wx331e8dd070f01d0e', path: 'pages/index/index?SourceID=' + app.globalData.ProgramID, imageName: "universalpic_product_pinyin_icon_size01", }, { id: 106, Name: "语文识字", appId: 'wx313a8f2c0741efe1', path: 'pages/index/index?SourceID=' + app.globalData.ProgramID, imageName: "universalpic_product_shizi_icon_size01", }, { id: 99, Name: "英语自然拼读", appId: 'wxb54a6d5aff836ee3', path: 'pages/index/index?SourceID=' + app.globalData.ProgramID, imageName: "universalpic_product_phonics_icon_size01", }, { id: 90, Name: "注意力游戏", appId: 'wxa5e33c61fe37dd01', path: 'pages/index/index?SourceID=' + app.globalData.ProgramID, imageName: "universalpic_product_zhuyili_icon_size01", }, { id: 127, Name: "空间智力游戏", appId: 'wxaa1a8b48d9853872', path: 'pages/index/game?SourceID=' + app.globalData.ProgramID, imageName: "universalpic_product_kongjian_icon_size01", }, ]; } function gotoFeedback() { wx.navigateToMiniProgram({ appId: "wx80059777521b897c", path: "pages/index/feedback", extraData: { }, success(res) { // 打开成功 } }); } function playAudio(ctx, sentence, player) { var url = app.globalData.audioUrlBaidu; url = url.replace("[token]", app.globalData.BaiduToken); url = url.replace("[word]", sentence); if (player) url = url.replace("per=4", "per="+player); //console.log(url); ctx.setSrc(url); ctx.play(); } function playSound(file){ const innerAudioContext = wx.createInnerAudioContext() innerAudioContext.autoplay = true innerAudioContext.src = file innerAudioContext.onPlay(() => { console.log('开始播放') }) } module.exports = { getData: getData, postData: postData, shareGroup: shareGroup, payMoney: payMoney, getLocalHost: getLocalHost, getTimeFormat: getTimeFormat, getWindowHeight: getWindowHeight, getStorageValue: getStorageValue, getDifficulty: getDifficulty, getProgramList: getProgramList, gotoFeedback: gotoFeedback, playAudio: playAudio, playSound: playSound, }