(logsign string)
| 55 | } |
| 56 | |
| 57 | func GetAccessToken(logsign string) (string, error) { |
| 58 | // https://open.feishu.cn/open-apis/message/v4/batch_send/ 批量发送消息 tenant_access_token |
| 59 | // 先获取 tenant_access_token |
| 60 | u := TenantAccessMeg{ |
| 61 | AppId: beego.AppConfig.String("FEISHU_APPID"), |
| 62 | AppSecret: beego.AppConfig.String("FEISHU_APPSECRET"), |
| 63 | } |
| 64 | b := new(bytes.Buffer) |
| 65 | json.NewEncoder(b).Encode(u) |
| 66 | var tr *http.Transport |
| 67 | if proxyUrl := beego.AppConfig.String("proxy"); proxyUrl != "" { |
| 68 | proxy := func(_ *http.Request) (*url.URL, error) { |
| 69 | return url.Parse(proxyUrl) |
| 70 | } |
| 71 | tr = &http.Transport{ |
| 72 | TLSClientConfig: &tls.Config{InsecureSkipVerify: true}, |
| 73 | Proxy: proxy, |
| 74 | } |
| 75 | } else { |
| 76 | tr = &http.Transport{ |
| 77 | TLSClientConfig: &tls.Config{InsecureSkipVerify: true}, |
| 78 | } |
| 79 | } |
| 80 | client := &http.Client{Transport: tr} |
| 81 | //res, err := client.Post("https://open.feishu.cn/open-apis/auth/v3/tenant_access_token/internal", "application/json; charset=utf-8", b) |
| 82 | res, err := http.NewRequest("POST", "https://open.feishu.cn/open-apis/auth/v3/tenant_access_token/internal", b) |
| 83 | if err != nil { |
| 84 | logs.Error(logsign, "[feishuapp]", err.Error()) |
| 85 | return "", err |
| 86 | } |
| 87 | res.Header.Set("Content-Type", "application/json; charset=utf-8") |
| 88 | resp, err := client.Do(res) |
| 89 | defer res.Body.Close() |
| 90 | result, err := ioutil.ReadAll(resp.Body) |
| 91 | if err != nil { |
| 92 | logs.Error(logsign, "[feishuapp]", err.Error()) |
| 93 | return "", err |
| 94 | } |
| 95 | resp_json := TenantAccessResp{} |
| 96 | json.Unmarshal(result, &resp_json) |
| 97 | if resp_json.Msg != "ok" { |
| 98 | logs.Error(logsign, "[feishuapp]", resp_json.Msg) |
| 99 | return "", errors.New(resp_json.Msg) |
| 100 | } |
| 101 | logs.Info(logsign, "[feishuapp]", string(result)) |
| 102 | return resp_json.TenantAccessToken, nil |
| 103 | } |
| 104 | |
| 105 | func PostToFeiShuApp(title, text, receiveIds, logsign string) string { |
| 106 | open := beego.AppConfig.String("open-feishuapp") |
no test coverage detected