You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

75 lines
1.8 KiB
Go

package http
import (
"bytes"
"errors"
"fmt"
)
const (
smsSendUrl = "/api/sendUrl"
)
type MsgRes struct {
State int `json:"state"`
Msg string `json:"msg"`
}
type MsgReq struct {
Code string `json:"code"`
Phone string `json:"msg"`
}
type SmsCaptchaReqForTencent struct {
Action string `json:"Action"`
Version string `json:"Version"`
Region string `json:"Region"`
PhoneNumberSet []string `json:"PhoneNumberSet"`
SmsSdkAppId string `json:"SmsSdkAppId"`
TemplateId string `json:"TemplateId"`
SignName string `json:"SignName"`
TemplateParamSet []string `json:"TemplateParamSet"`
}
type SmsCaptchaResForTencent struct {
SendStatusSet []*SmsCaptchaResForTencentSub `json:"SendStatusSet"`
}
type SmsCaptchaResForTencentSub struct {
Code string `json:"Code"`
Message string `json:"Message"`
}
func (c *Client) SubmitPhoneCodeRequest(phoneMsg *MsgReq) (*SmsCaptchaResForTencentSub, error) {
fmt.Sprintln("=============")
fmt.Println("start send captcha")
req := &SmsCaptchaReqForTencent{
Action: "SendSms",
Version: "2021-01-11",
Region: "ap-guangzhou",
PhoneNumberSet: []string{"+86" + phoneMsg.Phone},
SmsSdkAppId: "1400237962",
TemplateId: "387221",
SignName: "627395",
TemplateParamSet: []string{phoneMsg.Code, "3"},
}
fmt.Println(req)
body, err := json2.Marshal(req)
if err != nil {
fmt.Println(err.Error())
return nil, err
}
fmt.Println(string(body))
resp := &SmsCaptchaResForTencent{}
fmt.Println("gogogo")
err = c.getParsedResponse("POST", smsSendUrl, jsonHeader, bytes.NewReader(body), resp)
if err != nil {
fmt.Println(err.Error())
return nil, err
}
if len(resp.SendStatusSet) == 0 {
return nil, errors.New("发送失败")
}
return resp.SendStatusSet[0], nil
}