config.js 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. // let api = "https://passport.lrlz.com/mobile/index.php";
  2. // let api = "http://www.xyzshops.cn/mobile/index.php";
  3. // let api = "http://192.168.1.200/mobile/index.php";
  4. let api = "https://www.xyzshops.cn/mobile/index.php";
  5. let app = getApp();
  6. function getReq(data, callback, method)
  7. {
  8. let options = {
  9. client_type: 'mini'
  10. }
  11. data = Object.assign({}, options, data);
  12. let session_id = wx.getStorageSync('session_id');
  13. if (!session_id && data['op'] != 'ministart') {
  14. setTimeout(() => {
  15. getReq(data, callback, method)
  16. }, 0);
  17. return;
  18. }
  19. let act = data['act'];
  20. if(act.indexOf('member_') == 0)
  21. {
  22. console.log(act + ' must check login status.')
  23. // wx.navigateTo({
  24. // url: '/pages/auth/auth',
  25. // })
  26. // if(!app.globalData.userInfo) {
  27. // wx.navigateTo({
  28. // url: '/pages/auth/auth',
  29. // })
  30. // }
  31. }
  32. else {
  33. console.log('act = ' + act);
  34. }
  35. let header = {
  36. 'content-type': 'application/json', // 默认值
  37. 'Cookie': 'MPHPSESSID=' + session_id
  38. }
  39. if (method == 'POST') {
  40. header = {
  41. 'content-type': 'application/x-www-form-urlencoded', //数据转换成 query string
  42. 'Cookie': 'MPHPSESSID=' + session_id
  43. }
  44. }
  45. //const ErrUnLogin = 10014;
  46. return wx.request({
  47. url: api,
  48. data,
  49. method: method || 'GET',
  50. header,
  51. success(res)
  52. {
  53. callback(res.data)
  54. // if(res.data.code == 10014) {
  55. // wx.navigateTo({
  56. // url: '/pages/auth/auth',
  57. // })
  58. // }
  59. // else {
  60. // callback(res.data)
  61. // }
  62. },
  63. fail()
  64. {
  65. wx.showModal({
  66. confirmText: '重试',
  67. content: '网络错误',
  68. success: function (res) {
  69. if (res.confirm) {
  70. wx.reLaunch({
  71. url: "/pages/index/index"
  72. })
  73. } else if (res.cancel) {
  74. console.log('用户点击取消')
  75. }
  76. }
  77. })
  78. }
  79. })
  80. }
  81. function buyVGoods(goods_id,goods_num, other, successCallback, failCallback)
  82. {
  83. let ifcart = 0 ;
  84. let cartids = goods_id + '|' + goods_num;
  85. let params = {
  86. act: 'member_buy',
  87. op: 'step_vsecond',
  88. payment: 'minipay',
  89. usebonus: 0,
  90. ifcart : 0,
  91. cart_id: cartids,
  92. invoice_id: 0,
  93. ...other
  94. }
  95. console.table(params)
  96. params = Object.assign({}, params);
  97. getReq(params, function (res) {
  98. wx.hideLoading()
  99. if (res.code == 200) {
  100. let param = res.datas.param.data
  101. let pay_sn = res.datas.pay_sn
  102. wx.requestPayment({
  103. timeStamp: param.timeStamp, //时间戳,自1970年以来的秒数
  104. nonceStr: param.nonceStr, //随机串
  105. package: param.package,
  106. signType: param.signType, //微信签名方式:
  107. paySign: param.paySign, //微信签名
  108. success: function (res) {
  109. successCallback && successCallback(res)
  110. },
  111. fail: function (res) {
  112. // wx.redirectTo({
  113. // url: `/pages/orderPaySn/orderPaySn?pay_sn=${pay_sn}`
  114. // })
  115. wx.showToast({
  116. icon: 'none',
  117. title: '支付失败',
  118. duration: 2000
  119. })
  120. failCallback && failCallback(res)
  121. }
  122. });
  123. }
  124. else {
  125. wx.showToast({
  126. icon: 'none',
  127. title: res.message,
  128. duration: 2000
  129. })
  130. // app.globalData.fcodeErr = res.message
  131. // setTimeout(() => {
  132. // wx.navigateBack()
  133. // }, 2000);
  134. }
  135. })
  136. }
  137. module.exports = {
  138. getReq,
  139. host: api,
  140. buyVGoods:buyVGoods
  141. }