微信相关接口
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

  1. package wechat
  2. import (
  3. "crypto/md5"
  4. "encoding/hex"
  5. "net"
  6. "strings"
  7. )
  8. // 密码加密
  9. func Md5Str(str ...string) string {
  10. var build strings.Builder
  11. if len(str) > 0 {
  12. for _, v := range str {
  13. build.WriteString(v)
  14. }
  15. } else {
  16. return ""
  17. }
  18. h := md5.New()
  19. h.Write([]byte(build.String())) // 需要加密的字符串
  20. cipher2Str := h.Sum(nil)
  21. sMd5 := hex.EncodeToString(cipher2Str) // 输出加密结果
  22. return sMd5
  23. }
  24. /**
  25. * 取本地IP
  26. */
  27. func GetLocalIp() string {
  28. addrs, err := net.InterfaceAddrs()
  29. if err != nil {
  30. return ""
  31. }
  32. for _, address := range addrs {
  33. // 检查ip地址判断是否回环地址
  34. if ipnet, ok := address.(*net.IPNet); ok && !ipnet.IP.IsLoopback() {
  35. if ipnet.IP.To4() != nil && !ipnet.IP.IsLinkLocalUnicast() {
  36. return ipnet.IP.String()
  37. }
  38. }
  39. }
  40. return ""
  41. }