广告平台(媒体使用)
Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.

hdl_sms.go 3.5 KiB

3 mesi fa
3 mesi fa
3 mesi fa
3 mesi fa
3 mesi fa
4 mesi fa
3 mesi fa
3 mesi fa
3 mesi fa
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. package hdl
  2. import (
  3. implement2 "applet/app/db/implement"
  4. "applet/app/e"
  5. "applet/app/lib/validate"
  6. "applet/app/md"
  7. "applet/app/svc"
  8. "applet/app/utils"
  9. "code.fnuoos.com/go_rely_warehouse/zyos_go_third_party_api.git/sms"
  10. zhios_third_party_utils "code.fnuoos.com/go_rely_warehouse/zyos_go_third_party_api.git/utils"
  11. db "code.fnuoos.com/zhimeng/model.git/src"
  12. "code.fnuoos.com/zhimeng/model.git/src/implement"
  13. implement3 "code.fnuoos.com/zhimeng/model.git/src/super/implement"
  14. "code.fnuoos.com/zhimeng/model.git/src/super/model"
  15. "fmt"
  16. "github.com/gin-gonic/gin"
  17. "github.com/tidwall/gjson"
  18. "time"
  19. )
  20. // Sms
  21. // @Summary 短信发送
  22. // @Tags 短信
  23. // @Description 短信-短信发送
  24. // @param Authorization header string false "验证参数Bearer和token空格拼接"
  25. // @Accept json
  26. // @Produce json
  27. // @Param args body md.SmsReq true "请求参数"
  28. // @Success 200 {string} "success"
  29. // @Failure 400 {object} md.Response "具体错误"
  30. // @Router /api/sms [POST]
  31. func Sms(c *gin.Context) {
  32. var args md.SmsReq
  33. err := c.ShouldBindJSON(&args)
  34. if err != nil {
  35. err = validate.HandleValidateErr(err)
  36. err1 := err.(e.E)
  37. e.OutErr(c, err1.Code, err1.Error())
  38. return
  39. }
  40. if args.Type == "fast_login" {
  41. NewAdminDb := implement.NewMediumDb(svc.MasterDb(c))
  42. admin, _ := NewAdminDb.GetMediumByUsername(args.Phone)
  43. if admin == nil {
  44. e.OutErr(c, 400, e.NewErr(400, "账号未注册"))
  45. return
  46. }
  47. }
  48. if args.Type == "update_password" {
  49. admin, _ := svc.CheckUser(c)
  50. if admin == nil {
  51. e.OutErr(c, 400, e.NewErr(400, "账号未注册"))
  52. return
  53. }
  54. args.Phone = admin.Username
  55. }
  56. NewSysCfgDb := implement2.NewSysCfgDb(svc.MasterDb(c), c.GetString("mid"))
  57. key := NewSysCfgDb.SysCfgGetWithDb("mob_app_key")
  58. if key == "" {
  59. e.OutErr(c, 400, e.NewErr(400, "appkey不存在"))
  60. return
  61. }
  62. count := SmsNumGetSmsNum(c.GetString("mid"))
  63. if count-1 < 0 {
  64. e.OutErr(c, 400, e.NewErr(400, "短信数量不足"))
  65. return
  66. }
  67. where := map[string]interface{}{
  68. "appkey": key,
  69. "zone": "86",
  70. "phone": args.Phone,
  71. }
  72. send, err := sms.SmsMobApiSend(where)
  73. if err != nil {
  74. e.OutErr(c, 400, err.Error())
  75. return
  76. }
  77. status := gjson.Get(send, "status").Int()
  78. msg := gjson.Get(send, "error").String()
  79. if status == 471 {
  80. e.OutErr(c, 400, e.NewErr(400, "发送的ip不在白名单中"))
  81. return
  82. }
  83. if status == 406 {
  84. e.OutErr(c, 400, e.NewErr(400, "appkey不存在"))
  85. return
  86. }
  87. if status != 200 {
  88. e.OutErr(c, 400, e.NewErr(400, msg))
  89. return
  90. }
  91. //存入记录
  92. ext := map[string]interface{}{
  93. "send": send,
  94. "post": where,
  95. }
  96. var record = model.SmsRecord{
  97. OrdId: "",
  98. Uid: utils.StrToInt(c.GetString("mid")),
  99. Amount: "1",
  100. CostPrice: "",
  101. Balance: zhios_third_party_utils.IntToStr(count - 1),
  102. PayWay: 0,
  103. State: 1,
  104. Memo: "发送短信",
  105. CreateAt: time.Now(),
  106. UpdateAt: time.Now(),
  107. TradeNo: "",
  108. Type: 1,
  109. OrdType: "buy",
  110. Fee: "",
  111. Ext: zhios_third_party_utils.SerializeStr(ext),
  112. Phone: args.Phone,
  113. }
  114. db.Db.InsertOne(&record)
  115. sql := `UPDATE sms_num_list set num=num-%d WHERE uid=%s ;`
  116. sql = fmt.Sprintf(sql, 1, c.GetString("mid"))
  117. fmt.Println(sql)
  118. nativeString, err := db.QueryNativeString(db.Db, sql)
  119. fmt.Println(nativeString)
  120. fmt.Println(err)
  121. e.OutSuc(c, "success", nil)
  122. return
  123. }
  124. func SmsNumGetSmsNum(uid interface{}) int {
  125. NewSmsNumListDb := implement3.NewSmsNumListDb(db.Db)
  126. numData := NewSmsNumListDb.GetSmsNum(uid)
  127. num := 0
  128. if numData != nil {
  129. num = numData.Num
  130. }
  131. if num < 0 {
  132. num = 0
  133. }
  134. return num
  135. }