first commit
This commit is contained in:
commit
1ee4d0cadd
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
||||
txim
|
74
api/api.go
Normal file
74
api/api.go
Normal file
@ -0,0 +1,74 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"math/rand"
|
||||
|
||||
"github.com/imroc/req"
|
||||
"github.com/tencentyun/tls-sig-api-v2-golang/tencentyun"
|
||||
)
|
||||
|
||||
const (
|
||||
API_HOST = "console.tim.qq.com"
|
||||
API_VERSION = "v4"
|
||||
)
|
||||
|
||||
var g struct {
|
||||
sdkAppID int
|
||||
identifier string
|
||||
key string
|
||||
}
|
||||
|
||||
func Init(sdkAppID int, key, identifier string) {
|
||||
g.sdkAppID = sdkAppID
|
||||
g.key = key
|
||||
g.identifier = identifier
|
||||
}
|
||||
|
||||
func UserSig(identifier string, expire int) string {
|
||||
sig, _ := tencentyun.GenSig(g.sdkAppID, g.key, g.identifier, expire)
|
||||
return sig
|
||||
}
|
||||
|
||||
//https://cloud.tencent.com/document/product/269/1615
|
||||
type GroupCreateReq struct {
|
||||
OwnerAccount string `json:"Owner_Account"`
|
||||
Type string `json:"Type"`
|
||||
Name string `json:"Name"`
|
||||
ApplyJoinOption string `json:"ApplyJoinOption"`
|
||||
}
|
||||
type GroupCreateAns struct {
|
||||
ActionStatus string `json:"ActionStatus"`
|
||||
ErrorInfo string `json:"ErrorInfo"`
|
||||
ErrorCode int `json:"ErrorCode"`
|
||||
GroupId string `json:"GroupId"`
|
||||
}
|
||||
|
||||
func GroupCreate(r *GroupCreateReq) (*GroupCreateAns, error) {
|
||||
a := GroupCreateAns{}
|
||||
err := Api("group_open_http_svc", "create_group", r, &a)
|
||||
return &a, err
|
||||
}
|
||||
|
||||
func Api(servicename, command string, in, out interface{}) error {
|
||||
host := fmt.Sprintf("https://%s/%s/%s/%s", API_HOST, API_VERSION, servicename, command)
|
||||
|
||||
query := req.QueryParam{
|
||||
"sdkappid": g.sdkAppID,
|
||||
"identifier": g.identifier,
|
||||
"usersig": UserSig(g.identifier, 5*60),
|
||||
"random": rand.Uint32(),
|
||||
"contenttype": "json",
|
||||
}
|
||||
|
||||
resp, err := req.Post(host, query, req.BodyJSON(in))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := resp.ToJSON(out); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
25
demo.go
Normal file
25
demo.go
Normal file
@ -0,0 +1,25 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
txim "github.com/xucx/txim/api"
|
||||
)
|
||||
|
||||
func main() {
|
||||
txim.Init(1, "xxx", "xxx")
|
||||
|
||||
//生成签名
|
||||
sig := txim.UserSig("xxx", 300)
|
||||
fmt.Println("签名:", sig)
|
||||
|
||||
//创建房间
|
||||
ans, err := txim.GroupCreate(&txim.GroupCreateReq{
|
||||
OwnerAccount: "administrator",
|
||||
Type: "ChatRoom",
|
||||
Name: "测试聊天室",
|
||||
ApplyJoinOption: "FreeAccess",
|
||||
})
|
||||
fmt.Printf("创建房间结果:%x,%+v\n", err, ans)
|
||||
|
||||
}
|
8
go.mod
Normal file
8
go.mod
Normal file
@ -0,0 +1,8 @@
|
||||
module github.com/xucx/txim
|
||||
|
||||
go 1.13
|
||||
|
||||
require (
|
||||
github.com/imroc/req v0.3.0
|
||||
github.com/tencentyun/tls-sig-api-v2-golang v1.0.0
|
||||
)
|
4
go.sum
Normal file
4
go.sum
Normal file
@ -0,0 +1,4 @@
|
||||
github.com/imroc/req v0.3.0 h1:3EioagmlSG+z+KySToa+Ylo3pTFZs+jh3Brl7ngU12U=
|
||||
github.com/imroc/req v0.3.0/go.mod h1:F+NZ+2EFSo6EFXdeIbpfE9hcC233id70kf0byW97Caw=
|
||||
github.com/tencentyun/tls-sig-api-v2-golang v1.0.0 h1:NavMw9XO2iCLv8hTKaJW2kTaGR2SdNljMABbe39yu6Q=
|
||||
github.com/tencentyun/tls-sig-api-v2-golang v1.0.0/go.mod h1:u7WiArmCTXTaQAHJwAOaLgpJ5e2xdY5/cgMEy3ubL60=
|
Loading…
Reference in New Issue
Block a user