|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384 |
- package sms
-
- import (
- "applet/app/db"
- "applet/app/db/model"
- "applet/app/lib/zhimeng"
- "applet/app/utils"
- "applet/app/utils/cache"
- "applet/app/utils/logx"
- "code.fnuoos.com/go_rely_warehouse/zyos_go_third_party_api.git/sms"
- "fmt"
- "github.com/tidwall/gjson"
-
- "github.com/gin-gonic/gin"
- )
-
- // NewZhimengSMS is 智盟的短信服务
- func NewZhimengSMS(c *gin.Context) *zhimeng.SDK {
- sms := new(zhimeng.SDK)
- key := db.SysCfgGet(c, "third_zm_sms_key")
- secret := db.SysCfgGet(c, "third_zm_sms_secret")
- if key == "" || secret == "" {
- _ = logx.Warn("短信服务配置错误")
- }
- sms.Init("send_msg", key, secret)
- return sms
- }
- func GetSmsPlatform(c *gin.Context) string {
- var smsPlatform = "ljioe"
- key := fmt.Sprintf("%s:sms_platform", c.GetString("master_id"))
- smsPlatformTmp, _ := cache.GetString(key)
- if smsPlatformTmp == "" {
- smsPlatformTmp = GetWebSiteAppSmsPlatform(c.GetString("master_id"))
- if smsPlatformTmp != "" {
- cache.SetEx(key, smsPlatformTmp, 300)
- }
- }
- if smsPlatformTmp != "" {
- smsPlatform = smsPlatformTmp
- }
- return smsPlatform
- }
- func GetWebSiteAppSmsPlatform(mid string) string {
- obj := new(model.UserAppList)
- has, err := db.Db.Where("uuid=? ", mid).Asc("id").Get(obj)
- if err != nil || !has {
- return ""
- }
- return utils.AnyToString(obj.SmsPlatform)
- }
-
- func GetTplId(c *gin.Context, zone, types string) string {
- // 校验短信验证码
- tplId := ""
- if zone != "86" {
- tplId = db.SysCfgGet(c, "mob_sms_sdk_international_template_id")
- } else {
- tplId = db.SysCfgGet(c, "mob_sms_sdk_template_id")
- }
- if c.GetString("app_type") == "o2o" {
- tplId = db.SysCfgGet(c, "biz_mob_sms_sdk_template_id")
- }
- normal := gjson.Get(tplId, types).String()
- if normal == "" {
- normal = gjson.Get(tplId, "normal").String()
- }
- return normal
- }
- func GetSmsConfig(c *gin.Context, zone string, postData map[string]interface{}) error {
- postData["is_mob"] = "1"
- postData["type"] = "mob"
- postData["sms_type"] = "putong"
- zone = "86"
- postData["templateCode"] = "14373673"
- postData["zone"] = zone
- postData["smsmsg_key"] = "30dc33054b635"
- postData["uid"] = c.GetString("master_id")
- err := sms.SmsSendZy(db.Db, postData)
- if err != nil {
- return err
- }
- return nil
-
- }
|