main.js 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279
  1. import common from './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.showToast({
  17. title: '网络故障,请稍候再试!',
  18. duration: 3000
  19. });
  20. },
  21. });
  22. }
  23. function postData(url, postData, callback) {
  24. var url = common.Encrypt(url);
  25. //console.log("加密后的结果为===",url);
  26. wx.request({
  27. url: app.globalData.serverUrl + url,
  28. method: "POST",
  29. data: postData,
  30. success: function (res) {
  31. if (res.statusCode)
  32. common.checkError(res.statusCode);
  33. var data = res.data.result;
  34. callback(data);
  35. },
  36. fail: function () {
  37. wx.showToast({
  38. title: '网络故障,请稍候再试!',
  39. duration: 3000
  40. });
  41. },
  42. });
  43. }
  44. function getLocalHost(callback) {
  45. if (!app.globalData.IsProduction) {
  46. var url = common.Encrypt("Ping");
  47. wx.request({
  48. url: app.globalData.serverUrlLocalhost + url,
  49. success: function (res) {
  50. app.globalData.serverUrl = app.globalData.serverUrlLocalhost;
  51. callback();
  52. },
  53. fail: function () {
  54. app.globalData.serverUrl = app.globalData.serverUrlServer;
  55. callback();
  56. },
  57. });
  58. }
  59. else {
  60. app.globalData.serverUrl = app.globalData.serverUrlServer;
  61. callback();
  62. }
  63. }
  64. function payMoney(payType, buyType, money, detail, callback) {
  65. console.log(money);
  66. if (app.globalData.userInfo.UserID == 1)
  67. money = 0.01;
  68. else if (app.globalData.userInfo.UserID == 5)
  69. money = 0.01;
  70. //登录认证
  71. wx.login({
  72. success: function (res) {
  73. if (res.code) {
  74. console.log('获取用户登录态成功!' + res.code);
  75. //预支付
  76. getData('ProductPayLogin500?code=' + res.code + '&payType=' + payType + '&buyType=' + buyType + '&money=' + money + '&detail=' + detail + '&productID=' + app.globalData.ProgramID, function (data) {
  77. if (data && data.timeStamp) {
  78. //微信支付
  79. wx.requestPayment({
  80. 'timeStamp': data.timeStamp.toString(),
  81. 'nonceStr': data.nonceStr,
  82. 'package': data.package,
  83. 'signType': 'MD5',
  84. 'paySign': data.paySign,
  85. 'success': function (res3) {
  86. console.log("success:" + res3);
  87. callback(data);
  88. },
  89. 'fail': function (err) {
  90. if (err && err.errMsg && err.errMsg.indexOf("fail cancel")) {
  91. }
  92. else {
  93. wx.showToast({
  94. title: '服务器忙,请稍候再试!',
  95. duration: 3000
  96. });
  97. }
  98. }
  99. });
  100. }
  101. });
  102. } else {
  103. console.log('获取用户登录态失败!' + res.errMsg);
  104. wx.showToast({
  105. title: '服务器忙,请稍候再试!',
  106. duration: 3000
  107. });
  108. }
  109. }
  110. });
  111. }
  112. function getProgramList() {
  113. return [
  114. {
  115. ID: 166,
  116. Name: "秒过学习",
  117. Name2: "家长帮助孩子快速提高学习成绩",
  118. ImageUrl: "product_icon_mg_70x70.png",
  119. appId: 'wx84b3feac6069eec3',
  120. path: 'pages/index/index?SourceID=' + app.globalData.ProgramID,
  121. IsShow: true,
  122. IsShow2: true,
  123. Category: "",
  124. },
  125. {
  126. ID: 164,
  127. Name: "口算",
  128. Name2: "透视问题刻意练习",
  129. ImageUrl: "product_icon_ksxq_70x70.png",
  130. appId: 'wxa5441bbf344692ba',
  131. path: 'pages/index/index?SourceID=' + app.globalData.ProgramID,
  132. IsShow: true,
  133. IsShow2: true,
  134. Category: "数学系列",
  135. },
  136. {
  137. ID: 105,
  138. Name: "计算题",
  139. Name2: "竖式计算打印批改",
  140. ImageUrl: "product_icon_jst_70x70.png",
  141. appId: 'wx1fef080f74481cbd',
  142. path: 'pages/index/index?SourceID=' + app.globalData.ProgramID,
  143. IsShow: true,
  144. IsShow2: true,
  145. Category: "数学系列",
  146. },
  147. {
  148. ID: 106,
  149. Name: "识字",
  150. Name2: "课本同步汉字发言组词",
  151. ImageUrl: "product_icon_sz_70x70.png",
  152. appId: 'wx313a8f2c0741efe1',
  153. path: 'pages/index/index?SourceID=' + app.globalData.ProgramID,
  154. IsShow: false,
  155. IsShow2: true,
  156. Category: "语文系列",
  157. },
  158. {
  159. ID: 98,
  160. Name: "汉语拼音",
  161. Name2: "纯正发音练习",
  162. ImageUrl: "product_icon_py_70x70.png",
  163. appId: 'wx331e8dd070f01d0e',
  164. path: 'pages/index/index?SourceID=' + app.globalData.ProgramID,
  165. IsShow: true,
  166. IsShow2: true,
  167. Category: "语文系列",
  168. },
  169. {
  170. ID: 99,
  171. Name: "自然拼读",
  172. Name2: "真正英语国家母语学习法",
  173. ImageUrl: "product_icon_pd_70x70.png",
  174. appId: 'wxb54a6d5aff836ee3',
  175. path: 'pages/index/index?SourceID=' + app.globalData.ProgramID,
  176. IsShow: true,
  177. IsShow2: true,
  178. Category: "英语系列",
  179. },
  180. {
  181. ID: 89,
  182. Name: "数学口算练习",
  183. Name2: "帮助孩子快速提高口算能力",
  184. ImageUrl: "product_icon_kslx_70x70.png",
  185. appId: 'wx46a7b4c420e6d38f',
  186. path: 'pages/index/start?SourceID=' + app.globalData.ProgramID,
  187. IsShow: false,
  188. IsShow2: false,
  189. Category: "",
  190. },
  191. ];
  192. }
  193. function getProgramListOld() {
  194. var list = [
  195. {
  196. ID: 166,
  197. ImageUrl: "10001.png",
  198. appId: 'wx84b3feac6069eec3',
  199. path: 'pages/index/index?SourceID=' + app.globalData.ProgramID,
  200. },
  201. {
  202. ID: 164,
  203. ImageUrl: "03001.png",
  204. ImageUrl2: "02018.png",
  205. appId: 'wxa5441bbf344692ba',
  206. path: 'pages/index/index?SourceID=' + app.globalData.ProgramID,
  207. },
  208. {
  209. ID: 105,
  210. ImageUrl: "03005.png",
  211. ImageUrl2: "02033.png",
  212. appId: 'wx1fef080f74481cbd',
  213. path: 'pages/index/index?SourceID=' + app.globalData.ProgramID,
  214. },
  215. {
  216. ID: 99,
  217. ImageUrl: "03002.png",
  218. ImageUrl2: "02020.png",
  219. appId: 'wxb54a6d5aff836ee3',
  220. path: 'pages/index/index?SourceID=' + app.globalData.ProgramID,
  221. },
  222. {
  223. ID: 98,
  224. ImageUrl: "03003.png",
  225. ImageUrl2: "02019.png",
  226. appId: 'wx331e8dd070f01d0e',
  227. path: 'pages/index/index?SourceID=' + app.globalData.ProgramID,
  228. },
  229. {
  230. ID: 90,
  231. ImageUrl: "03004.png",
  232. ImageUrl2: "02021.png",
  233. appId: 'wxa5e33c61fe37dd01',
  234. path: 'pages/index/index?SourceID=' + app.globalData.ProgramID,
  235. },
  236. {
  237. ID: 127,
  238. ImageUrl2: "02034.png",
  239. appId: 'wxaa1a8b48d9853872',
  240. path: 'pages/index/game?SourceID=' + app.globalData.ProgramID,
  241. },
  242. ];
  243. return list;
  244. }
  245. function gotoFeedback(){
  246. wx.navigateToMiniProgram({
  247. appId: "wx80059777521b897c",
  248. path: "pages/index/feedback",
  249. extraData: {
  250. },
  251. success(res) {
  252. // 打开成功
  253. }
  254. });
  255. }
  256. module.exports = {
  257. getData: getData,
  258. postData: postData,
  259. payMoney: payMoney,
  260. getLocalHost: getLocalHost,
  261. getProgramList: getProgramList,
  262. getProgramListOld: getProgramListOld,
  263. gotoFeedback: gotoFeedback,
  264. }