-
Notifications
You must be signed in to change notification settings - Fork 4
/
SMS.go
67 lines (58 loc) · 1.41 KB
/
SMS.go
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
package lean
import (
"github.com/parnurzeal/gorequest"
)
const (
VoiceSMS = "void"
TextSMS = "sms"
)
//Number is the phone number
//TTL is default to 10 minutes
//AppName is default to the app name of you lean cloud application
//Op is default to verifying
//SmsType is default to TextSMS,
//set SmsType to VoiceSMS if you wanna send a voice sms
type RequestMobilePhoneVerify struct {
Number string `json:"mobilePhoneNumber"`
TTL int `json:"ttl,omitempty"`
AppName string `json:"name,omitempty"`
Op string `json:"op,omitempty"`
SmsType string `json:"smsType,omitempty"`
}
//request a mobile phone verify
func (client *leanClient) RequestMobilVerify(
verifyRequest RequestMobilePhoneVerify) error {
request := gorequest.New()
url := UrlBase + "/requestSmsCode"
superAgent := request.Post(url).
Set("X-LC-Id", client.appId).
Send(verifyRequest)
agent := Agent{
superAgent: superAgent,
client: client,
}
err := agent.Do()
if nil != err {
return err
} else {
return nil
}
}
//verfiy the code
func (client *leanClient) VerifyCode(phone, code string) error {
request := gorequest.New()
url := UrlBase + "/verifySmsCode/" + code
superAgent := request.Post(url).
Set("X-LC-Id", client.appId).
Query("mobilePhoneNumber=" + phone)
agent := Agent{
superAgent: superAgent,
client: client,
}
err := agent.UseSignature().Do()
if nil != err {
return err
} else {
return nil
}
}