正在显示
3 个修改的文件
包含
150 行增加
和
0 行删除
@@ -2,6 +2,7 @@ package auth | @@ -2,6 +2,7 @@ package auth | ||
2 | 2 | ||
3 | type ILoginAuth interface { | 3 | type ILoginAuth interface { |
4 | LoginAuth() error | 4 | LoginAuth() error |
5 | + TODO(v interface{}) error | ||
5 | } | 6 | } |
6 | 7 | ||
7 | //TODO | 8 | //TODO |
@@ -34,3 +35,15 @@ func (o LoginBySms) LoginAuth() error { | @@ -34,3 +35,15 @@ func (o LoginBySms) LoginAuth() error { | ||
34 | func (o LoginByXxxx) LoginAuth() error { | 35 | func (o LoginByXxxx) LoginAuth() error { |
35 | return nil | 36 | return nil |
36 | } | 37 | } |
38 | + | ||
39 | +func (o LoginByPassword) TODO(v interface{}) error { | ||
40 | + return nil | ||
41 | +} | ||
42 | + | ||
43 | +func (o LoginBySms) TODO(v interface{}) error { | ||
44 | + return nil | ||
45 | +} | ||
46 | + | ||
47 | +func (o LoginByXxxx) TODO(v interface{}) error { | ||
48 | + return nil | ||
49 | +} |
services/im/models.go
0 → 100644
1 | +package im | ||
2 | + | ||
3 | +import ( | ||
4 | + "fmt" | ||
5 | +) | ||
6 | + | ||
7 | +type ImParam interface { | ||
8 | + Format() map[string]string | ||
9 | + GetPath() string | ||
10 | +} | ||
11 | + | ||
12 | +type BaseResp struct { | ||
13 | + Code int `json:"code"` | ||
14 | +} | ||
15 | + | ||
16 | +//TokenInfo 云通信Token | ||
17 | +type TokenInfo struct { | ||
18 | + Token string `json:"token"` | ||
19 | + Accid string `json:"accid"` | ||
20 | + Name string `json:"name"` | ||
21 | +} | ||
22 | +type UserCreateResult struct { | ||
23 | + BaseResp | ||
24 | + Info TokenInfo `json:"info"` | ||
25 | +} | ||
26 | + | ||
27 | +//UserCreate 云通信用户 | ||
28 | +type UserCreate struct { | ||
29 | + Accid string //网易云通信ID,最大长度32字符 | ||
30 | + Name string //ID昵称,最大长度64字符。 | ||
31 | + Props string //json属性,开发者可选填,最大长度1024字符 | ||
32 | + Icon string //ID头像URL,开发者可选填,最大长度1024字符 | ||
33 | + Token string | ||
34 | + /**云通信ID可以指定登录token值,最大长度128字符, | ||
35 | + 并更新,如果未指定,会自动生成token,并在 | ||
36 | + 创建成功后返回**/ | ||
37 | + Sign string //签名 | ||
38 | + Email string | ||
39 | + Birth string | ||
40 | + Mobile string | ||
41 | + Gender int //0未知,1男,2女 | ||
42 | + Ex string //扩展字段 | ||
43 | +} | ||
44 | + | ||
45 | +var ( | ||
46 | + _ ImParam = UserCreate{} | ||
47 | +) | ||
48 | + | ||
49 | +func (p UserCreate) Format() map[string]string { | ||
50 | + return map[string]string{ | ||
51 | + "accid": p.Accid, | ||
52 | + "name": p.Name, | ||
53 | + "props": p.Props, | ||
54 | + "icon": p.Icon, | ||
55 | + "token": p.Token, | ||
56 | + "sign": p.Sign, | ||
57 | + "email": p.Email, | ||
58 | + "birth": p.Birth, | ||
59 | + "mobile": p.Mobile, | ||
60 | + "gender": fmt.Sprintf("%d", p.Gender), | ||
61 | + "ex": p.Ex, | ||
62 | + } | ||
63 | +} | ||
64 | + | ||
65 | +func (p UserCreate) GetPath() string { | ||
66 | + return "/user/create.action" | ||
67 | +} |
services/im/netease.go
0 → 100644
1 | +package im | ||
2 | + | ||
3 | +import ( | ||
4 | + "crypto/sha1" | ||
5 | + "encoding/hex" | ||
6 | + "io/ioutil" | ||
7 | + "math/rand" | ||
8 | + "net/http" | ||
9 | + "net/url" | ||
10 | + "strconv" | ||
11 | + "strings" | ||
12 | + "time" | ||
13 | +) | ||
14 | + | ||
15 | +func buildCheckSum(appSecret string, nonce string, curTime string) string { | ||
16 | + str := []byte(appSecret + nonce + curTime) | ||
17 | + sh := sha1.New() | ||
18 | + sh.Write(str) | ||
19 | + result := hex.EncodeToString(sh.Sum(nil)) | ||
20 | + return strings.ToLower(result) | ||
21 | +} | ||
22 | + | ||
23 | +type ImClient struct { | ||
24 | + baseUrl string | ||
25 | + appKey string | ||
26 | + appSecret string | ||
27 | +} | ||
28 | + | ||
29 | +func (i ImClient) buildHeader() http.Header { | ||
30 | + var h = http.Header{} | ||
31 | + curTime := strconv.FormatInt(time.Now().Unix(), 10) | ||
32 | + nonce := strconv.FormatInt(time.Now().Unix()+rand.Int63n(5000), 10) | ||
33 | + checkSum := buildCheckSum(i.appSecret, nonce, curTime) | ||
34 | + h.Set("Content-Type", "application/x-www-form-urlencoded") | ||
35 | + h.Set("AppKey", i.appKey) | ||
36 | + h.Set("Nonce", nonce) | ||
37 | + h.Set("CurTime", curTime) | ||
38 | + h.Set("CheckSum", checkSum) | ||
39 | + return h | ||
40 | +} | ||
41 | + | ||
42 | +func (i ImClient) httpDo(path string, posts map[string]string) ([]byte, error) { | ||
43 | + client := http.Client{} | ||
44 | + reqURL := i.baseUrl + path | ||
45 | + params := url.Values{} | ||
46 | + for k, v := range posts { | ||
47 | + params.Add(k, v) | ||
48 | + } | ||
49 | + req, err := http.NewRequest("POST", reqURL, strings.NewReader(params.Encode())) | ||
50 | + if err != nil { | ||
51 | + return nil, err | ||
52 | + } | ||
53 | + req.Header = i.buildHeader() | ||
54 | + resp, err := client.Do(req) | ||
55 | + if err != nil { | ||
56 | + return nil, err | ||
57 | + } | ||
58 | + defer resp.Body.Close() | ||
59 | + | ||
60 | + body, err := ioutil.ReadAll(resp.Body) | ||
61 | + if err != nil { | ||
62 | + return nil, err | ||
63 | + } | ||
64 | + | ||
65 | + return body, nil | ||
66 | +} | ||
67 | + | ||
68 | +func (i ImClient) Call(param ImParam) ([]byte, error) { | ||
69 | + return i.httpDo(param.GetPath(), param.Format()) | ||
70 | +} |
-
请 注册 或 登录 后发表评论