main.js 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311
  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, money, callback) {
  96. console.log(money);
  97. //登录认证
  98. wx.login({
  99. success: function (res) {
  100. if (res.code) {
  101. console.log('获取用户登录态成功!' + res.code);
  102. //预支付
  103. getData('PayLogin?code=' + res.code + '&payType=' + payType + '&money=' + money, function (data) {
  104. if (data && data.timeStamp) {
  105. //微信支付
  106. wx.requestPayment({
  107. 'timeStamp': data.timeStamp.toString(),
  108. 'nonceStr': data.nonceStr,
  109. 'package': data.package,
  110. 'signType': 'MD5',
  111. 'paySign': data.paySign,
  112. 'success': function (res3) {
  113. console.log("success:" + res3);
  114. callback();
  115. },
  116. 'fail': function (err) {
  117. if (err && err.errMsg && err.errMsg.indexOf("fail cancel")) {
  118. }
  119. else {
  120. wx.showToast({
  121. title: '服务器忙,请稍候再试!',
  122. duration: 3000
  123. });
  124. wx.redirectTo({
  125. url: './error',
  126. });
  127. }
  128. }
  129. });
  130. }
  131. });
  132. } else {
  133. console.log('获取用户登录态失败!' + res.errMsg);
  134. }
  135. }
  136. });
  137. }
  138. function downloadImage(scoreID) {
  139. wx.showLoading({
  140. title: '下载中_然后长按保存',
  141. });
  142. var that = this;
  143. getData('MakeSchulteShare?ScoreID=' + scoreID, function (data) {
  144. setTimeout(function () {
  145. wx.downloadFile({
  146. url: "https://schulte-1253256735.file.myqcloud.com/share" + scoreID + ".jpg",
  147. success: function (res) {
  148. wx.hideLoading();
  149. wx.previewImage({
  150. current: res.tempFilePath, // 当前显示图片的http链接
  151. urls: [res.tempFilePath] // 需要预览的图片http链接列表
  152. })
  153. },
  154. fail: function () {
  155. wx.hideLoading();
  156. getData('MakeSchulteShare?ScoreID=' + scoreID, function (data) { });
  157. wx.showToast({
  158. title: '请稍候再试!',
  159. duration: 2000
  160. });
  161. }
  162. });
  163. }, 2000);
  164. });
  165. }
  166. function getTimeFormat(duration) {
  167. //console.log("duration:" + duration);
  168. var arr = ['', '', '']
  169. if (duration.indexOf("'") > 0)
  170. arr[0] = duration.substring(0, duration.indexOf("'"));
  171. if (duration.indexOf(".") > 0) {
  172. arr[1] = duration.substring(duration.indexOf("'") + 1, duration.indexOf(".") + 1);
  173. arr[2] = duration.substring(duration.indexOf(".") + 1, duration.indexOf('"'));
  174. }
  175. else {
  176. arr[1] = duration.substring(duration.indexOf("'") + 1, duration.indexOf('"'));
  177. }
  178. return arr;
  179. }
  180. function getWindowHeight() {
  181. var height = app.globalData.systemInfo.windowHeight;
  182. //console.log("app.globalData.systemInfo.windowHeight:" + app.globalData.systemInfo.windowHeight * 2);
  183. if (app.globalData.systemInfo.model) {
  184. if (height == 504 && (
  185. app.globalData.systemInfo.model.indexOf("iPhone 6<") >= 0
  186. || app.globalData.systemInfo.model.indexOf("iPhone 7<") >= 0
  187. || app.globalData.systemInfo.model.indexOf("iPhone 6s<") >= 0
  188. || app.globalData.systemInfo.model.indexOf("iPhone 5") >= 0
  189. || app.globalData.systemInfo.model.indexOf("iPhone SE") >= 0
  190. )) {
  191. height = 596;
  192. }
  193. }
  194. height = height * 2;
  195. if (app.globalData.systemInfo.system && app.globalData.systemInfo.system.indexOf("Android") >= 0) {
  196. height = height + 168;
  197. }
  198. else {
  199. height = height + 50;
  200. }
  201. //console.log("height:" + height);
  202. return height;
  203. }
  204. //获取存储数据,若不存在,则获得缺省值。
  205. function getStorageValue(obj, name, defaultStatus, callback) {
  206. wx.getStorage({
  207. key: name,
  208. success: function (res) {
  209. obj.data[name] = res.data;
  210. obj.setData(obj.data);
  211. callback();
  212. },
  213. fail: function (res) {
  214. obj.data[name] = defaultStatus;
  215. obj.setData(obj.data);
  216. callback();
  217. },
  218. });
  219. }
  220. function getDifficulty(num) {
  221. switch (Number(num)) {
  222. case 3:
  223. case 4:
  224. case 5:
  225. return "EASY";
  226. case 6:
  227. case 7:
  228. return "HARD";
  229. case 8:
  230. case 9:
  231. return "SUPER";
  232. }
  233. }
  234. function getProgramList() {
  235. return [
  236. {
  237. id: 89,
  238. appId: 'wx46a7b4c420e6d38f',
  239. path: 'pages/index/start?SourceID=' + app.globalData.ProgramID,
  240. },
  241. {
  242. id: 98,
  243. appId: 'wx331e8dd070f01d0e',
  244. path: 'pages/index/index?SourceID=' + app.globalData.ProgramID,
  245. },
  246. {
  247. id: 99,
  248. appId: 'wxb54a6d5aff836ee3',
  249. path: 'pages/index/index?SourceID=' + app.globalData.ProgramID,
  250. },
  251. {
  252. id: 106,
  253. appId: 'wx313a8f2c0741efe1',
  254. path: 'pages/index/index?SourceID=' + app.globalData.ProgramID,
  255. },
  256. {
  257. id: 90,
  258. appId: 'wxa5e33c61fe37dd01',
  259. path: 'pages/index/index?SourceID=' + app.globalData.ProgramID,
  260. },
  261. ];
  262. }
  263. function gotoFeedback() {
  264. wx.navigateToMiniProgram({
  265. appId: "wx80059777521b897c",
  266. path: "pages/index/feedback",
  267. extraData: {
  268. },
  269. success(res) {
  270. // 打开成功
  271. }
  272. });
  273. }
  274. module.exports = {
  275. getData: getData,
  276. postData: postData,
  277. shareGroup: shareGroup,
  278. payMoney: payMoney,
  279. downloadImage: downloadImage,
  280. getLocalHost: getLocalHost,
  281. getTimeFormat: getTimeFormat,
  282. getWindowHeight: getWindowHeight,
  283. getStorageValue: getStorageValue,
  284. getDifficulty: getDifficulty,
  285. getProgramList: getProgramList,
  286. gotoFeedback: gotoFeedback,
  287. }