
// 微信
//1wxpay_mini微信小程序 2wxpay_jsapi  3ios 4android 6wxpay_h5
//支付宝
//3alipay_app 4alipay_app

let client = null
// #ifdef MP-WEIXIN
client = 1
// #endif

// #ifdef H5
client = isWeixinClient() ? 2 : 6
// #endif

// #ifdef APP-PLUS
client = 3;
uni.getSystemInfo({
  success: res => {
    client = res.platform == 'ios' ? 3 : 4;
  },
  fail: res => {
    client = 3
  }
})
// #endif

const payList = [{
  key: 1,
  label: '微信小程序',
  aliValue: '',
  wxValue: 'wxpay_mp'
}, {
  key: 2,
  label: '微信浏览器',
  aliValue: '',
  value: 'wxpay_jsapi'
}, {
  key: 3,
  label: 'IOS',
  aliValue: 'alipay_app',
  wxValue: 'wxpay_app'
}, {
  key: 4,
  label: '安卓',
  aliValue: 'alipay_app',
  wxValue: 'wxpay_app'
}, {
  key: 6,
  label: 'H5',
  aliValue: '',
  wxValue: 'wxpay_h5'
}]

const payWay = payList.find(e => e.key == client)

export {
  payWay,
  client
}

//判断是否为微信环境
export function isWeixinClient() {
  var ua = navigator.userAgent.toLowerCase();
  if (ua.match(/MicroMessenger/i) == "micromessenger") {
    //这是微信环境
    return true;
  } else {
    //这是非微信环境
    return false;
  }
}

//判断是否为安卓环境
export function isAndroid() {
  let u = navigator.userAgent;
  return u.indexOf('Android') > -1 || u.indexOf('Adr') > -1;
}

//获取url后的参数  以对象返回
export function strToParams(str) {
	var newparams = {}
	for (let item of str.split('&')) {
		newparams[item.split('=')[0]] = item.split('=')[1]
	}
	return newparams
}


