📄 send_all_mon_wait.cpp
字号:
//本程序用于对所有包月用户进行包月扣费,参数有:号码文件名 业务代码 费用 每秒发送频次(包月扣费,WAIT表)//发送格式:./send_all_mon_wait 发送号码文件名 业务代码 费用 每秒发送频次 指定发送开始时间(包月扣费,WAIT表)#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;//fixdatetime为指定的时间,subtime为间隔时间,adddate为得到的时间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); fixdate[8]='\0'; strncpy(fixtime,fixdatetime+8,6); 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","localhost",db_host); GetProfileString(INIFILE,"DB_LOCAL","LOGNAME","root",db_user); GetProfileString(INIFILE,"DB_LOCAL","LOGPASS","",db_passwd); GetProfileString(INIFILE,"DB_LOCAL","DBNAME","NW_SM",db_dbname); return 0;}int main(int argc,char *argv[]){ char *day; FILE *fp; char filename[100],sv_code[100],begin_date[20]; double fee; char msisdn[30]; int i,k,n; int times; SEND_STRUC sendstruc; InitPara(); puts(db_dbname); if(argc<6) { printf("格式:%s 号码文件名 业务代码 费用 每秒发送频次 指定发送开始时间(包月扣费,WAIT表)\n",argv[0]); return 0; } else { strcpy(filename,argv[1]); strcpy(sv_code,argv[2]); fee = atof(argv[3]); times=atoi(argv[4]); strcpy(begin_date,argv[5]); puts(begin_date); if (strlen(begin_date)!=14 || strncmp(begin_date,"20",2)<0) { puts("begin_date must be 14 byte, like as 20031028051201"); return 0; } } memset(&sendstruc,0,sizeof(sendstruc)); sendstruc.nNeedReply = 2; sendstruc.nMsgLevel = 8; strcpy(sendstruc.sServiceID,sv_code); sendstruc.nMsgFormat = 15; strcpy(sendstruc.sFeeType,"03"); 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"); day = getnowdate(sendstruc.Send_Date); strcpy(sendstruc.sMsgContent,"aaaa"); 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; } i=0;k=0;n=0; while(fgets(msisdn,30,fp)!=NULL) { msisdn[11] = '\0'; if (strncmp(msisdn,"13",2)!=0 || strlen(msisdn)!=11) continue; strcpy(sendstruc.sDesTermID,msisdn); //getadddate(sendstruc.Send_Date,i); getfixdate(begin_date,i,sendstruc.Send_Date); //puts(sendstruc.Send_Date); if(k>=times) { i++; k=0; } SendMsg_Wait(&sendstruc,&myconn); strcpy(msisdn,""); k++; n++; if(n%1000==0) { printf("%d\n",n); } } fclose(fp); puts(sendstruc.Send_Date); printf("you have send %d records\n",n); return 0; }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -