广告平台(媒体使用)
25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

76 lines
1.9 KiB

  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. "code.fnuoos.com/go_rely_warehouse/zyos_go_third_party_api.git/sms"
  9. "code.fnuoos.com/zhimeng/model.git/src/implement"
  10. "github.com/gin-gonic/gin"
  11. "github.com/tidwall/gjson"
  12. )
  13. // Sms
  14. // @Summary 短信发送
  15. // @Tags 短信
  16. // @Description 短信-短信发送
  17. // @param Authorization header string false "验证参数Bearer和token空格拼接"
  18. // @Accept json
  19. // @Produce json
  20. // @Param args body md.SmsReq true "请求参数"
  21. // @Success 200 {string} "success"
  22. // @Failure 400 {object} md.Response "具体错误"
  23. // @Router /api/sms [POST]
  24. func Sms(c *gin.Context) {
  25. var args md.SmsReq
  26. err := c.ShouldBindJSON(&args)
  27. if err != nil {
  28. err = validate.HandleValidateErr(err)
  29. err1 := err.(e.E)
  30. e.OutErr(c, err1.Code, err1.Error())
  31. return
  32. }
  33. if args.Type == "fast_login" {
  34. NewAdminDb := implement.NewAdminDb(svc.MasterDb(c))
  35. admin, _ := NewAdminDb.GetAdminByUserName(args.Phone)
  36. if admin == nil {
  37. e.OutErr(c, 400, e.NewErr(400, "账号未注册"))
  38. return
  39. }
  40. }
  41. NewSysCfgDb := implement2.NewSysCfgDb(svc.MasterDb(c), c.GetString("mid"))
  42. key := NewSysCfgDb.SysCfgGetWithDb("mob_app_key")
  43. if key == "" {
  44. e.OutErr(c, 400, e.NewErr(400, "appkey不存在"))
  45. return
  46. }
  47. where := map[string]interface{}{
  48. "appkey": key,
  49. "zone": "86",
  50. "phone": args.Phone,
  51. }
  52. send, err := sms.SmsMobApiSend(where)
  53. if err != nil {
  54. e.OutErr(c, 400, err.Error())
  55. return
  56. }
  57. status := gjson.Get(send, "status").Int()
  58. msg := gjson.Get(send, "error").String()
  59. if status == 471 {
  60. e.OutErr(c, 400, e.NewErr(400, "发送的ip不在白名单中"))
  61. return
  62. }
  63. if status == 406 {
  64. e.OutErr(c, 400, e.NewErr(400, "appkey不存在"))
  65. return
  66. }
  67. if status != 200 {
  68. e.OutErr(c, 400, e.NewErr(400, msg))
  69. return
  70. }
  71. e.OutSuc(c, "success", nil)
  72. return
  73. }