|
- 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/aliyun"
- "errors"
- "fmt"
- "github.com/tidwall/gjson"
- "math/rand"
- "time"
-
- "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")
- captcha := createCaptcha()
- data := AliyunSmsBase(c)
- err := aliyun.AliyunSendSmsOwn(data["aliyun_sms_id"], data["aliyun_sms_secret"], postData["mobile"].(string), data["aliyun_sms_sign_name"], data["aliyun_sms_code"], "{\"code\":\""+captcha+"\"}")
- if err != nil {
- return errors.New("发送失败")
- }
- cache.SetEx("zhimeng:sms."+c.GetString("master_id")+":"+postData["mobile"].(string), captcha, 300)
- return nil
-
- }
- func createCaptcha() string {
- return fmt.Sprintf("%04v", rand.New(rand.NewSource(time.Now().UnixNano())).Int31n(10000))
- }
- func AliyunSmsBase(c *gin.Context) map[string]string {
- data := map[string]string{
- "aliyun_sms_id": "LTAI5tFzD9fUoYkp9SE6zcQb",
- "aliyun_sms_secret": "B8Jz7x2tn5YhHbba4vxmcdIufNtkAh",
- "aliyun_sms_code": "SMS_492445554",
- "aliyun_sms_sign_name": "广东智莺科技",
- }
- return data
- }
|