|
1 | 1 | package handler |
2 | 2 |
|
3 | 3 | import ( |
4 | | - "fmt" |
5 | 4 | "net/http" |
6 | 5 | "strings" |
7 | 6 |
|
@@ -57,29 +56,13 @@ func (s *Server) SMSHandler(c *gin.Context) { |
57 | 56 | log.Info(c, "processed request to send SMS to: %s, content: %s", phoneNumber, messageContent) |
58 | 57 | log.Info(c, "simulating SMS sent to %s with content: %s", phoneNumber, messageContent) |
59 | 58 | } else { |
60 | | - code, err := service.GetLoginCode(SMSCfg.ClientID, SMSCfg.ClientSecret) |
| 59 | + err := service.SendSMS(phoneNumber, messageContent) |
61 | 60 | if err != nil { |
62 | | - errmsg := fmt.Sprintf("Error getting sms code: %v", err) |
63 | | - log.Error(c, "Error: %s received data: %v", errmsg) |
64 | | - response.JSONError(c, http.StatusBadRequest, "", errmsg) |
| 61 | + log.Error(c, "failed to send SMS to %s, error: %v", phoneNumber, err) |
| 62 | + response.JSONError(c, http.StatusInternalServerError, "", "failed to send sms") |
65 | 63 | return |
66 | 64 | } |
67 | | - token, err := service.GetJWTToken(code, SMSCfg.ClientID, s.HTTPClient) |
68 | | - if err != nil { |
69 | | - errmsg := fmt.Sprintf("Error getting sms token: %v", err) |
70 | | - log.Error(c, "Error: %s Received data: %v", errmsg) |
71 | | - response.JSONError(c, http.StatusBadRequest, "", errmsg) |
72 | | - return |
73 | | - } |
74 | | - messageContent = fmt.Sprintf("验证码:%s,5分钟内有效,请妥善保管!", messageContent) |
75 | | - _, err = service.SendSMS(s.HTTPClient, token, phoneNumber, messageContent) |
76 | | - if err != nil { |
77 | | - errmsg := fmt.Sprintf("Error getting sms token: %v", err) |
78 | | - log.Error(c, "Error: %s Received data: %v", errmsg) |
79 | | - response.JSONError(c, http.StatusBadRequest, "", errmsg) |
80 | | - return |
81 | | - } |
82 | | - log.Info(c, "simulating SMS sent to %s with content: %s", phoneNumber, messageContent) |
| 65 | + log.Info(c, "successfully sent SMS to %s for verification", phoneNumber) |
83 | 66 | } |
84 | 67 | c.JSON(http.StatusOK, ResponseBody{Status: "ok", Msg: "simulated SMS sent successfully"}) |
85 | 68 | } |
0 commit comments