main.js 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394
  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: 164,
  215. Name: "口算",
  216. Name2: "透视问题刻意练习",
  217. ImageUrl: "product_icon_ksxq_70x70.png",
  218. appId: 'wxa5441bbf344692ba',
  219. path: 'pages/index/index?SourceID=' + app.globalData.ProgramID,
  220. IsShow: true,
  221. IsShow2: true,
  222. Category: "数学系列",
  223. },
  224. {
  225. ID: 105,
  226. Name: "计算题",
  227. Name2: "竖式计算打印批改",
  228. ImageUrl: "product_icon_jst_70x70.png",
  229. appId: 'wx1fef080f74481cbd',
  230. path: 'pages/index/index?SourceID=' + app.globalData.ProgramID,
  231. IsShow: false,
  232. IsShow2: true,
  233. Category: "数学系列",
  234. },
  235. {
  236. ID: 106,
  237. Name: "识字",
  238. Name2: "课本同步汉字发言组词",
  239. ImageUrl: "product_icon_sz_70x70.png",
  240. appId: 'wx313a8f2c0741efe1',
  241. path: 'pages/index/index?SourceID=' + app.globalData.ProgramID,
  242. IsShow: true,
  243. IsShow2: true,
  244. Category: "语文系列",
  245. },
  246. {
  247. ID: 98,
  248. Name: "汉语拼音",
  249. Name2: "纯正发音练习",
  250. ImageUrl: "product_icon_py_70x70.png",
  251. appId: 'wx331e8dd070f01d0e',
  252. path: 'pages/index/index?SourceID=' + app.globalData.ProgramID,
  253. IsShow: true,
  254. IsShow2: true,
  255. Category: "语文系列",
  256. },
  257. {
  258. ID: 99,
  259. Name: "自然拼读",
  260. Name2: "真正英语国家母语学习法",
  261. ImageUrl: "product_icon_pd_70x70.png",
  262. appId: 'wxb54a6d5aff836ee3',
  263. path: 'pages/index/index?SourceID=' + app.globalData.ProgramID,
  264. IsShow: true,
  265. IsShow2: true,
  266. Category: "英语系列",
  267. },
  268. {
  269. ID: 89,
  270. Name: "数学口算练习",
  271. Name2: "帮助孩子快速提高口算能力",
  272. ImageUrl: "product_icon_kslx_70x70.png",
  273. appId: 'wx46a7b4c420e6d38f',
  274. path: 'pages/index/start?SourceID=' + app.globalData.ProgramID,
  275. IsShow: false,
  276. IsShow2: false,
  277. Category: "",
  278. },
  279. ];
  280. }
  281. function getProgramListOld() {
  282. return [
  283. {
  284. id: 164,
  285. Name:"口算星球",
  286. appId: 'wxa5441bbf344692ba',
  287. path: 'pages/index/index?SourceID=' + app.globalData.ProgramID,
  288. imageName:"universalpic_product_kousuan_icon_size01",
  289. },
  290. {
  291. id: 98,
  292. Name: "语文汉语拼音",
  293. appId: 'wx331e8dd070f01d0e',
  294. path: 'pages/index/index?SourceID=' + app.globalData.ProgramID,
  295. imageName: "universalpic_product_pinyin_icon_size01",
  296. },
  297. {
  298. id: 106,
  299. Name: "语文识字",
  300. appId: 'wx313a8f2c0741efe1',
  301. path: 'pages/index/index?SourceID=' + app.globalData.ProgramID,
  302. imageName: "universalpic_product_shizi_icon_size01",
  303. },
  304. {
  305. id: 99,
  306. Name: "英语自然拼读",
  307. appId: 'wxb54a6d5aff836ee3',
  308. path: 'pages/index/index?SourceID=' + app.globalData.ProgramID,
  309. imageName: "universalpic_product_phonics_icon_size01",
  310. },
  311. {
  312. id: 90,
  313. Name: "注意力游戏",
  314. appId: 'wxa5e33c61fe37dd01',
  315. path: 'pages/index/index?SourceID=' + app.globalData.ProgramID,
  316. imageName: "universalpic_product_zhuyili_icon_size01",
  317. },
  318. {
  319. id: 127,
  320. Name: "空间智力游戏",
  321. appId: 'wxaa1a8b48d9853872',
  322. path: 'pages/index/game?SourceID=' + app.globalData.ProgramID,
  323. imageName: "universalpic_product_kongjian_icon_size01",
  324. },
  325. ];
  326. }
  327. function gotoFeedback() {
  328. wx.navigateToMiniProgram({
  329. appId: "wx80059777521b897c",
  330. path: "pages/index/feedback",
  331. extraData: {
  332. },
  333. success(res) {
  334. // 打开成功
  335. }
  336. });
  337. }
  338. function playAudio(ctx, sentence, player) {
  339. var url = app.globalData.audioUrlBaidu;
  340. url = url.replace("[token]", app.globalData.BaiduToken);
  341. url = url.replace("[word]", sentence);
  342. if (player)
  343. url = url.replace("per=4", "per="+player);
  344. //console.log(url);
  345. ctx.setSrc(url);
  346. ctx.play();
  347. }
  348. function playSound(file){
  349. const innerAudioContext = wx.createInnerAudioContext()
  350. innerAudioContext.autoplay = true
  351. innerAudioContext.src = file
  352. innerAudioContext.onPlay(() => {
  353. //console.log('开始播放')
  354. })
  355. }
  356. module.exports = {
  357. getData: getData,
  358. postData: postData,
  359. shareGroup: shareGroup,
  360. payMoney: payMoney,
  361. getLocalHost: getLocalHost,
  362. getTimeFormat: getTimeFormat,
  363. getWindowHeight: getWindowHeight,
  364. getStorageValue: getStorageValue,
  365. getDifficulty: getDifficulty,
  366. getProgramList: getProgramList,
  367. getProgramListOld: getProgramListOld,
  368. gotoFeedback: gotoFeedback,
  369. playAudio: playAudio,
  370. playSound: playSound,
  371. }