黄梓健
5 years ago
9 changed files with 104 additions and 5 deletions
-
16controllers/client/login.go
-
1controllers/client/login_test.go
-
1go.mod
-
2go.sum
-
58libs/im/im.go
-
11libs/im/im_test.go
-
4models/live_config.go
-
3models/user.go
-
13utils/utils.go
@ -0,0 +1,58 @@ |
|||||
|
package im |
||||
|
|
||||
|
import ( |
||||
|
"encoding/json" |
||||
|
"errors" |
||||
|
"fmt" |
||||
|
"github.com/kirinlabs/HttpRequest" |
||||
|
"github.com/tencentyun/tls-sig-api-v2-golang/tencentyun" |
||||
|
"hudongzhuanjia/utils" |
||||
|
) |
||||
|
|
||||
|
var ( |
||||
|
//SdkAppid = 1400345581
|
||||
|
//SdkAppKey = "e3d095ce8253fe18109d6c1ad068907978cac0a428fbad181d8958631b78e930"
|
||||
|
|
||||
|
SdkAppKey = "9683fc9d2e50857f33c7ef5431942458f2dbc7042ba526f87042092afb646331" |
||||
|
SdkAppid = 1400337419 |
||||
|
TxImHost = "https://console.tim.qq.com" |
||||
|
) |
||||
|
|
||||
|
type AccountImportResult struct { |
||||
|
ActionStatus string `json:"ActionStatus"` |
||||
|
ErrorCode int `json:"ErrorCode"` |
||||
|
ErrorInfo string `json:"ErrorInfo"` |
||||
|
} |
||||
|
type AccountImportParam struct { |
||||
|
Identifier string `json:"Identifier"` |
||||
|
Nick string `json:"Nick"` |
||||
|
FaceUrl string `json:"FaceUrl"` |
||||
|
} |
||||
|
|
||||
|
func AccountImport(identifier, nickname, faceurl string) (string, error) { |
||||
|
sign, err := tencentyun.GenSig(SdkAppid, SdkAppKey, "admin", 86400*180) |
||||
|
if err != nil { |
||||
|
return "", err |
||||
|
} |
||||
|
random := utils.RandomStr(32) |
||||
|
u := fmt.Sprintf("%s/v4/im_open_login_svc/account_import?sdkappid=%d&identifier=admin&usersig=%s&random=%s&contenttype=json", TxImHost, SdkAppid, sign, random) |
||||
|
bs, _ := json.Marshal(&AccountImportParam{ |
||||
|
Identifier: identifier, |
||||
|
Nick: nickname, |
||||
|
FaceUrl: faceurl, |
||||
|
}) |
||||
|
resp, err := HttpRequest.NewRequest().Debug(true).JSON().Post(u, string(bs)) |
||||
|
if err != nil { |
||||
|
return "", err |
||||
|
} |
||||
|
res := AccountImportResult{} |
||||
|
err = resp.Json(&res) |
||||
|
if err != nil { |
||||
|
return "", err |
||||
|
} |
||||
|
if res.ErrorCode != 0 { |
||||
|
return "", errors.New(res.ErrorInfo) |
||||
|
} |
||||
|
|
||||
|
return tencentyun.GenSig(SdkAppid, SdkAppKey, identifier, 86400000) |
||||
|
} |
@ -0,0 +1,11 @@ |
|||||
|
package im |
||||
|
|
||||
|
import ( |
||||
|
"fmt" |
||||
|
"testing" |
||||
|
) |
||||
|
|
||||
|
func TestAccountImport(t *testing.T) { |
||||
|
sig, err := AccountImport("test1", "tommy", "http://a.cphotos.bdimg.com/timg?image&quality=100&size=b4000_4000&sec=1585813714&di=c76777c95455780deffa04d28b25cb70&src=http://b-ssl.duitang.com/uploads/item/201412/28/20141228171331_L5T2n.jpeg") |
||||
|
fmt.Println(sig, err) |
||||
|
} |
Write
Preview
Loading…
Cancel
Save
Reference in new issue