正在显示
2 个修改的文件
包含
60 行增加
和
0 行删除
internal/push/umeng/const.go
0 → 100644
| 1 | +package umeng | ||
| 2 | + | ||
| 3 | +const ( | ||
| 4 | + Android = iota + 1 | ||
| 5 | + IPhone | ||
| 6 | + IPad | ||
| 7 | +) | ||
| 8 | +const ( | ||
| 9 | + ProjectDefault = "default" | ||
| 10 | +) | ||
| 11 | + | ||
| 12 | +var UMAppAuths UMAppAuth | ||
| 13 | + | ||
| 14 | +func init() { | ||
| 15 | + UMAppAuths = map[string]*AppAuth{ | ||
| 16 | + ProjectDefault: NewAppAuth(ProjectDefault). | ||
| 17 | + AddAuth(Android, Auth{}). | ||
| 18 | + AddAuth(IPhone, Auth{}), | ||
| 19 | + } | ||
| 20 | +} | ||
| 21 | + | ||
| 22 | +type UMAppAuth map[string]*AppAuth | ||
| 23 | + | ||
| 24 | +func (a UMAppAuth) DefaultAppAuth() *AppAuth { | ||
| 25 | + return a.GetAppAuth(ProjectDefault) | ||
| 26 | +} | ||
| 27 | +func (a UMAppAuth) GetAppAuth(appName string) *AppAuth { | ||
| 28 | + if auth, ok := a[appName]; ok { | ||
| 29 | + return auth | ||
| 30 | + } | ||
| 31 | + return nil | ||
| 32 | +} | ||
| 33 | + | ||
| 34 | +type AppAuth struct { | ||
| 35 | + AppName string //app名称 | ||
| 36 | + AppAuthMap map[int]Auth //android ios ipad | ||
| 37 | +} | ||
| 38 | + | ||
| 39 | +//新建 | ||
| 40 | +func NewAppAuth(appName string) *AppAuth { | ||
| 41 | + return &AppAuth{ | ||
| 42 | + AppName: appName, | ||
| 43 | + AppAuthMap: make(map[int]Auth), | ||
| 44 | + } | ||
| 45 | +} | ||
| 46 | + | ||
| 47 | +//添加凭证 | ||
| 48 | +func (a *AppAuth) AddAuth(t int, auth Auth) *AppAuth { | ||
| 49 | + if _, ok := a.AppAuthMap[t]; !ok { | ||
| 50 | + a.AppAuthMap[t] = auth | ||
| 51 | + } | ||
| 52 | + return a | ||
| 53 | +} | ||
| 54 | + | ||
| 55 | +//凭证 | ||
| 56 | +type Auth struct { | ||
| 57 | + AppKey string //应用唯一标识 | ||
| 58 | + AppMasterSecret string //服务器秘钥,用于服务器端调用API请求时对发送内容做签名验证 | ||
| 59 | +} |
-
请 注册 或 登录 后发表评论