config.js 4.3 KB

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