main.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396
  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. app.globalData.userInfo.IsMember = 1;
  118. app.globalData.userInfo.IsPay = 1;
  119. console.log("success:" + res3);
  120. callback(data);
  121. },
  122. 'fail': function (err) {
  123. if (err && err.errMsg && err.errMsg.indexOf("fail cancel")) {
  124. }
  125. else {
  126. wx.showToast({
  127. title: '服务器忙,请稍候再试!',
  128. duration: 3000
  129. });
  130. }
  131. }
  132. });
  133. }
  134. });
  135. } else {
  136. console.log('获取用户登录态失败!' + res.errMsg);
  137. wx.showToast({
  138. title: '服务器忙,请稍候再试!',
  139. duration: 3000
  140. });
  141. }
  142. }
  143. });
  144. }
  145. function getTimeFormat(duration) {
  146. //console.log("duration:" + duration);
  147. var arr = ['', '', '']
  148. if (duration.indexOf("'") > 0)
  149. arr[0] = duration.substring(0, duration.indexOf("'"));
  150. if (duration.indexOf(".") > 0) {
  151. arr[1] = duration.substring(duration.indexOf("'") + 1, duration.indexOf(".") + 1);
  152. arr[2] = duration.substring(duration.indexOf(".") + 1, duration.indexOf('"'));
  153. }
  154. else {
  155. arr[1] = duration.substring(duration.indexOf("'") + 1, duration.indexOf('"'));
  156. }
  157. return arr;
  158. }
  159. function getWindowHeight() {
  160. var height = app.globalData.systemInfo.windowHeight;
  161. //console.log("app.globalData.systemInfo.windowHeight:" + app.globalData.systemInfo.windowHeight * 2);
  162. if (app.globalData.systemInfo.model) {
  163. if (height == 504 && (
  164. app.globalData.systemInfo.model.indexOf("iPhone 6<") >= 0
  165. || app.globalData.systemInfo.model.indexOf("iPhone 7<") >= 0
  166. || app.globalData.systemInfo.model.indexOf("iPhone 6s<") >= 0
  167. || app.globalData.systemInfo.model.indexOf("iPhone 5") >= 0
  168. || app.globalData.systemInfo.model.indexOf("iPhone SE") >= 0
  169. )) {
  170. height = 596;
  171. }
  172. }
  173. height = height * 2;
  174. if (app.globalData.systemInfo.system && app.globalData.systemInfo.system.indexOf("Android") >= 0) {
  175. height = height + 168;
  176. }
  177. else {
  178. height = height + 50;
  179. }
  180. //console.log("height:" + height);
  181. return height;
  182. }
  183. //获取存储数据,若不存在,则获得缺省值。
  184. function getStorageValue(obj, name, defaultStatus, callback) {
  185. wx.getStorage({
  186. key: name,
  187. success: function (res) {
  188. obj.data[name] = res.data;
  189. obj.setData(obj.data);
  190. callback();
  191. },
  192. fail: function (res) {
  193. obj.data[name] = defaultStatus;
  194. obj.setData(obj.data);
  195. callback();
  196. },
  197. });
  198. }
  199. function getDifficulty(num) {
  200. switch (Number(num)) {
  201. case 3:
  202. case 4:
  203. case 5:
  204. return "EASY";
  205. case 6:
  206. case 7:
  207. return "HARD";
  208. case 8:
  209. case 9:
  210. return "SUPER";
  211. }
  212. }
  213. function getProgramList() {
  214. return [
  215. {
  216. ID: 164,
  217. Name: "口算",
  218. Name2: "透视问题刻意练习",
  219. ImageUrl: "product_icon_ksxq_70x70.png",
  220. appId: 'wxa5441bbf344692ba',
  221. path: 'pages/index/index?SourceID=' + app.globalData.ProgramID,
  222. IsShow: true,
  223. IsShow2: true,
  224. Category: "数学系列",
  225. },
  226. {
  227. ID: 105,
  228. Name: "计算题",
  229. Name2: "竖式计算打印批改",
  230. ImageUrl: "product_icon_jst_70x70.png",
  231. appId: 'wx1fef080f74481cbd',
  232. path: 'pages/index/index?SourceID=' + app.globalData.ProgramID,
  233. IsShow: false,
  234. IsShow2: true,
  235. Category: "数学系列",
  236. },
  237. {
  238. ID: 106,
  239. Name: "识字",
  240. Name2: "课本同步汉字发言组词",
  241. ImageUrl: "product_icon_sz_70x70.png",
  242. appId: 'wx313a8f2c0741efe1',
  243. path: 'pages/index/index?SourceID=' + app.globalData.ProgramID,
  244. IsShow: true,
  245. IsShow2: true,
  246. Category: "语文系列",
  247. },
  248. {
  249. ID: 98,
  250. Name: "汉语拼音",
  251. Name2: "纯正发音练习",
  252. ImageUrl: "product_icon_py_70x70.png",
  253. appId: 'wx331e8dd070f01d0e',
  254. path: 'pages/index/index?SourceID=' + app.globalData.ProgramID,
  255. IsShow: true,
  256. IsShow2: true,
  257. Category: "语文系列",
  258. },
  259. {
  260. ID: 99,
  261. Name: "自然拼读",
  262. Name2: "真正英语国家母语学习法",
  263. ImageUrl: "product_icon_pd_70x70.png",
  264. appId: 'wxb54a6d5aff836ee3',
  265. path: 'pages/index/index?SourceID=' + app.globalData.ProgramID,
  266. IsShow: true,
  267. IsShow2: true,
  268. Category: "英语系列",
  269. },
  270. {
  271. ID: 89,
  272. Name: "数学口算练习",
  273. Name2: "帮助孩子快速提高口算能力",
  274. ImageUrl: "product_icon_kslx_70x70.png",
  275. appId: 'wx46a7b4c420e6d38f',
  276. path: 'pages/index/start?SourceID=' + app.globalData.ProgramID,
  277. IsShow: false,
  278. IsShow2: false,
  279. Category: "",
  280. },
  281. ];
  282. }
  283. function getProgramListOld() {
  284. return [
  285. {
  286. id: 164,
  287. Name:"口算星球",
  288. appId: 'wxa5441bbf344692ba',
  289. path: 'pages/index/index?SourceID=' + app.globalData.ProgramID,
  290. imageName:"universalpic_product_kousuan_icon_size01",
  291. },
  292. {
  293. id: 98,
  294. Name: "语文汉语拼音",
  295. appId: 'wx331e8dd070f01d0e',
  296. path: 'pages/index/index?SourceID=' + app.globalData.ProgramID,
  297. imageName: "universalpic_product_pinyin_icon_size01",
  298. },
  299. {
  300. id: 106,
  301. Name: "语文识字",
  302. appId: 'wx313a8f2c0741efe1',
  303. path: 'pages/index/index?SourceID=' + app.globalData.ProgramID,
  304. imageName: "universalpic_product_shizi_icon_size01",
  305. },
  306. {
  307. id: 99,
  308. Name: "英语自然拼读",
  309. appId: 'wxb54a6d5aff836ee3',
  310. path: 'pages/index/index?SourceID=' + app.globalData.ProgramID,
  311. imageName: "universalpic_product_phonics_icon_size01",
  312. },
  313. {
  314. id: 90,
  315. Name: "注意力游戏",
  316. appId: 'wxa5e33c61fe37dd01',
  317. path: 'pages/index/index?SourceID=' + app.globalData.ProgramID,
  318. imageName: "universalpic_product_zhuyili_icon_size01",
  319. },
  320. {
  321. id: 127,
  322. Name: "空间智力游戏",
  323. appId: 'wxaa1a8b48d9853872',
  324. path: 'pages/index/game?SourceID=' + app.globalData.ProgramID,
  325. imageName: "universalpic_product_kongjian_icon_size01",
  326. },
  327. ];
  328. }
  329. function gotoFeedback() {
  330. wx.navigateToMiniProgram({
  331. appId: "wx80059777521b897c",
  332. path: "pages/index/feedback",
  333. extraData: {
  334. },
  335. success(res) {
  336. // 打开成功
  337. }
  338. });
  339. }
  340. function playAudio(ctx, sentence, player) {
  341. var url = app.globalData.audioUrlBaidu;
  342. url = url.replace("[token]", app.globalData.BaiduToken);
  343. url = url.replace("[word]", sentence);
  344. if (player)
  345. url = url.replace("per=4", "per="+player);
  346. //console.log(url);
  347. ctx.setSrc(url);
  348. ctx.play();
  349. }
  350. function playSound(file){
  351. const innerAudioContext = wx.createInnerAudioContext()
  352. innerAudioContext.autoplay = true
  353. innerAudioContext.src = file
  354. innerAudioContext.onPlay(() => {
  355. //console.log('开始播放')
  356. })
  357. }
  358. module.exports = {
  359. getData: getData,
  360. postData: postData,
  361. shareGroup: shareGroup,
  362. payMoney: payMoney,
  363. getLocalHost: getLocalHost,
  364. getTimeFormat: getTimeFormat,
  365. getWindowHeight: getWindowHeight,
  366. getStorageValue: getStorageValue,
  367. getDifficulty: getDifficulty,
  368. getProgramList: getProgramList,
  369. getProgramListOld: getProgramListOld,
  370. gotoFeedback: gotoFeedback,
  371. playAudio: playAudio,
  372. playSound: playSound,
  373. }