語音通知接口文檔 點(diǎn)擊下載
語音通知接口接入指南 點(diǎn)擊訪問
//接口類型:互億無線語音通知接口。
//賬戶注冊(cè):請(qǐng)通過該地址開通賬戶https://user.ihuyi.com/new/register.html
//注意事項(xiàng):
//(1)調(diào)試期間,請(qǐng)仔細(xì)閱讀接口文檔;
//(2)請(qǐng)使用APIID(查看APIID請(qǐng)登錄用戶中心->語音通知->產(chǎn)品總覽->APIID)及APIkey來調(diào)用接口;
//(3)該代碼僅供接入互億無線語音通知接口參考使用,客戶可根據(jù)實(shí)際需要自行編寫;
#define IPSTR "api.vm.ihuyi.com"
#define PORT 80
#define BUFSIZE 1024
//linux下的編譯方法 gcc -o sms sms.c
int main(int argc, char **argv)
{
int sockfd, ret, i, h,srandnum;
struct sockaddr_in servaddr;
char str1[4096], str2[4096], buf[BUFSIZE], *str;
socklen_t len;
fd_set t_set1;
struct timeval tv;
if ((sockfd = socket(AF_INET, SOCK_STREAM, 0)) < 0 ) {
printf("創(chuàng)建網(wǎng)絡(luò)連接失敗,本線程即將終止---socket error!\n");
exit(0);
};
bzero(&servaddr, sizeof(servaddr));
servaddr.sin_family = AF_INET;
servaddr.sin_port = htons(PORT);
if (inet_pton(AF_INET, IPSTR, &servaddr.sin_addr) <= 0 ){
printf("創(chuàng)建網(wǎng)絡(luò)連接失敗,本線程即將終止--inet_pton error!\n");
exit(0);
};
if (connect(sockfd, (struct sockaddr *)&servaddr, sizeof(servaddr)) < 0){
printf("連接到服務(wù)器失敗,connect error!\n");
exit(0);
}
printf("與遠(yuǎn)端建立了連接\n");
//發(fā)送數(shù)據(jù)
//用戶名是登錄用戶中心->語音通知->產(chǎn)品總覽->APIID
//查看密碼請(qǐng)登錄用戶中心->語音通知->產(chǎn)品總覽->APIKEY
memset(str2, 0, 4096);
strcat(str2, "account=用戶名&password=密碼&mobile=189xxxxxxxx&content=1125");
str=(char *)malloc(128);
len = strlen(str2);
sprintf(str, "%d", len);
memset(str1, 0, 4096);
strcat(str1, "POST /webservice/voice.php?method=Submit&format=json HTTP/1.1\n");
strcat(str1, "Host: api.vm.ihuyi.com\n");
strcat(str1, "Content-Type: application/x-www-form-urlencoded\n");
strcat(str1, "Content-Length: ");
strcat(str1, str);
strcat(str1, "\n\n");
strcat(str1, str2);
strcat(str1, "\r\n\r\n");
printf("%s\n",str1);
ret = write(sockfd,str1,strlen(str1));
if (ret < 0) {
printf("發(fā)送失敗!錯(cuò)誤代碼是%d,錯(cuò)誤信息是'%s'\n",errno, strerror(errno));
exit(0);
}else{
printf("消息發(fā)送成功,共發(fā)送了%d個(gè)字節(jié)!\n\n", ret);
}
FD_ZERO(&t_set1);
FD_SET(sockfd, &t_set1);
while(1){
sleep(2);
tv.tv_sec= 0;
tv.tv_usec= 0;
h = 0;
printf("--------------->1\r\n");
h = select(sockfd +1, &t_set1, NULL, NULL, &tv);
printf("--------------->2%d\r\n",h);
//if (h == 0) continue;//break;
if (h == 0) {
close(sockfd);
printf("連接關(guān)閉!\n");
return 1;
};
if (h < 0) {
close(sockfd);
printf("在讀取數(shù)據(jù)報(bào)文時(shí)SELECT檢測到異常,該異常導(dǎo)致線程終止!\n");
return -1;
};
if (h > 0){
memset(buf, 0, 4096);
i= read(sockfd, buf, 4095);
if (i==0){
close(sockfd);
printf("讀取數(shù)據(jù)報(bào)文時(shí)發(fā)現(xiàn)遠(yuǎn)端關(guān)閉,該線程終止!\n");
return -1;
}
printf("%s\n", buf);
}
}
close(sockfd);
return 0;
}
驗(yàn)證碼已發(fā)送到您的手機(jī),請(qǐng)查收!
輸入驗(yàn)證碼后,點(diǎn)擊“開通體驗(yàn)賬戶”按鈕可立即開通體驗(yàn)賬戶。