config.js 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  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 api = "http://www.xyzshops.cn/mobile/index.php";
  6. function getReq(app,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 (!app.globalData.fMinistart && data['op'] != 'ministart') {
  14. setTimeout(() => {
  15. getReq(app,data, callback, method)
  16. }, 0);
  17. return;
  18. }
  19. let act = data['act'];
  20. if(act.indexOf('member_') == 0)
  21. {
  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('header:', res.header["Set-Cookie"])
  48. var cookies = res.header["Set-Cookie"];
  49. if (cookies) {
  50. var cookie = getCookieValue(cookies, 'MPHPSESSID');
  51. if(cookie) wx.setStorageSync('session_id', cookie);
  52. }
  53. if (res.data.code == 10014) { //ErrUnLogin = 10014;
  54. wx.navigateTo({
  55. url: '/pages/auth/auth',
  56. })
  57. }
  58. else {
  59. callback(res.data)
  60. }
  61. },
  62. fail()
  63. {
  64. wx.showModal({
  65. confirmText: '重试',
  66. content: '网络错误',
  67. success: function (res) {
  68. if (res.confirm) {
  69. wx.reLaunch({
  70. url: "/pages/index/index"
  71. })
  72. }
  73. else if (res.cancel) {
  74. console.log('用户点击取消')
  75. }
  76. }
  77. })
  78. }
  79. })
  80. }
  81. function getCookieValue(cookies,name) {
  82. var cookie_pos = cookies.indexOf(name,0);
  83. if (cookie_pos != -1) {
  84. cookie_pos += name.length + 1;
  85. var cookie_end = cookies.indexOf(";", cookie_pos);
  86. if (cookie_end == -1) {
  87. cookie_end = cookies.length;
  88. }
  89. var value = unescape(cookies.substring(cookie_pos, cookie_end));
  90. return value;
  91. } else {
  92. return '';
  93. }
  94. }
  95. function buyVGoods(app,goods_id,goods_num, other, successCallback, failCallback)
  96. {
  97. let ifcart = 0 ;
  98. let cartids = goods_id + '|' + goods_num;
  99. let params = {
  100. act: 'member_buy',
  101. op: 'step_vsecond',
  102. payment: 'minipay',
  103. usebonus: 0,
  104. ifcart : 0,
  105. cart_id: cartids,
  106. invoice_id: 0,
  107. ...other
  108. }
  109. console.table(params)
  110. wx.showLoading({
  111. title: '加载中',
  112. mask: true
  113. });
  114. params = Object.assign({}, params);
  115. getReq(app,params, function (res) {
  116. wx.hideLoading()
  117. if (res.code == 200) {
  118. let param = res.datas.param.data
  119. let pay_sn = res.datas.pay_sn
  120. wx.requestPayment({
  121. timeStamp: param.timeStamp, //时间戳,自1970年以来的秒数
  122. nonceStr: param.nonceStr, //随机串
  123. package: param.package,
  124. signType: param.signType, //微信签名方式:
  125. paySign: param.paySign, //微信签名
  126. success: function (res) {
  127. wx.hideLoading()
  128. successCallback && successCallback(res)
  129. },
  130. fail: function (res) {
  131. wx.showToast({
  132. icon: 'none',
  133. title: '支付失败',
  134. duration: 2000
  135. })
  136. failCallback && failCallback(res)
  137. }
  138. });
  139. }
  140. else {
  141. wx.showToast({
  142. icon: 'none',
  143. title: '支付未完成,订单将在10分钟后取消...',
  144. duration: 2000
  145. })
  146. }
  147. })
  148. }
  149. function payOrder(app, pay_sn) {
  150. let params = {
  151. act: 'member_order',
  152. op: 'pay',
  153. pay_sn: pay_sn,
  154. payment: 'minipay'
  155. }
  156. getReq(app, params, function (res) {
  157. if (res.code == 200) {
  158. let param = res.datas.param.data;
  159. wx.requestPayment({
  160. timeStamp: param.timeStamp, //时间戳,自1970年以来的秒数
  161. nonceStr: param.nonceStr, //随机串
  162. package: param.package,
  163. signType: param.signType, //微信签名方式:
  164. paySign: param.paySign, //微信签名
  165. success: function (res) {
  166. wx.redirectTo({
  167. url: "/pages/order_tabs/orderTabs?state_type=state_pay"
  168. })
  169. console.log("支付成功:", res);
  170. },
  171. fail: function (res) {
  172. setTimeout(() => {
  173. wx.showToast({
  174. icon: 'none',
  175. title: '支付未完成,订单将在10分钟后取消...',
  176. duration: 2000
  177. })
  178. }, 200);
  179. console.log("失败:", res);
  180. }
  181. });
  182. }
  183. })
  184. }
  185. module.exports = {
  186. getReq: getReq,
  187. host: api,
  188. buyVGoods: buyVGoods,
  189. payOrder: payOrder
  190. }