智盟项目
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

преди 5 месеца
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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. }