You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
41 lines
806 B
41 lines
806 B
8 months ago
|
package jpush
|
||
|
|
||
|
import (
|
||
|
"encoding/json"
|
||
|
"errors"
|
||
|
)
|
||
|
|
||
|
const verificationUrl = "https://api.verification.jpush.cn"
|
||
|
|
||
|
type loginTokenVerify struct {
|
||
|
Id int64 `json:"id"`
|
||
|
Code int `json:"code"`
|
||
|
Content string `json:"content"`
|
||
|
ExID string `json:"exID"`
|
||
|
Phone string `json:"phone"`
|
||
|
}
|
||
|
|
||
|
// GetPhone @Title 获取手机号
|
||
|
func GetPhone(token string) (phone string, err error) {
|
||
|
resByte, err := exec(verificationUrl, "/v1/web/loginTokenVerify", map[string]string{
|
||
|
"loginToken": token,
|
||
|
})
|
||
|
if err != nil {
|
||
|
return
|
||
|
}
|
||
|
var res loginTokenVerify
|
||
|
if err = json.Unmarshal(resByte, &res); err != nil {
|
||
|
return
|
||
|
}
|
||
|
if res.Code == 8000 {
|
||
|
bytes, err := decrypt(res.Phone)
|
||
|
if err != nil {
|
||
|
return phone, err
|
||
|
}
|
||
|
phone = string(bytes)
|
||
|
} else {
|
||
|
err = errors.New(res.Content)
|
||
|
}
|
||
|
return
|
||
|
}
|