47 lines
953 B
Go
47 lines
953 B
Go
package modifystate
|
|
|
|
import (
|
|
"fmt"
|
|
"io"
|
|
"log"
|
|
"net/http"
|
|
"strings"
|
|
"udesk/udesk/auth"
|
|
)
|
|
|
|
func PostToModifyState(email, state string) error {
|
|
// 获取 URL
|
|
url := fmt.Sprintf("https://servicecenter-alauda.udesk.cn/open_api_v1/callcenter/agent_state?email=%s&", email)
|
|
url = auth.Geturlstring(url)
|
|
|
|
// 请求体
|
|
bodystring := fmt.Sprintf("{\"agent_email\": \"%s\",\"agent_work_state\": \"%s\"}", email, state)
|
|
|
|
// 创建请求
|
|
req, err := http.NewRequest("POST", url, strings.NewReader(bodystring))
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
// 设置请求头
|
|
req.Header.Set("Content-Type", "application/json")
|
|
|
|
// 发送请求
|
|
client := &http.Client{}
|
|
resp, err := client.Do(req)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
defer resp.Body.Close()
|
|
|
|
// 读取响应体
|
|
respBody, err := io.ReadAll(resp.Body)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
// 打印响应体
|
|
log.Printf("send udesk to modify state,Response is: %s", string(respBody))
|
|
return nil
|
|
}
|