main.js 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  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.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 payMoney(payType, money, callback) {
  67. console.log(money);
  68. if (app.globalData.userInfo.UserID == 1)
  69. money = 0.01;
  70. //登录认证
  71. wx.login({
  72. success: function (res) {
  73. if (res.code) {
  74. console.log('获取用户登录态成功!' + res.code);
  75. //预支付
  76. getData('HanziPayLogin?code=' + res.code + '&payType=' + payType + '&money=' + money, 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. app.globalData.userInfo.IsMember = 1;
  87. app.globalData.userInfo.IsPay = 1;
  88. console.log("success:" + res3);
  89. callback();
  90. },
  91. 'fail': function (err) {
  92. if (err && err.errMsg && err.errMsg.indexOf("fail cancel")) {
  93. }
  94. else {
  95. wx.showToast({
  96. title: '服务器忙,请稍候再试!',
  97. duration: 3000
  98. });
  99. }
  100. }
  101. });
  102. }
  103. });
  104. } else {
  105. console.log('获取用户登录态失败!' + res.errMsg);
  106. wx.showToast({
  107. title: '服务器忙,请稍候再试!',
  108. duration: 3000
  109. });
  110. }
  111. }
  112. });
  113. }
  114. function getProgramList(){
  115. return [
  116. {
  117. ImageUrl: "03001.png",
  118. ImageUrl2: "02018.png",
  119. appId: 'wx46a7b4c420e6d38f',
  120. path: 'pages/index/start?SourceID=' + app.globalData.ProgramID,
  121. left: 117,
  122. top: 837,
  123. },
  124. {
  125. ImageUrl: "03002.png",
  126. ImageUrl2: "02020.png",
  127. appId: 'wxb54a6d5aff836ee3',
  128. path: 'pages/index/index?SourceID=' + app.globalData.ProgramID,
  129. left: 117,
  130. top: 1181,
  131. },
  132. {
  133. ImageUrl: "03003.png",
  134. ImageUrl2: "02019.png",
  135. appId: 'wx331e8dd070f01d0e',
  136. path: 'pages/index/index?SourceID=' + app.globalData.ProgramID,
  137. left: 425,
  138. top: 837,
  139. },
  140. {
  141. ImageUrl: "03004.png",
  142. ImageUrl2: "02021.png",
  143. appId: 'wxa5e33c61fe37dd01',
  144. path: 'pages/index/index?SourceID=' + app.globalData.ProgramID,
  145. left: 117,
  146. top: 1525,
  147. },
  148. ];
  149. }
  150. module.exports = {
  151. getData: getData,
  152. postData: postData,
  153. payMoney: payMoney,
  154. getLocalHost: getLocalHost,
  155. getProgramList: getProgramList,
  156. }