config.js 2.8 KB

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