91超碰碰碰碰久久久久久综合_超碰av人澡人澡人澡人澡人掠_国产黄大片在线观看画质优化_txt小说免费全本

溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

Go語言實現釘釘發送通知

發布時間:2020-06-23 12:16:16 來源:網絡 閱讀:408 作者:藍葉子Sheep 欄目:系統運維
package?main

import?(
???"bufio"
???"io"
???"fmt"
???"io/ioutil"
???"os/exec"
???"net/http"
???"os"
???"strings"
)

func?GetKey()?(timestamp?string?,sign?string,?err?error){
???cmd?:=?exec.Command("/bin/python",?"/application/scripts/hezhong_host_status/aaa.py")
???stdout?,?err?:=?cmd.StdoutPipe()
???if?err?!=?nil?{
??????fmt.Println("Error:can?not?obtain?stdout?pipe?for?command:%s?\n",?err)
??????return?timestamp?,?sign,??err
???}


???if?err?:=?cmd.Start()?;?err?!=?nil?{
??????fmt.Println("Error:The?command?is?err?",err)
??????return??timestamp,??sign,err
???}

???var?Key?[]string
???//讀取所有輸出
???bytes?:=?bufio.NewReader(stdout)
???for?{
??????line?,err:=?bytes.ReadString('\n')
??????if?err?==?io.EOF{
?????????break
??????}
??????if?err?!=?nil?{
?????????fmt.Println("Read?Err:",err)
??????}
??????Key?=?append(Key,line)
???}


???if?err?:=?cmd.Wait();err!=?nil{
??????fmt.Println("Wait",err.Error())
??????return??timestamp,?sign?,err
???}

???timestamp?=?Key[0]
???sign?=?Key[1]
???return?timestamp?,sign?,nil
}

func?SendDingMsg(msg?string)?{
???//請求地址模板

???timestamp?,?sign?,?err?:=?GetKey()
???if?err?!=?nil?{
??????fmt.Println("Get?Key?Err:",err)
???}
???timestamp?=?strings.TrimRight(timestamp,?"\n")
???sign?=?strings.TrimRight(sign,?"\n")
???//timestamp?:=?time.Now().UnixNano()?/?1e6
???//timestamp?:=?int64(1572870805748)
???//sign?:=?"oJ5SHD3IwCWVIcL78k3pgX0tfQnjDfcDZMPXAI%2BvrFE%3D"
???webHook?:=?"https://oapi.dingtalk.com/robot/send?access_token=628d11124aef5f9efe2a8c8a6b5afa2b67ab01dxxxxxxxxxxxxxxxxxxxxx&"+?"timestamp="?+?timestamp?+?"&sign="?+?sign
???content?:=?`{"msgtype":?"text",
??????"text":?{"content":?"`+?msg?+?`"},
????????????????"at":?{
?????????????????????"atMobiles":?[
?????????????????????????"18301371817"
?????????????????????],
?????????????????????"isAtAll":?true
????????????????}
???}`
???//創建一個請求
???req,?err?:=?http.NewRequest("POST",?webHook,?strings.NewReader(content))
???if?err?!=?nil?{
??????fmt.Println(err)
???}
???client?:=?&http.Client{}
???//設置請求頭
???req.Header.Set("Content-Type",?"application/json")
???req.Header.Set("User-agent","firefox")
???//發送請求
???resp,?err?:=?client.Do(req)
???//關閉請求
???defer?resp.Body.Close()
???fmt.Println(resp.StatusCode)
???body,_?:=?ioutil.ReadAll(resp.Body)
???fmt.Println(string(body))
???if?err?!=?nil?{
??????fmt.Println("handle?error")
???}
}


func?main(){
???SendDingMsg(os.Args[1])
}

輔助Python腳本:

#!python?2.7
import?time
import?hmac
import?hashlib
import?base64
import?urllib
timestamp?=?long(round(time.time()?*?1000))
secret?=?'this?is?secret'
secret_enc?=?bytes(secret).encode('utf-8')
string_to_sign?=?'{}\n{}'.format(timestamp,?secret)
string_to_sign_enc?=?bytes(string_to_sign).encode('utf-8')
hmac_code?=?hmac.new(secret_enc,?string_to_sign_enc,?digestmod=hashlib.sha256).digest()
sign?=?urllib.quote_plus(base64.b64encode(hmac_code))
print(timestamp)
print(sign)




向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI

西平县| 资兴市| 黄冈市| 正阳县| 孟州市| 泗洪县| 砚山县| 台州市| 金沙县| 银川市| 杭州市| 大余县| 儋州市| 那坡县| 盐池县| 阿图什市| 恩平市| 台中县| 九龙城区| 太仓市| 宕昌县| 施甸县| 济阳县| 武平县| 满城县| 敦煌市| 化州市| 霞浦县| 睢宁县| 图木舒克市| 漳州市| 德庆县| 合阳县| 岳阳县| 嵊泗县| 景洪市| 三原县| 兴业县| 个旧市| 阳原县| 南漳县|