package global import ( base_ctl "SCRM/controllers" "SCRM/service/sms_service" "encoding/json" "strconv" "github.com/astaxie/beego" ) func SMSCBAPICtlRegistRouters() { beego.Router("/sms/callback", &SMSTplCallBackAPIController{}, "post:CallBack") } type SMSTplCallBackAPIController struct { base_ctl.BaseAPIController } // /sms/callback [post] func (this *SMSTplCallBackAPIController) CallBack() { var callbackParams map[string]string json.Unmarshal(this.Ctx.Input.RequestBody, &callbackParams) this.TraceLog("短信平台回调: params: %v", callbackParams) code := callbackParams["code"] templateIDStr := callbackParams["templateid"] if len(templateIDStr) != 0 { templateID, _ := strconv.Atoi(templateIDStr) if code == "2" { err := sms_service.SMSUCPaasTemplateApproved(int64(templateID)) if err != nil { this.ErrorLog("短信平台回调(成功)——数据库操作失败: err: %v; templateID: %v", err, templateID) } } else if code == "3" { err := sms_service.SMSUCPaasTemplateUnapproved(int64(templateID)) if err != nil { this.ErrorLog("短信平台回调(失败)——数据库操作失败: err: %v; templateID: %v", err, templateID) } } } else { this.TraceLog("短信平台回调: %+v", this.Ctx.Request) } this.ServeSuccessJSON(map[string]interface{}{ "result": true, }) }