main.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412
  1. import common from '../utils/util';
  2. var app = getApp();
  3. function getData(url, callback) {
  4. //console.log("加密前的结果为===", url);
  5. var url = common.Encrypt(url);
  6. //console.log("加密后的结果为===",url);
  7. wx.request({
  8. url: app.globalData.serverUrl + url,
  9. success: function (res) {
  10. if (res.statusCode)
  11. common.checkError(res.statusCode);
  12. var data = res.data.result;
  13. callback(data);
  14. },
  15. fail: function () {
  16. wx.redirectTo({
  17. url: './error',
  18. });
  19. },
  20. });
  21. }
  22. function postData(url, postData, callback) {
  23. var url = common.Encrypt(url);
  24. //console.log("加密后的结果为===",url);
  25. wx.request({
  26. url: app.globalData.serverUrl + url,
  27. method: "POST",
  28. data: postData,
  29. success: function (res) {
  30. if (res.statusCode)
  31. common.checkError(res.statusCode);
  32. var data = res.data.result;
  33. callback(data);
  34. },
  35. fail: function () {
  36. wx.showToast({
  37. title: '服务器忙,请稍候再试!',
  38. duration: 3000
  39. });
  40. wx.redirectTo({
  41. url: './error',
  42. });
  43. },
  44. });
  45. }
  46. function getLocalHost(callback) {
  47. if (!app.globalData.IsProduction) {
  48. var url = common.Encrypt("Ping");
  49. wx.request({
  50. url: app.globalData.serverUrlLocalhost + url,
  51. success: function (res) {
  52. app.globalData.serverUrl = app.globalData.serverUrlLocalhost;
  53. callback();
  54. },
  55. fail: function () {
  56. app.globalData.serverUrl = app.globalData.serverUrlServer;
  57. callback();
  58. },
  59. });
  60. }
  61. else {
  62. app.globalData.serverUrl = app.globalData.serverUrlServer;
  63. callback();
  64. }
  65. }
  66. function shareGroup(shareTickets, isShared) {
  67. // 转发成功
  68. console.log("shareTickets:" + shareTickets);
  69. if (shareTickets && shareTickets.length > 0) {
  70. var that = this;
  71. for (var i = 0; i < shareTickets.length; i++) {
  72. wx.getShareInfo({
  73. shareTicket: shareTickets[i],
  74. success: function (groupInfo) {
  75. wx.login({
  76. success: function (res0) {
  77. console.log("groupInfo:" + groupInfo);
  78. that.postData('AddSpatialIntelligenceGroup', {
  79. Code: res0.code,
  80. UserID: app.globalData.userInfo.UserID,
  81. GroupInfo: groupInfo,
  82. IsShared: isShared,
  83. }, function (data) {
  84. });
  85. }
  86. });
  87. },
  88. fail: function (err) {
  89. console.log(err);
  90. },
  91. });
  92. }
  93. }
  94. }
  95. function payMoney(payType, buyType, money, detail, callback) {
  96. console.log(money);
  97. if (app.globalData.userInfo.UserID == 1)
  98. money = 0.01;
  99. else if (app.globalData.userInfo.UserID == 5)
  100. money = 0.01;
  101. //登录认证
  102. wx.login({
  103. success: function (res) {
  104. if (res.code) {
  105. console.log('获取用户登录态成功!' + res.code);
  106. //预支付
  107. getData('ProductPayLogin500?code=' + res.code + '&payType=' + payType + '&buyType=' + buyType + '&money=' + money + '&detail=' + detail + '&productID=' + app.globalData.ProgramID, function (data) {
  108. if (data && data.timeStamp) {
  109. //微信支付
  110. wx.requestPayment({
  111. 'timeStamp': data.timeStamp.toString(),
  112. 'nonceStr': data.nonceStr,
  113. 'package': data.package,
  114. 'signType': 'MD5',
  115. 'paySign': data.paySign,
  116. 'success': function (res3) {
  117. console.log("success:" + res3);
  118. callback(data);
  119. },
  120. 'fail': function (err) {
  121. if (err && err.errMsg && err.errMsg.indexOf("fail cancel")) {
  122. }
  123. else {
  124. wx.showToast({
  125. title: '服务器忙,请稍候再试!',
  126. duration: 3000
  127. });
  128. }
  129. }
  130. });
  131. }
  132. });
  133. } else {
  134. console.log('获取用户登录态失败!' + res.errMsg);
  135. wx.showToast({
  136. title: '服务器忙,请稍候再试!',
  137. duration: 3000
  138. });
  139. }
  140. }
  141. });
  142. }
  143. function getTimeFormat(duration) {
  144. //console.log("duration:" + duration);
  145. var arr = ['', '', '']
  146. if (duration.indexOf("'") > 0)
  147. arr[0] = duration.substring(0, duration.indexOf("'"));
  148. if (duration.indexOf(".") > 0) {
  149. arr[1] = duration.substring(duration.indexOf("'") + 1, duration.indexOf(".") + 1);
  150. arr[2] = duration.substring(duration.indexOf(".") + 1, duration.indexOf('"'));
  151. }
  152. else {
  153. arr[1] = duration.substring(duration.indexOf("'") + 1, duration.indexOf('"'));
  154. }
  155. return arr;
  156. }
  157. function getWindowHeight() {
  158. var height = app.globalData.systemInfo.windowHeight;
  159. //console.log("app.globalData.systemInfo.windowHeight:" + app.globalData.systemInfo.windowHeight * 2);
  160. if (app.globalData.systemInfo.model) {
  161. if (height == 504 && (
  162. app.globalData.systemInfo.model.indexOf("iPhone 6<") >= 0
  163. || app.globalData.systemInfo.model.indexOf("iPhone 7<") >= 0
  164. || app.globalData.systemInfo.model.indexOf("iPhone 6s<") >= 0
  165. || app.globalData.systemInfo.model.indexOf("iPhone 5") >= 0
  166. || app.globalData.systemInfo.model.indexOf("iPhone SE") >= 0
  167. )) {
  168. height = 596;
  169. }
  170. }
  171. height = height * 2;
  172. if (app.globalData.systemInfo.system && app.globalData.systemInfo.system.indexOf("Android") >= 0) {
  173. height = height + 168;
  174. }
  175. else {
  176. height = height + 50;
  177. }
  178. //console.log("height:" + height);
  179. return height;
  180. }
  181. //获取存储数据,若不存在,则获得缺省值。
  182. function getStorageValue(obj, name, defaultStatus, callback) {
  183. wx.getStorage({
  184. key: name,
  185. success: function (res) {
  186. obj.data[name] = res.data;
  187. obj.setData(obj.data);
  188. callback();
  189. },
  190. fail: function (res) {
  191. obj.data[name] = defaultStatus;
  192. obj.setData(obj.data);
  193. callback();
  194. },
  195. });
  196. }
  197. function getDifficulty(num) {
  198. switch (Number(num)) {
  199. case 3:
  200. case 4:
  201. case 5:
  202. return "EASY";
  203. case 6:
  204. case 7:
  205. return "HARD";
  206. case 8:
  207. case 9:
  208. return "SUPER";
  209. }
  210. }
  211. function getProgramList() {
  212. return [
  213. {
  214. ID: 166,
  215. Name: "秒过学习",
  216. Name2: "家长帮助孩子快速提高学习成绩",
  217. ImageUrl: "product_icon_mg_70x70.png",
  218. appId: 'wx84b3feac6069eec3',
  219. path: 'pages/index/index?SourceID=' + app.globalData.ProgramID,
  220. IsShow: true,
  221. IsShow2: true,
  222. Category: "",
  223. },
  224. {
  225. ID: 164,
  226. Name: "口算",
  227. Name2: "透视问题刻意练习",
  228. ImageUrl: "product_icon_ksxq_70x70.png",
  229. appId: 'wxa5441bbf344692ba',
  230. path: 'pages/index/index?SourceID=' + app.globalData.ProgramID,
  231. IsShow: true,
  232. IsShow2: true,
  233. Category: "数学系列",
  234. },
  235. {
  236. ID: 105,
  237. Name: "计算题",
  238. Name2: "竖式计算打印批改",
  239. ImageUrl: "product_icon_jst_70x70.png",
  240. appId: 'wx1fef080f74481cbd',
  241. path: 'pages/index/index?SourceID=' + app.globalData.ProgramID,
  242. IsShow: false,
  243. IsShow2: true,
  244. Category: "数学系列",
  245. },
  246. {
  247. ID: 106,
  248. Name: "识字",
  249. Name2: "课本同步汉字发言组词",
  250. ImageUrl: "product_icon_sz_70x70.png",
  251. appId: 'wx313a8f2c0741efe1',
  252. path: 'pages/index/index?SourceID=' + app.globalData.ProgramID,
  253. IsShow: true,
  254. IsShow2: true,
  255. Category: "语文系列",
  256. },
  257. {
  258. ID: 98,
  259. Name: "汉语拼音",
  260. Name2: "纯正发音练习",
  261. ImageUrl: "product_icon_py_70x70.png",
  262. appId: 'wx331e8dd070f01d0e',
  263. path: 'pages/index/index?SourceID=' + app.globalData.ProgramID,
  264. IsShow: true,
  265. IsShow2: true,
  266. Category: "语文系列",
  267. },
  268. {
  269. ID: 99,
  270. Name: "自然拼读",
  271. Name2: "真正英语国家母语学习法",
  272. ImageUrl: "product_icon_pd_70x70.png",
  273. appId: 'wxb54a6d5aff836ee3',
  274. path: 'pages/index/index?SourceID=' + app.globalData.ProgramID,
  275. IsShow: true,
  276. IsShow2: true,
  277. Category: "英语系列",
  278. },
  279. {
  280. ID: 89,
  281. Name: "数学口算练习",
  282. Name2: "帮助孩子快速提高口算能力",
  283. ImageUrl: "product_icon_kslx_70x70.png",
  284. appId: 'wx46a7b4c420e6d38f',
  285. path: 'pages/index/start?SourceID=' + app.globalData.ProgramID,
  286. IsShow: false,
  287. IsShow2: false,
  288. Category: "",
  289. },
  290. ];
  291. }
  292. function getProgramListOld() {
  293. return [
  294. {
  295. ID: 166,
  296. Name: "秒过学习",
  297. appId: 'wx84b3feac6069eec3',
  298. path: 'pages/index/index?SourceID=' + app.globalData.ProgramID,
  299. imageName: "product_icon_mg_70x70",
  300. },
  301. {
  302. id: 164,
  303. Name:"口算星球",
  304. appId: 'wxa5441bbf344692ba',
  305. path: 'pages/index/index?SourceID=' + app.globalData.ProgramID,
  306. imageName:"universalpic_product_kousuan_icon_size01",
  307. },
  308. {
  309. id: 98,
  310. Name: "语文汉语拼音",
  311. appId: 'wx331e8dd070f01d0e',
  312. path: 'pages/index/index?SourceID=' + app.globalData.ProgramID,
  313. imageName: "universalpic_product_pinyin_icon_size01",
  314. },
  315. {
  316. id: 106,
  317. Name: "语文识字",
  318. appId: 'wx313a8f2c0741efe1',
  319. path: 'pages/index/index?SourceID=' + app.globalData.ProgramID,
  320. imageName: "universalpic_product_shizi_icon_size01",
  321. },
  322. {
  323. id: 99,
  324. Name: "英语自然拼读",
  325. appId: 'wxb54a6d5aff836ee3',
  326. path: 'pages/index/index?SourceID=' + app.globalData.ProgramID,
  327. imageName: "universalpic_product_phonics_icon_size01",
  328. },
  329. {
  330. id: 90,
  331. Name: "注意力游戏",
  332. appId: 'wxa5e33c61fe37dd01',
  333. path: 'pages/index/index?SourceID=' + app.globalData.ProgramID,
  334. imageName: "universalpic_product_zhuyili_icon_size01",
  335. },
  336. {
  337. id: 127,
  338. Name: "空间智力游戏",
  339. appId: 'wxaa1a8b48d9853872',
  340. path: 'pages/index/game?SourceID=' + app.globalData.ProgramID,
  341. imageName: "universalpic_product_kongjian_icon_size01",
  342. },
  343. ];
  344. }
  345. function gotoFeedback() {
  346. wx.navigateToMiniProgram({
  347. appId: "wx80059777521b897c",
  348. path: "pages/index/feedback",
  349. extraData: {
  350. },
  351. success(res) {
  352. // 打开成功
  353. }
  354. });
  355. }
  356. function playAudio(ctx, sentence, player) {
  357. var url = app.globalData.audioUrlBaidu;
  358. url = url.replace("[token]", app.globalData.BaiduToken);
  359. url = url.replace("[word]", sentence);
  360. if (player)
  361. url = url.replace("per=4", "per="+player);
  362. //console.log(url);
  363. ctx.setSrc(url);
  364. ctx.play();
  365. }
  366. function playSound(file){
  367. const innerAudioContext = wx.createInnerAudioContext()
  368. innerAudioContext.autoplay = true
  369. innerAudioContext.src = file
  370. innerAudioContext.onPlay(() => {
  371. //console.log('开始播放')
  372. })
  373. }
  374. module.exports = {
  375. getData: getData,
  376. postData: postData,
  377. shareGroup: shareGroup,
  378. payMoney: payMoney,
  379. getLocalHost: getLocalHost,
  380. getTimeFormat: getTimeFormat,
  381. getWindowHeight: getWindowHeight,
  382. getStorageValue: getStorageValue,
  383. getDifficulty: getDifficulty,
  384. getProgramList: getProgramList,
  385. getProgramListOld: getProgramListOld,
  386. gotoFeedback: gotoFeedback,
  387. playAudio: playAudio,
  388. playSound: playSound,
  389. }