httplib_sms_service_gateway.go
2.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package svr
import (
"strings"
"time"
"gitlab.fjmaimaimai.com/mmm-go/partner/pkg/constant"
"gitlab.fjmaimaimai.com/mmm-go/partner/pkg/log"
)
type HttplibMmmSmsApiServiceGateway struct {
httplibBaseServiceGateway
}
func (serviceGateway *HttplibMmmSmsApiServiceGateway) SendSms(phone string) (map[string]interface{}, error) {
url := strings.Join([]string{serviceGateway.baseURL, "service", "sendSms"}, "/")
request := serviceGateway.createRequest(url, "post")
options := make(map[string]interface{})
options["phone"] = strings.TrimSpace(phone)
request.JSONBody(options)
response := make(map[string]interface{})
err := request.ToJSON(&response)
if err != nil {
log.Error("Service Gateway Fail:", err)
return nil, err
}
data, err := serviceGateway.responseHandle(response)
return data, err
}
func (serviceGateway *HttplibMmmSmsApiServiceGateway) CheckSmsCode(phone string, code string) (map[string]interface{}, error) {
url := strings.Join([]string{serviceGateway.baseURL, "service", "checkSmsCode"}, "/")
request := serviceGateway.createRequest(url, "post")
options := make(map[string]interface{})
options["phone"] = phone
options["code"] = code
request.JSONBody(options)
response := make(map[string]interface{})
request.ToJSON(&response)
data, err := serviceGateway.responseHandle(response)
return data, err
}
func NewHttplibMmmSmsApiServiceGateway() *HttplibMmmSmsApiServiceGateway {
return &HttplibMmmSmsApiServiceGateway{
httplibBaseServiceGateway: httplibBaseServiceGateway{
baseURL: constant.MMM_SMS_SERVICE_HOST,
connectTimeout: 100 * time.Second,
readWriteTimeout: 30 * time.Second,
},
}
}
type HttplibMmmSmsApiEmpty struct{}
func NewHttplibMmmSmsApiEmpty() *HttplibMmmSmsApiEmpty {
return &HttplibMmmSmsApiEmpty{}
}
func (serviceGateway *HttplibMmmSmsApiEmpty) SendSms(phone string) (map[string]interface{}, error) {
log.Info("非正式环境调用HttplibMmmSmsApiEmpty.SendSms发送短信")
return map[string]interface{}{}, nil
}
func (serviceGateway *HttplibMmmSmsApiEmpty) CheckSmsCode(phone string, code string) (map[string]interface{}, error) {
log.Info("非正式环境调用HttplibMmmSmsApiEmpty.CheckSmsCode 检查短信验证码")
return map[string]interface{}{}, nil
}