util_mobile.lua 2.1 KB

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