util_mobile.lua 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. local util_mobile = {}
  2. -- 运营商数据
  3. local oper_data = {
  4. -- 中国移动
  5. ["46000"] = {"CM", "中国移动", {"10086", "CXLL"}},
  6. ["46002"] = {"CM", "中国移动", {"10086", "CXLL"}},
  7. ["46007"] = {"CM", "中国移动", {"10086", "CXLL"}},
  8. -- 中国联通
  9. ["46001"] = {"CU", "中国联通", {"10010", "2082"}},
  10. ["46006"] = {"CU", "中国联通", {"10010", "2082"}},
  11. ["46009"] = {"CU", "中国联通", {"10010", "2082"}},
  12. -- 中国电信
  13. ["46003"] = {"CT", "中国电信", {"10001", "108"}},
  14. ["46005"] = {"CT", "中国电信", {"10001", "108"}},
  15. ["46011"] = {"CT", "中国电信", {"10001", "108"}},
  16. -- 中国广电
  17. ["46015"] = {"CB", "中国广电"}
  18. }
  19. --- 获取 MCC 和 MNC
  20. -- @return MCC or -1
  21. -- @return MNC or -1
  22. function util_mobile.getMccMnc()
  23. local imsi = mobile.imsi(mobile.simid()) or ""
  24. return string.sub(imsi, 1, 3) or -1, string.sub(imsi, 4, 5) or -1
  25. end
  26. --- 获取 Band
  27. -- @return Band or -1
  28. function util_mobile.getBand()
  29. local info = mobile.getCellInfo()[1] or {}
  30. return info.band or -1
  31. end
  32. --- 获取运营商
  33. -- @param is_zh 是否返回中文
  34. -- @return 运营商 or ""
  35. function util_mobile.getOper(is_zh)
  36. local imsi = mobile.imsi(mobile.simid()) or ""
  37. local mcc, mnc = string.sub(imsi, 1, 3), string.sub(imsi, 4, 5)
  38. local mcc_mnc = mcc .. mnc
  39. local oper = oper_data[mcc_mnc]
  40. if oper then
  41. return is_zh and oper[2] or oper[1]
  42. else
  43. return mcc_mnc
  44. end
  45. end
  46. --- 发送查询流量短信
  47. function util_mobile.queryTraffic()
  48. local imsi = mobile.imsi(mobile.simid()) or ""
  49. local mcc_mnc = string.sub(imsi, 1, 5)
  50. local oper = oper_data[mcc_mnc]
  51. if oper and oper[3] then
  52. sms.send(oper[3][1], oper[3][2])
  53. else
  54. log.warn("util_mobile.queryTraffic", "查询流量代码未配置")
  55. end
  56. end
  57. return util_mobile