|
|
package umeng
|
|
|
|
|
|
const (
|
|
|
Android = iota + 1
|
|
|
IPhone
|
|
|
IPad
|
|
|
)
|
|
|
const (
|
|
|
ProjectDefault = "default"
|
|
|
)
|
|
|
|
|
|
var UMAppAuths UMAppAuth
|
|
|
|
|
|
func init() {
|
|
|
UMAppAuths = map[string]*AppAuth{
|
|
|
ProjectDefault: NewAppAuth(ProjectDefault).
|
|
|
AddAuth(Android, Auth{}).
|
|
|
AddAuth(IPhone, Auth{}),
|
|
|
}
|
|
|
}
|
|
|
|
|
|
type UMAppAuth map[string]*AppAuth
|
|
|
|
|
|
func (a UMAppAuth) DefaultAppAuth() *AppAuth {
|
|
|
return a.GetAppAuth(ProjectDefault)
|
|
|
}
|
|
|
func (a UMAppAuth) GetAppAuth(appName string) *AppAuth {
|
|
|
if auth, ok := a[appName]; ok {
|
|
|
return auth
|
|
|
}
|
|
|
return nil
|
|
|
}
|
|
|
|
|
|
type AppAuth struct {
|
|
|
AppName string //app名称
|
|
|
AppAuthMap map[int]Auth //android ios ipad
|
|
|
}
|
|
|
|
|
|
//新建
|
|
|
func NewAppAuth(appName string) *AppAuth {
|
|
|
return &AppAuth{
|
|
|
AppName: appName,
|
|
|
AppAuthMap: make(map[int]Auth),
|
|
|
}
|
|
|
}
|
|
|
|
|
|
//添加凭证
|
|
|
func (a *AppAuth) AddAuth(t int, auth Auth) *AppAuth {
|
|
|
if _, ok := a.AppAuthMap[t]; !ok {
|
|
|
a.AppAuthMap[t] = auth
|
|
|
}
|
|
|
return a
|
|
|
}
|
|
|
|
|
|
//凭证
|
|
|
type Auth struct {
|
|
|
AppKey string //应用唯一标识
|
|
|
AppMasterSecret string //服务器秘钥,用于服务器端调用API请求时对发送内容做签名验证
|
|
|
} |
...
|
...
|
|