sms_controller.go 1.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. package global
  2. import (
  3. base_ctl "SCRM/controllers"
  4. "SCRM/service/sms_service"
  5. "encoding/json"
  6. "strconv"
  7. "github.com/astaxie/beego"
  8. )
  9. func SMSCBAPICtlRegistRouters() {
  10. beego.Router("/sms/callback", &SMSTplCallBackAPIController{}, "post:CallBack")
  11. }
  12. type SMSTplCallBackAPIController struct {
  13. base_ctl.BaseAPIController
  14. }
  15. // /sms/callback [post]
  16. func (this *SMSTplCallBackAPIController) CallBack() {
  17. var callbackParams map[string]string
  18. json.Unmarshal(this.Ctx.Input.RequestBody, &callbackParams)
  19. this.TraceLog("短信平台回调: params: %v", callbackParams)
  20. code := callbackParams["code"]
  21. templateIDStr := callbackParams["templateid"]
  22. if len(templateIDStr) != 0 {
  23. templateID, _ := strconv.Atoi(templateIDStr)
  24. if code == "2" {
  25. err := sms_service.SMSUCPaasTemplateApproved(int64(templateID))
  26. if err != nil {
  27. this.ErrorLog("短信平台回调(成功)——数据库操作失败: err: %v; templateID: %v", err, templateID)
  28. }
  29. } else if code == "3" {
  30. err := sms_service.SMSUCPaasTemplateUnapproved(int64(templateID))
  31. if err != nil {
  32. this.ErrorLog("短信平台回调(失败)——数据库操作失败: err: %v; templateID: %v", err, templateID)
  33. }
  34. }
  35. } else {
  36. this.TraceLog("短信平台回调: %+v", this.Ctx.Request)
  37. }
  38. this.ServeSuccessJSON(map[string]interface{}{
  39. "result": true,
  40. })
  41. }