前端判断渠道是微信端还是支付宝

/**
 * 渠道编码
 */
export  default function channelcode  () {
  if (navigator.userAgent.toLowerCase().indexOf("alipay") != -1) {
    const channelcode = 'Alipay'
    return channelcode
  }else if(navigator.userAgent.toLowerCase().match(/MicroMessenger/i) == "micromessenger"){
    const channelcode = 'WeChat'
    return channelcode
  }
}
// 判断是否微信浏览器还是支付宝浏览器
var ua = window.navigator.userAgent.toLowerCase();
if (ua.match(/MicroMessenger/i) == 'micromessenger'){
  // console.log('微信'+ua)
  // dplus.register({"APP来源": "微信"})
} else if (ua.match(/AliApp/i) == 'aliapp') {
  // console.log('支付宝'+ua)
  // dplus.register({"APP来源": "支付宝"})
} else {
  // console.log('其他'+ua)
   // dplus.register({"APP来源": "其他"})
}
  1. 根据UserAgent中的关键字来判断 
  2. 如果有 MicroMessenger 为微信
  3. 如果有 ApliPayClient 则为支付宝
  4.  否则,不是这两家

猜你喜欢

转载自www.cnblogs.com/arealy/p/12928606.html