In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-20 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/03 Report--
Package mainimport ("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 / / read all output 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 () Erratic = nil {fmt.Println ("Wait", err.Error ()) return timestamp, sign, err} timestamp = Key [0] sign = Key [1] return timestamp, sign, nil} func SendDingMsg (msg string) {/ / request address template timestamp, sign, err: = GetKey () if errata = nil {fmt.Println ("GetKey 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}} `/ / create a request req Err: = http.NewRequest ("POST", webHook, strings.NewReader (content)) if err! = nil {fmt.Println (err)} client: = & http.Client {} / / set request header req.Header.Set ("Content-Type", "application/json") req.Header.Set ("User-agent", "firefox") / / send request resp Err: = client.Do (req) / / close request 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])}
Secondary Python script:
#! python 2.7import timeimport hmacimport hashlibimport base64import urllibtimestamp = 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)
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.