yunpian / yunpian-go-sdk

MIT License
41 stars 5 forks source link

重构SDK代码 #2

Closed gotoxu closed 6 years ago

gotoxu commented 6 years ago

新的SDK代码在yunpian文件夹下,请评审。 新接口的调用方式,以发送单个SMS短信为例:

cfg := DefaultConfig().WithAPIKey("" /*you api key*/)
sms := NewClient(cfg).SMS()

input := &SingleSendRequest{
    Mobile: "13800138000",
    Text:   "您的验证码是1234。如非本人操作,请忽略本短信",
}

resp, err := sms.SingleSend(input)
if err != nil {
    // handle error
    return
}

if !resp.IsSuccess() {
    // 发送失败
    return
}

// 正常业务流程

目前只实现了V2接口,如果需要实现V1接口,请自行实现。 由于我没有测试API KEY,因此测试用例不是很齐全,如果需要请自行补齐。

gotoxu commented 6 years ago

重新合并到develop分支中,请到这里查看