config.js 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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 header = {
  20. 'content-type': 'application/json', // 默认值
  21. 'Cookie': 'MPHPSESSID=' + session_id
  22. }
  23. if (method == 'POST') {
  24. header = {
  25. 'content-type': 'application/x-www-form-urlencoded', //数据转换成 query string
  26. 'Cookie': 'MPHPSESSID=' + session_id
  27. }
  28. }
  29. return wx.request({
  30. url: api,
  31. data,
  32. method: method || 'GET',
  33. header,
  34. success(res) {
  35. callback(res.data)
  36. },
  37. fail() {
  38. wx.showModal({
  39. confirmText: '重试',
  40. content: '网络错误',
  41. success: function (res) {
  42. if (res.confirm) {
  43. wx.reLaunch({
  44. url: "/pages/index/index"
  45. })
  46. } else if (res.cancel) {
  47. console.log('用户点击取消')
  48. }
  49. }
  50. })
  51. }
  52. })
  53. }
  54. function buyVGoods(goods_id,goods_num, other, successCallback, failCallback)
  55. {
  56. let ifcart = 0 ;
  57. let cartids = goods_id + '|' + goods_num;
  58. let params = {
  59. act: 'member_buy',
  60. op: 'step_vsecond',
  61. payment: 'minipay',
  62. usebonus: 0,
  63. ifcart : 0,
  64. cart_id: cartids,
  65. invoice_id: 0,
  66. ...other
  67. }
  68. params = Object.assign({}, params);
  69. getReq(params, function (res) {
  70. wx.hideLoading()
  71. if (res.code == 200) {
  72. let param = res.datas.param.data
  73. let pay_sn = res.datas.pay_sn
  74. wx.requestPayment({
  75. timeStamp: param.timeStamp, //时间戳,自1970年以来的秒数
  76. nonceStr: param.nonceStr, //随机串
  77. package: param.package,
  78. signType: param.signType, //微信签名方式:
  79. paySign: param.paySign, //微信签名
  80. success: function (res) {
  81. successCallback && successCallback(res)
  82. },
  83. fail: function (res) {
  84. // wx.redirectTo({
  85. // url: `/pages/orderPaySn/orderPaySn?pay_sn=${pay_sn}`
  86. // })
  87. wx.showToast({
  88. icon: 'none',
  89. title: '支付失败',
  90. duration: 2000
  91. })
  92. failCallback && failCallback(res)
  93. }
  94. });
  95. }
  96. else {
  97. wx.showToast({
  98. icon: 'none',
  99. title: res.message,
  100. duration: 2000
  101. })
  102. app.globalData.fcodeErr = res.message
  103. setTimeout(() => {
  104. wx.navigateBack()
  105. }, 2000);
  106. }
  107. })
  108. }
  109. module.exports = {
  110. getReq,
  111. host: api,
  112. buyVGoods:buyVGoods
  113. }