附近小店
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。
 
 
 

123 行
3.2 KiB

  1. package sms
  2. import (
  3. "applet/app/db"
  4. "applet/app/lib/zhimeng"
  5. "applet/app/svc"
  6. "applet/app/utils/cache"
  7. "applet/app/utils/logx"
  8. "code.fnuoos.com/go_rely_warehouse/zyos_go_third_party_api.git/sms"
  9. "errors"
  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 := svc.SysCfgGet(c, "third_zm_sms_key")
  18. secret := svc.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("mid"))
  28. smsPlatformTmp, _ := cache.GetString(key)
  29. if smsPlatformTmp == "" {
  30. smsPlatformTmp = svc.GetWebSiteAppSmsPlatform(c.GetString("mid"))
  31. if smsPlatformTmp != "" {
  32. cache.SetEx(key, smsPlatformTmp, 300)
  33. }
  34. }
  35. if smsPlatformTmp != "" {
  36. smsPlatform = smsPlatformTmp
  37. }
  38. return smsPlatform
  39. }
  40. func GetTplId(c *gin.Context, zone, types string) string {
  41. // 校验短信验证码
  42. tplId := ""
  43. if zone != "86" {
  44. tplId = svc.SysCfgGet(c, "mob_sms_sdk_international_template_id")
  45. } else {
  46. tplId = svc.SysCfgGet(c, "mob_sms_sdk_template_id")
  47. }
  48. if c.GetString("app_type") == "o2o" {
  49. tplId = db.SysCfgGet(c, "biz_mob_sms_sdk_template_id")
  50. }
  51. normal := gjson.Get(tplId, types).String()
  52. if normal == "" {
  53. normal = gjson.Get(tplId, "normal").String()
  54. }
  55. return normal
  56. }
  57. func GetSmsConfig(c *gin.Context, zone string, postData map[string]interface{}) error {
  58. m := db.SysCfgGet(c, "third_app_push_set")
  59. if c.GetString("app_type") == "o2o" {
  60. m = db.SysCfgGet(c, "biz_third_app_push_set")
  61. }
  62. key := gjson.Get(m, "mobAppKey").String()
  63. postData["is_mob"] = "1"
  64. postData["type"] = "mob"
  65. postData["sms_type"] = "putong"
  66. smsPlatform := GetSmsPlatform(c)
  67. if smsPlatform == "ljioe" {
  68. postData["is_mob"] = "0"
  69. postData["type"] = ""
  70. }
  71. token := c.GetHeader("Authorization")
  72. if zone == "" && token != "" {
  73. arkToken, _ := db.UserProfileFindByArkToken(svc.MasterDb(c), token)
  74. if arkToken != nil && arkToken.Uid > 0 {
  75. user, _ := db.UserFindByID(svc.MasterDb(c), arkToken.Uid)
  76. if user != nil && user.Uid > 0 {
  77. zone = user.Zone
  78. }
  79. }
  80. }
  81. if zone == "" {
  82. zone = "86"
  83. }
  84. if zone != "86" { //国际短信
  85. postData["is_sales"] = "2"
  86. postData["sms_type"] = "international"
  87. }
  88. postData["templateCode"] = GetTplId(c, zone, postData["templateCode"].(string))
  89. postData["zone"] = zone
  90. if key != "" {
  91. postData["smsmsg_key"] = key
  92. }
  93. if c.GetString("sms_type") == "1" { //新的
  94. postData["uid"] = c.GetString("mid")
  95. err := sms.SmsSend(db.Db, postData)
  96. if err != nil {
  97. return err
  98. }
  99. return nil
  100. }
  101. fmt.Println("===短信", postData, c.ClientIP())
  102. sdk, err := NewZhimengSMS(c).SelectFunction("msg_doing").WithSMSArgs(postData).Result()
  103. if err != nil {
  104. msg := gjson.Get(err.Error(), "msg").String()
  105. if msg == "" {
  106. msg = err.Error()
  107. }
  108. fmt.Println("===短信", err)
  109. errs := errors.New(msg)
  110. return errs
  111. }
  112. rmap := sdk.ToInterface().(map[string]interface{})
  113. fmt.Println("===短信", rmap)
  114. if rmap["status"] == "" {
  115. return err
  116. }
  117. return nil
  118. }