package util

import (
	"net/http"
	"regexp"
	"strings"
)

var mobileReg = regexp.MustCompile("(?i)(Android|Mobile|Phone)")

func CheckPlatform(r *http.Request) (p string) {
	p = "PC"
	if CheckIsMobile(r) {
		if CheckWxBrowser(r) {
			p = "WX"
		} else {
			p = "APP"
		}
	}
	return
}

//判断是否是微信访问
func CheckWxBrowser(Request *http.Request) bool {
	if strings.Index(Request.UserAgent(), "MicroMessenger") > -1 || strings.Index(Request.UserAgent(), "Wechat") > -1 {
		return true
	} else {
		return false
	}
}

//是否是移动端
func CheckIsMobile(r *http.Request) bool {
	client := r.UserAgent()
	if mobileReg.MatchString(client) {
		return true
	}
	return false
}
