util_mobile.lua 1.5 KB

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