PHP代码

if ( strpos($_SERVER['HTTP_USER_AGENT'], 'MicroMessenger') !== false ) {
        return ‘WeiXin’;
}
//判断是不是支付宝
if (strpos($_SERVER['HTTP_USER_AGENT'], 'AlipayClient') !== false) {
        return "AliPay";
}

JS判断

function WxOrAli(){
    var ua = window.navigator.userAgent.toLowerCase();
    //判断是不是微信
    if ( ua.match(/MicroMessenger/i) == 'micromessenger' ) {  
        return "WeiXIN";  
    }    
    //判断是不是支付宝
    if (ua.match(/AlipayClient/i) == 'alipayclient') {
        return "Alipay";  
    }
    //哪个都不是
    return "false";
}