Files
mir-godot/server/framework/utils/phone.go
2024-03-03 22:59:18 +08:00

70 lines
1.5 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package Utils
import (
"bytes"
"encoding/json"
"io/ioutil"
"log"
"net/http"
"regexp"
)
func MobileFormat(str string) string {
re, _ := regexp.Compile("(\\d{3})(\\d{6})(\\d{2})")
return re.ReplaceAllString(str, "$1******$3")
}
func SendMessage(form string, phone string, info string) bool {
status := true
if form == "" || phone == "" || info == "" {
status = false
return status
}
desc := ""
if form == "express" {
desc = "【GEEKROS】Hi" + info + " 你在GEEKROS的订单已经发货请留意快递信息及时查收。"
}
if form == "account" {
desc = "【GEEKROS】你的验证码为" + info + " 有效期10分钟工作人员绝不会索取此验证码切勿告知他人。"
}
apiUrl := "https://smssh1.253.com/msg/v1/send/json"
params := make(map[string]interface{})
params["account"] = ""
params["password"] = ""
params["phone"] = phone
params["msg"] = desc
params["report"] = "false"
bytesData, err := json.Marshal(params)
if err != nil {
status = false
return status
}
reader := bytes.NewReader(bytesData)
request, err := http.NewRequest("POST", apiUrl, reader)
if err != nil {
status = false
return status
}
request.Header.Set("Content-Type", "application/json;charset=UTF-8")
client := http.Client{}
resp, err := client.Do(request)
if err != nil {
status = false
return status
}
respBytes, err := ioutil.ReadAll(resp.Body)
if err != nil {
status = false
return status
}
log.Println("[PhoneMessage]", string(respBytes))
return true
}