sms.lua 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. local M = {}
  2. local httpclient = require("httpclient")
  3. local sms_url = "https://api-v4.mysubmail.com/sms/xsend"
  4. local sms_world_url = "https://api-v4.mysubmail.com/internationalsms/xsend"
  5. M.send = function(phone,appid,appkey,signature,template_code,vars)
  6. local data = {
  7. appid = appid,
  8. signature = appkey,
  9. to = phone,
  10. project = template_code,
  11. vars = cjson.encode(vars),
  12. sms_signature = signature,
  13. }
  14. local result,msg = httpclient.post(sms_url,{
  15. ["Content-Type"] = "application/json",
  16. },cjson.encode(data))
  17. if result then
  18. local json = cjson.decode(msg)
  19. if json.status == "success" then
  20. return true
  21. else
  22. return false,json.msg
  23. end
  24. else
  25. return false,msg
  26. end
  27. end
  28. M.send_world = function(phone,appid,appkey,template_code,vars)
  29. local data = {
  30. appid = appid,
  31. signature = appkey,
  32. to = phone,
  33. project = template_code,
  34. vars = cjson.encode(vars)
  35. }
  36. print(cjson.encode(data))
  37. local result,msg = httpclient.post(sms_world_url,{
  38. ["Content-Type"] = "application/json",
  39. },cjson.encode(data))
  40. if result then
  41. local json = cjson.decode(msg)
  42. if json.status == "success" then
  43. return true
  44. else
  45. return false,json.msg
  46. end
  47. else
  48. return false,msg
  49. end
  50. end
  51. return M