package main import ( "fmt" "io" "io/ioutil" "log" "net/http" ) const _accessKeyId string = "LTAI5tGjnZY6k799BHxhmqcm" const _accessKeySecret string = "eU1DmULbgHe2dnIg3P93634PO2vEh5" const _addr string = ":8081" func smsHandler(w http.ResponseWriter, r *http.Request) { defer r.Body.Close() body, err := io.ReadAll(r.Body) if err != nil { http.Error(w, err.Error()+"\n访问 /help 查看使用帮助", http.StatusInternalServerError) } if err := SendSMS(&body); err != nil { http.Error(w, err.Error()+"\n访问 /help 查看使用帮助", http.StatusInternalServerError) } fmt.Fprintf(w, "success") } func helpHandler(w http.ResponseWriter, r *http.Request) { content, err := ioutil.ReadFile("./help.html") if err != nil { http.Error(w, err.Error(), http.StatusInternalServerError) } w.Header().Set("Content-Type", "text/html; charset=utf-8") w.Write(content) } func main() { http.HandleFunc("/sms", smsHandler) http.HandleFunc("/help", helpHandler) log.Fatal(http.ListenAndServe(_addr, nil)) }