⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 send_single_wait.cpp

📁 SP平台联通短信群发程序
💻 CPP
字号:
//从文件中读取号码和内容,按条发送,插入到WAIT表中//格式: ./sendfree_all_wait 发送号码文件名 发送内容文件名 扣费代码 费率 每秒发送频次(按条收费,WAIT表)//例子:./sendfree_all_wait phone.txt nr.txt -XX 0.10 5#include <stdio.h>#include <string.h>#include <time.h>#include <stdlib.h>#include <sys/types.h>#include <sys/stat.h>#include <unistd.h>#include "../include/define.h"#include "../include/CMPPAPI.hpp"#include "mysql/mysql.h"#include "../include/sm_tools.h"#include "../include/sm_db.h"#define INIFILE "../config/sm.ini"char db_host[100],db_user[100],db_passwd[100],db_dbname[100];MYSQL *myconn;char *getfixdate(char *fixdatetime,int subtime,char *adddate){        time_t ftimer;        struct tm ftm;        struct tm *ltm;        char fixdate[20],fixtime[20],ndate[20];        int fday,ftime;                memset(ndate,0,sizeof(fixdatetime));        memset(fixdate,0,sizeof(fixdatetime));        memset(fixtime,0,sizeof(fixdatetime));        	strncpy(fixdate,fixdatetime,8);	strncpy(fixtime,fixdatetime+8,6);	fixdate[8]='\0';	fixtime[6]='\0';	fday=atoi(fixdate);	ftime=atoi(fixtime);        //printf("ftime%d\n",ftime);        ftm.tm_year=fday/10000 - 1900;	fday%=10000;	ftm.tm_mon=fday/100 - 1;        ftm.tm_mday=fday%100;        ftm.tm_hour=ftime/10000;        ftime%=10000;	ftm.tm_min=ftime/100;	ftm.tm_sec=ftime%100;	ftm.tm_isdst=0;		ftimer=mktime(&ftm);	ftimer+=subtime;	ltm = localtime(&ftimer);	sprintf(ndate,"%04d%02d%02d%02d%02d%02d",                ltm->tm_year + 1900,                ltm->tm_mon + 1,                ltm->tm_mday,                ltm->tm_hour,                ltm->tm_min,                ltm->tm_sec);        //printf("ndate=%s\n",ndate);        strcpy(adddate,ndate);        //puts(adddate);        return adddate;}static int InitPara(){	myconn = NULL;	GetProfileString(INIFILE,"DB_LOCAL","HOST","192.168.0.7",db_host);	GetProfileString(INIFILE,"DB_LOCAL","LOGNAME","dream",db_user);	GetProfileString(INIFILE,"DB_LOCAL","LOGPASS","",db_passwd);	GetProfileString(INIFILE,"DB_LOCAL","DBNAME","NW_SM_TEST",db_dbname);	return 0;}int main(int argc,char *argv[]){	char *day;	char filename[100],file_nr[100],begin_date[20],sv_code[100],sql[500];	char dcode[30];	char msisdn[30];	char context[1000];	FILE *fp;	int len,i,n,k,retval;	int times;	float fee;	MYSQL_ROW row;	MYSQL_RES *res = NULL;		SEND_STRUC sendstruc;	i=0;n=0;k=0;	puts("start");	InitPara();		puts(db_dbname);	puts("end");	if(argc<7)	{		printf("格式:%s 号码文件名 发送内容 业务代码 费率 每秒发送频次 指定发送开始时间(按条收费,WAIT表)\n",argv[0]);		return 0;	}	else	{		strcpy(filename,argv[1]);		strcpy(file_nr,argv[2]);		strcpy(dcode,argv[3]);		fee=atof(argv[4]);		times=atoi(argv[5]);		strcpy(begin_date,argv[6]);		puts(begin_date);		printf("the dcode is %s, fee is %f\n",dcode,fee);		if (strlen(begin_date)!=14 || strncmp(begin_date,"20",2)<0)		{			puts("begin_date must be 14 byte, like as 20031028051201");			return 0;		}			}	fp = fopen(file_nr,"rb");	if(fp == NULL)	{		puts("打开发送内容文件失败!");		return 0;	}	len = fread(context,1,999,fp);	context[len] = '\0';		printf("content len:%d\n",len);	fclose(fp);		if(len>500)	{		puts("你的发送内容已超过500个字节,请查实后再发");		return 0;	}	memset(&sendstruc,0,sizeof(sendstruc));	sendstruc.nNeedReply = NEED_REPLY_NO;	sendstruc.nMsgLevel = 5;	strcpy(sendstruc.sServiceID,dcode);	sendstruc.nMsgFormat = 15;	strcpy(sendstruc.sFeeType,"02");	sendstruc.sFeeCode = fee;	strcpy(sendstruc.sValidTime,"");	strcpy(sendstruc.sAtTime,"");	strcpy(sendstruc.sSrcTermID,"8566");	sendstruc.cFeeUserType=0;	strcpy(sendstruc.sFeeTerminalID,"");	sendstruc.cTpPid = 0;	sendstruc.cTpUdhi = 0;	strcpy(sendstruc.step,"0");	strcpy(sendstruc.sMsgContent,context);		fp = fopen(filename,"r");	if(fp == NULL)	{		puts("open file error!");		return 0;	}	myconn = dbconnect(db_host,db_user,db_passwd,db_dbname);	if(myconn == NULL)	{		puts("连接数据库失败,请查看日志文件!");		return 0;	}	while(fgets(msisdn,30,fp)!=NULL)	{		msisdn[11] = '\0';		if(strncmp(msisdn,"13",2)!=0 || strlen(msisdn)!=11) continue;								strcpy(sendstruc.sDesTermID,msisdn);			getfixdate(begin_date,i,sendstruc.Send_Date);			//getadddate(sendstruc.Send_Date,i);			if(k>=times)			{				i++;				k=0;			}    			SendMsg_Wait(&sendstruc,&myconn);    			strcpy(msisdn,"");    			k++;			n++;			if(n%1000==0)			{				printf("%d\n",n);			}	}		printf("the total num you send is :%d\n",n);	puts(sendstruc.Send_Date);	fclose(fp);		return 0;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -