广告平台(媒体使用)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

hdl_sms.go 2.1 KiB

4 months ago
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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. if args.Type == "update_password" {
  42. admin, _ := svc.CheckUser(c)
  43. if admin == nil {
  44. e.OutErr(c, 400, e.NewErr(400, "账号未注册"))
  45. return
  46. }
  47. args.Phone = admin.Username
  48. }
  49. NewSysCfgDb := implement2.NewSysCfgDb(svc.MasterDb(c), c.GetString("mid"))
  50. key := NewSysCfgDb.SysCfgGetWithDb("mob_app_key")
  51. if key == "" {
  52. e.OutErr(c, 400, e.NewErr(400, "appkey不存在"))
  53. return
  54. }
  55. where := map[string]interface{}{
  56. "appkey": key,
  57. "zone": "86",
  58. "phone": args.Phone,
  59. }
  60. send, err := sms.SmsMobApiSend(where)
  61. if err != nil {
  62. e.OutErr(c, 400, err.Error())
  63. return
  64. }
  65. status := gjson.Get(send, "status").Int()
  66. msg := gjson.Get(send, "error").String()
  67. if status == 471 {
  68. e.OutErr(c, 400, e.NewErr(400, "发送的ip不在白名单中"))
  69. return
  70. }
  71. if status == 406 {
  72. e.OutErr(c, 400, e.NewErr(400, "appkey不存在"))
  73. return
  74. }
  75. if status != 200 {
  76. e.OutErr(c, 400, e.NewErr(400, msg))
  77. return
  78. }
  79. e.OutSuc(c, "success", nil)
  80. return
  81. }