util_mobile.lua 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. local util_mobile = {mcc = 99, mnc = 99, band = 99}
  2. -- 查询流量代码
  3. local trafficCode = {
  4. CU = {"10010", "1071"},
  5. CM = {"10086", "cxll"},
  6. CT = {"10001", "108"}
  7. }
  8. -- 获取运营商
  9. function util_mobile.getOper(is_zh)
  10. if util_mobile.mcc ~= 460 then
  11. return ""
  12. end
  13. if util_mobile.mnc == 1 then
  14. return is_zh and "中国联通" or "CU"
  15. end
  16. if util_mobile.mnc == 0 then
  17. return is_zh and "中国移动" or "CM"
  18. end
  19. if util_mobile.mnc == 11 then
  20. return is_zh and "中国电信" or "CT"
  21. end
  22. if util_mobile.mnc == 15 then
  23. return is_zh and "中国广电" or "CB"
  24. end
  25. return ""
  26. end
  27. -- 发送查询流量短信
  28. function util_mobile.queryTraffic()
  29. local oper = util_mobile.getOper()
  30. if oper and trafficCode[oper] then
  31. sms.send(trafficCode[oper][1], trafficCode[oper][2])
  32. else
  33. log.warn("queryTraffic", "查询流量代码未配置")
  34. end
  35. end
  36. sys.subscribe(
  37. "CELL_INFO_UPDATE",
  38. function()
  39. local info = mobile.getCellInfo()[1] or {}
  40. util_mobile.mcc, util_mobile.mnc, util_mobile.band = info.mcc, info.mnc, info.band
  41. log.info("cell", "mcc:", util_mobile.mcc, "mnc:", util_mobile.mnc, "band:", util_mobile.band)
  42. end
  43. )
  44. return util_mobile