config.js 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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. console.table(params)
  69. params = Object.assign({}, params);
  70. getReq(params, function (res) {
  71. wx.hideLoading()
  72. if (res.code == 200) {
  73. let param = res.datas.param.data
  74. let pay_sn = res.datas.pay_sn
  75. wx.requestPayment({
  76. timeStamp: param.timeStamp, //时间戳,自1970年以来的秒数
  77. nonceStr: param.nonceStr, //随机串
  78. package: param.package,
  79. signType: param.signType, //微信签名方式:
  80. paySign: param.paySign, //微信签名
  81. success: function (res) {
  82. successCallback && successCallback(res)
  83. },
  84. fail: function (res) {
  85. // wx.redirectTo({
  86. // url: `/pages/orderPaySn/orderPaySn?pay_sn=${pay_sn}`
  87. // })
  88. wx.showToast({
  89. icon: 'none',
  90. title: '支付失败',
  91. duration: 2000
  92. })
  93. failCallback && failCallback(res)
  94. }
  95. });
  96. }
  97. else {
  98. wx.showToast({
  99. icon: 'none',
  100. title: res.message,
  101. duration: 2000
  102. })
  103. // app.globalData.fcodeErr = res.message
  104. // setTimeout(() => {
  105. // wx.navigateBack()
  106. // }, 2000);
  107. }
  108. })
  109. }
  110. module.exports = {
  111. getReq,
  112. host: api,
  113. buyVGoods:buyVGoods
  114. }