config.js 2.6 KB

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