Go对接语音验证码接口代码示例

package main

import (
	"fmt"
	"io/ioutil"
	"net/http"
	"net/url"
	"strings"
)

const strUrl = "https://api.ihuyi.com/voice/Submit.json"

func main() {

    v := url.Values{}
        v.Set("account", "xxxxxxxx") //APIID(用户中心【云语音】-【语音验证码】-【产品总览】查看)
        v.Set("password", "xxxxxxxxx") //1、APIKEY(用户中心【云语音】-【语音验证码】-【产品总览】查看)2、动态密码(生成动态密码方式请看该文档末尾的说明)
        v.Set("mobile", "136xxxxxxxx") //接收手机号码,只能提交1个号码
        v.Set("content", "832745") //验证码(4-6位数字)
        v.Set("time", "1623643787") //Unix时间戳(10位整型数字,当使用动态密码方式时为必填)

	body := strings.NewReader(v.Encode()) //把form数据编码
	client := &http.Client{}
	req, _ := http.NewRequest("POST", strUrl, body)
	req.Header.Set("Content-Type", "application/x-www-form-urlencoded")

	resp, err := client.Do(req) //发送
	if err != nil {
		fmt.Println(err)
	}

	defer resp.Body.Close() //一定要关闭resp.Body
	res, _ := ioutil.ReadAll(resp.Body)
	fmt.Println(string(res))
}