微信相关接口
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

51 lines
825 B

package wechat
import (
"crypto/md5"
"encoding/hex"
"net"
"strings"
)
// 密码加密
func Md5Str(str ...string) string {
var build strings.Builder
if len(str) > 0 {
for _, v := range str {
build.WriteString(v)
}
} else {
return ""
}
h := md5.New()
h.Write([]byte(build.String())) // 需要加密的字符串
cipher2Str := h.Sum(nil)
sMd5 := hex.EncodeToString(cipher2Str) // 输出加密结果
return sMd5
}
/**
* 取本地IP
*/
func GetLocalIp() string {
addrs, err := net.InterfaceAddrs()
if err != nil {
return ""
}
for _, address := range addrs {
// 检查ip地址判断是否回环地址
if ipnet, ok := address.(*net.IPNet); ok && !ipnet.IP.IsLoopback() {
if ipnet.IP.To4() != nil && !ipnet.IP.IsLinkLocalUnicast() {
return ipnet.IP.String()
}
}
}
return ""
}