config.js 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  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. console.log(res)
  48. if (res.data.code == 10014) { //ErrUnLogin = 10014;
  49. wx.removeStorage('session_id');
  50. wx.navigateTo({
  51. url: '/pages/auth/auth',
  52. })
  53. }
  54. else {
  55. callback(res.data)
  56. }
  57. },
  58. fail()
  59. {
  60. wx.showModal({
  61. confirmText: '重试',
  62. content: '网络错误',
  63. success: function (res) {
  64. if (res.confirm) {
  65. wx.reLaunch({
  66. url: "/pages/index/index"
  67. })
  68. }
  69. else if (res.cancel) {
  70. console.log('用户点击取消')
  71. }
  72. }
  73. })
  74. }
  75. })
  76. }
  77. function buyVGoods(app,goods_id,goods_num, other, successCallback, failCallback)
  78. {
  79. let ifcart = 0 ;
  80. let cartids = goods_id + '|' + goods_num;
  81. let params = {
  82. act: 'member_buy',
  83. op: 'step_vsecond',
  84. payment: 'minipay',
  85. usebonus: 0,
  86. ifcart : 0,
  87. cart_id: cartids,
  88. invoice_id: 0,
  89. ...other
  90. }
  91. console.table(params)
  92. params = Object.assign({}, params);
  93. getReq(app,params, function (res) {
  94. wx.hideLoading()
  95. if (res.code == 200) {
  96. let param = res.datas.param.data
  97. let pay_sn = res.datas.pay_sn
  98. wx.requestPayment({
  99. timeStamp: param.timeStamp, //时间戳,自1970年以来的秒数
  100. nonceStr: param.nonceStr, //随机串
  101. package: param.package,
  102. signType: param.signType, //微信签名方式:
  103. paySign: param.paySign, //微信签名
  104. success: function (res) {
  105. successCallback && successCallback(res)
  106. },
  107. fail: function (res) {
  108. wx.showToast({
  109. icon: 'none',
  110. title: '支付失败',
  111. duration: 2000
  112. })
  113. failCallback && failCallback(res)
  114. }
  115. });
  116. }
  117. else {
  118. wx.showToast({
  119. icon: 'none',
  120. title: res.message,
  121. duration: 2000
  122. })
  123. }
  124. })
  125. }
  126. function payOrder(app, pay_sn) {
  127. let params = {
  128. act: 'member_order',
  129. op: 'pay',
  130. pay_sn: pay_sn,
  131. payment: 'minipay'
  132. }
  133. getReq(app, params, function (res) {
  134. if (res.code == 200) {
  135. let param = res.datas.param.data;
  136. wx.requestPayment({
  137. timeStamp: param.timeStamp, //时间戳,自1970年以来的秒数
  138. nonceStr: param.nonceStr, //随机串
  139. package: param.package,
  140. signType: param.signType, //微信签名方式:
  141. paySign: param.paySign, //微信签名
  142. success: function (res) {
  143. wx.redirectTo({
  144. url: "/pages/order_tabs/orderTabs?state_type=state_pay"
  145. })
  146. console.log("支付成功:", res);
  147. },
  148. fail: function (res) {
  149. setTimeout(() => {
  150. wx.showToast({
  151. icon: 'none',
  152. title: res.errMsg,
  153. duration: 2000
  154. })
  155. }, 200);
  156. console.log("失败:", res);
  157. }
  158. });
  159. }
  160. })
  161. }
  162. module.exports = {
  163. getReq: getReq,
  164. host: api,
  165. buyVGoods: buyVGoods,
  166. payOrder: payOrder
  167. }