140 lines
3.5 KiB
Go
140 lines
3.5 KiB
Go
package enterprise_wechat
|
|
|
|
import (
|
|
"fmt"
|
|
"git.rosy.net.cn/baseapi"
|
|
"git.rosy.net.cn/jx-callback/globals"
|
|
"go.uber.org/zap"
|
|
"strconv"
|
|
"testing"
|
|
)
|
|
|
|
var (
|
|
api *API
|
|
sugarLogger *zap.SugaredLogger
|
|
)
|
|
|
|
func init() {
|
|
logger, _ := zap.NewDevelopment()
|
|
sugarLogger = logger.Sugar()
|
|
baseapi.Init(sugarLogger)
|
|
//api = New("ww9a156bfa070e1857", "JQsEmSTltHhNgdPIT320YJFphiYmRs-YZa-rCBwplss") // 小程序
|
|
api = New("ww9a156bfa070e1857", "0jBdCjSmoFiOoHIXyeCK9VbGQ82fVNJZ8uMl6JNN7X4") // 通讯录
|
|
api = New("ww9a156bfa070e1857", "JQsEmSTltHhNgdPIT320YJFphiYmRs-YZa-rCBwplss") // 小程序
|
|
//api = New("6705486294797503379", "c1e6c280-e618-4103-9d0a-673bc54fb22e", "5375691", "cabrXQf9eFMVWVYg4hNlwu")
|
|
//token, _ := api.GetAccessToken()
|
|
//api.accessToken = token.BusinessDataObj.AccessToken
|
|
}
|
|
|
|
func TestGetToken(t *testing.T) {
|
|
token, err := api.GetAccessToken()
|
|
if err != nil {
|
|
fmt.Println("err=", err)
|
|
}
|
|
fmt.Println("errmsg:=", token.ErrMsg)
|
|
fmt.Println("errmsg:=", token.AccessToken)
|
|
fmt.Println("errmsg:=", token.ExpiresIn)
|
|
fmt.Println("errmsg api token:=", api.accessToken)
|
|
fmt.Println("errmsg api expiresin time:=", api.expiresIn)
|
|
}
|
|
|
|
func TestAPI_GetDepartmentList(t *testing.T) {
|
|
var aa int = 10004
|
|
fmt.Println(aa)
|
|
cc := strconv.Itoa(int(aa))
|
|
bb := string(aa)
|
|
fmt.Println(bb)
|
|
fmt.Println(cc)
|
|
ee := "四川省"
|
|
fmt.Println(ee[0:6])
|
|
}
|
|
|
|
// 获取所有的部门
|
|
func TestGetAllDepartmentList(t *testing.T) {
|
|
data, err := api.GetAllDepartmentList()
|
|
fmt.Println(err)
|
|
for _, v := range data {
|
|
fmt.Println(v.Name)
|
|
}
|
|
}
|
|
|
|
// 创建员工
|
|
func TestCreateStaff(t *testing.T) {
|
|
err := api.CreateBoss2JxStaff(&CreateBoos2JXStaffReq{
|
|
Userid: "jx2022524_6685111",
|
|
Name: "门店老板",
|
|
Alias: "",
|
|
Mobile: "189818103",
|
|
Department: []int{18}, // 四川省
|
|
Order: nil,
|
|
Position: "老板_群主",
|
|
Gender: "1",
|
|
Email: "",
|
|
IsLeaderInDept: []int{1},
|
|
Enable: 0,
|
|
AvatarMediaid: "",
|
|
Telephone: "",
|
|
Address: "",
|
|
Extattr: Extattr{},
|
|
MainDepartment: 0,
|
|
ToInvite: true,
|
|
ExternalPosition: "",
|
|
ExternalProfile: ExternalProfile{},
|
|
})
|
|
fmt.Println("err", err)
|
|
}
|
|
|
|
// 手机账号获取用户信息
|
|
func TestGetUserByMobile(t *testing.T) {
|
|
mobile, err := api.GetUserIdByMobile("18981810351")
|
|
fmt.Println(err)
|
|
fmt.Println(mobile)
|
|
}
|
|
|
|
// 创建会话群聊
|
|
func TestCreateSession(t *testing.T) {
|
|
err := api.CreateAppChat(&CreateAppChatParamReq{
|
|
UserList: []string{"WangXiao", "LiuLei"},
|
|
Name: "刘磊的企业微信群1",
|
|
Owner: "LiuLei",
|
|
ChatId: "18981810341",
|
|
})
|
|
fmt.Println("err======", err)
|
|
}
|
|
|
|
// 发送消息到企业微信
|
|
func TestSendMsg(t *testing.T) {
|
|
msg := &EnterpriseSendMsgReq{
|
|
Touser: "LiuLei",
|
|
Toparty: "",
|
|
Totag: "",
|
|
Msgtype: "textcard",
|
|
Agentid: 1000005,
|
|
Textcard: TextCardObject{
|
|
Title: "异步任务",
|
|
Description: "刚刚的同步任务下载链接",
|
|
Url: "https://www.baidu.com",
|
|
Btntxt: "详情",
|
|
},
|
|
EnableIdTrans: 0,
|
|
EnableDuplicateCheck: 0,
|
|
DuplicateCheckInterval: 0,
|
|
}
|
|
err := api.SendMsgToUser(msg)
|
|
fmt.Println("err === ", err)
|
|
}
|
|
|
|
// 获取员工信息
|
|
func TestGetUserId(t *testing.T) {
|
|
phone, err := api.GetUserIdByMobile("18981810340")
|
|
globals.SugarLogger.Debugf("phone := %s,err :=%s", phone, err)
|
|
}
|
|
|
|
func TestDepartmentList(t *testing.T) {
|
|
api.GetDepartmentList()
|
|
}
|
|
|
|
func TestGetEnterpriseStaffInfo(t *testing.T) {
|
|
api.GetEnterpriseStaffInfo(7)
|
|
}
|