智盟项目
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

85 行
2.1 KiB

  1. package sms
  2. import (
  3. "applet/app/db"
  4. "applet/app/db/model"
  5. "applet/app/lib/zhimeng"
  6. "applet/app/utils"
  7. "applet/app/utils/cache"
  8. "applet/app/utils/logx"
  9. "code.fnuoos.com/go_rely_warehouse/zyos_go_third_party_api.git/sms"
  10. "fmt"
  11. "github.com/tidwall/gjson"
  12. "github.com/gin-gonic/gin"
  13. )
  14. // NewZhimengSMS is 智盟的短信服务
  15. func NewZhimengSMS(c *gin.Context) *zhimeng.SDK {
  16. sms := new(zhimeng.SDK)
  17. key := db.SysCfgGet(c, "third_zm_sms_key")
  18. secret := db.SysCfgGet(c, "third_zm_sms_secret")
  19. if key == "" || secret == "" {
  20. _ = logx.Warn("短信服务配置错误")
  21. }
  22. sms.Init("send_msg", key, secret)
  23. return sms
  24. }
  25. func GetSmsPlatform(c *gin.Context) string {
  26. var smsPlatform = "ljioe"
  27. key := fmt.Sprintf("%s:sms_platform", c.GetString("master_id"))
  28. smsPlatformTmp, _ := cache.GetString(key)
  29. if smsPlatformTmp == "" {
  30. smsPlatformTmp = GetWebSiteAppSmsPlatform(c.GetString("master_id"))
  31. if smsPlatformTmp != "" {
  32. cache.SetEx(key, smsPlatformTmp, 300)
  33. }
  34. }
  35. if smsPlatformTmp != "" {
  36. smsPlatform = smsPlatformTmp
  37. }
  38. return smsPlatform
  39. }
  40. func GetWebSiteAppSmsPlatform(mid string) string {
  41. obj := new(model.UserAppList)
  42. has, err := db.Db.Where("uuid=? ", mid).Asc("id").Get(obj)
  43. if err != nil || !has {
  44. return ""
  45. }
  46. return utils.AnyToString(obj.SmsPlatform)
  47. }
  48. func GetTplId(c *gin.Context, zone, types string) string {
  49. // 校验短信验证码
  50. tplId := ""
  51. if zone != "86" {
  52. tplId = db.SysCfgGet(c, "mob_sms_sdk_international_template_id")
  53. } else {
  54. tplId = db.SysCfgGet(c, "mob_sms_sdk_template_id")
  55. }
  56. if c.GetString("app_type") == "o2o" {
  57. tplId = db.SysCfgGet(c, "biz_mob_sms_sdk_template_id")
  58. }
  59. normal := gjson.Get(tplId, types).String()
  60. if normal == "" {
  61. normal = gjson.Get(tplId, "normal").String()
  62. }
  63. return normal
  64. }
  65. func GetSmsConfig(c *gin.Context, zone string, postData map[string]interface{}) error {
  66. postData["is_mob"] = "1"
  67. postData["type"] = "mob"
  68. postData["sms_type"] = "putong"
  69. zone = "86"
  70. postData["templateCode"] = "14373673"
  71. postData["zone"] = zone
  72. postData["smsmsg_key"] = "30dc33054b635"
  73. postData["uid"] = c.GetString("master_id")
  74. err := sms.SmsSendZy(db.Db, postData)
  75. if err != nil {
  76. return err
  77. }
  78. return nil
  79. }