📄 gpms.cpp.bak.bak
字号:
// GPMS.cpp : 定义 DLL 应用程序的入口点。
//
#define GPMSDLL_API extern "C" _declspec(dllexport)
#include "stdafx.h"
#include <string>
//#include "Gpms.h"
#include "GPMSProcer.h"
#include "HttpRequest.h"
#include "Extract.h"
#include "AdoSQL.h"
using namespace std;
BOOL APIENTRY DllMain( HANDLE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved
)
{
return TRUE;
}
// 返回结果
// 类型:Int
// 值定义: 1: 正常
// -1:异常(转处理:在网站查询相应信息)
//Mobile:手机号码
//TelCode:所在地(0592/592)
//Content:内容 (股票/gp/stock/上证/上证指数/深证/深证指数)分析是否为股票 \
(天气/tq/今天天气/明天天气/后天天气/今日天气/明日天气/后日天气)分析是否为天气
//LinkID:通过这个ID可以免费下行一条
//Sender:通过这个实现互动,可匹配详细的互动栏目
char * UCase(const char * s);//如果是小写字母则转为大写
char * RSapce(const char * s);
int AnalyStock(const char * s, string & , int & ) ; //股票关键字解析
int AnalyWeather(const char * s , string &) ; //天气关键字解析
bool IsDigit(const char * s); //判断字符串中是否有字母,如有则返回false ,纯数字返回true
//int Analyse(string & );
int Analyse(const string &sTelCode, const string &sMobile, string &strContent ,const string &sLinkID , string &sSender);
int IACShell(const string &, const string &, string & ,const string & , string &); //互动
int AnalyseStock(const char * szStock , string & ) ;
int AnalyseWeather(const char * szWeather);
string g_strTelCode ;
extern "C" int __stdcall IAC(const string sTelCode, const string sMobile, string *sContent ,\
const string sLinkID , string *sSender)
{
int ilen =0;
ilen =sTelCode.length();
if( 0 == ilen )
return -1;
g_strTelCode = sTelCode ;
ilen = sMobile.length();
if ( 0 == ilen )
return -1;
//把sContent字母的转成大写
sContent = UCase(sContent->c_str());
sContent =RSapce(sContent->c_str());
ilen = sContent.length();
int ilenS = sSender.length();
if( 0 == ilen && 0 == ilenS )
return -1;
//如果sSender不为空并且不为数字则处理下一个业务
if( ilenS !=0 && IsDigit(sSender.c_str()))
{
//转到互动处理
int iRet = IACShell(sTelCode, sMobile, sContent ,sLinkID , sSender);
return iRet;
}
else
{
int iRet = Analyse(sTelCode, sMobile, sContent ,sLinkID , sSender);
return iRet;
}
return 1;
}
int AnalyseStock(const char * szStock , string &strGet )
{
//char szWebFile[50]={0};
//string strGet ="";
//sprintf(szWebFile , "http://quote.jrj.com.cn//htmdata/html/%s.htm",szStock );
//if(!getHTTPFile("http://quote.jrj.com.cn//htmdata/html/000100.htm" , strGet, 80) )
try
{
if ( 0 == strlen(szStock) )
{
strGet ="找不到该股票或连接服务器失败,请确认代码是否正确。";
return 0;
}
if(!getHTTPFile(szStock , strGet, 80) )
{
Sleep(10);
strGet ="找不到该股票或连接服务器失败,请确认代码是否正确。";
return 0;
}
Extract extract;
extract.funProcess(strGet);
}
catch(MyException e)
{
Log("Get Data From Web Error!");
return -1;
}
return 1;
}
//int Analyse(string &strContent )
int Analyse(const string &sTelCode, const string &sMobile, string &strContent ,\
const string &sLinkID , string &sSender)
{
int i =0;
string strContentTmp = "";
string strGet = "";
int iRetType = 0;
//i = AnalyStock(strContent.c_str(), strContentTmp);
int iRet ;
if ( (i = AnalyStock(strContent.c_str(), strContentTmp , iRetType)) != -1 )
{
iRet = AnalyseStock(strContentTmp.c_str() , strGet );
int ilen = strGet.length();
if ( 0 == ilen )
{
strContent ="您所所输入的股票代码不对或者为空!";
return -1;
}
//执行股票相 //股票/gp/stock/上证/上证指数/深证/深证指数
if( !iRet)
{
strContent = strGet;
return iRet;
}
else
{
//int iPos = strGet.find(strContentTmp.c_str());
//if (iPos > 0 )
if ( 1 == iRetType)
strGet = strGet.substr(1);
char array[39][10] ={0};
//v[0..38]
char *temp ;
temp = (char *)strtok(( char*)strGet.c_str() ,",");
int i=0;
while(temp != NULL)
{
strcpy(array[i++], temp);
//Log("array[%d] = %s\n",i-1,array[i-1]);
temp = (char *)strtok(NULL,",");
}
//修改传递进来的strContent值
char szTemp[150] ={0};
if (1 == iRetType)
{
sprintf(szTemp , "[%s][%s],成交:%s,涨跌:%s,幅度:%s,总手:%s,金额:%s.", array[0],array[2], \
array[3], array[5], array[6], array[8] ,array[9]);
}
else if (2 == iRetType)
{
int iPos = strContent.find("指数");
if(iPos < 0 )
strContent += "指数";
sprintf(szTemp , "%s[%s]:%s,涨跌幅:%s,涨跌比:%s,金额:%s亿,总手:%s万.",strContent.c_str(), array[1],array[0], \
array[2], array[3], array[4], array[5] );
}
strContent = szTemp;
}
return iRet;
}
else if( (iRet = AnalyWeather(strContent.c_str(), strContentTmp)) != -1 )
{
//执行天气相关 /天气/tq/今天天气/明天天气/后天天气/今日天气/明日天气/后日天气
/*返回值0 全部
1 今天/今日
2 明天/明日
3 后天/后日*/
string strRetInfo;
i = strContentTmp.length();
AdoSQL *pAdoSQL ;
pAdoSQL = new AdoSQL();
if( 0 == i)
strContentTmp = g_strTelCode;
char const *s = strContentTmp.c_str();
unsigned char szT = (unsigned char) s[0];
if ( szT < 0xa1)
{
pAdoSQL->ExucteSP_Weather( strContentTmp.c_str() , " ",iRet, strRetInfo);
}
else
{
pAdoSQL->ExucteSP_Weather( " ", strContentTmp.c_str() ,iRet, strRetInfo);
}
strContent = strRetInfo; //返回天气的查询结果
return 1;
}
else
{
//转到互动处理
iRet = IACShell(sTelCode, sMobile, strContent ,sLinkID , sSender);
return iRet;
}
return 0;
}
//字符串中是否为全数字.如果含有字母则返加false
bool IsDigit(const char * s)
{
register int x ;
int len;
len = strlen(s);
unsigned char szTemp;
for (x = 0 ; len--; x++ )
{
szTemp = (unsigned char) s[x];
if (szTemp <= '9' && szTemp >= '0')
;
else
return false ;
}
return true;
}
//小写字母转大写
char * UCase(const char * s)
{
register int x ;
int len;
unsigned char *str;
len = strlen(s);
str = (unsigned char *) new char[ len + 1];
if(str == NULL){
return NULL;
}
for (x = 0 ; len--; x++ )
{
str[x] = (unsigned char) s[x];
if (str[x] <= 'z' && str[x] >= 'a')
{
str[x] = str[x] - 32;
}
else
str[x] = str[x] ;
}
str[x] = '\0';
return ((char *) str);
}
//字符串的空格替换
char * RSapce(const char * s)
{
register int x ,y ;
int len;
unsigned char *str;
len = strlen(s);
str = (unsigned char *) new char[ len + 1];
if(str == NULL){
return NULL;
}
for (x = 0 ,y =0; x < len ; x++ )
{
char szT = (unsigned char) s[x];
if (szT == 32 )
{
;
}
else
{
str[y] = szT ;
y++ ;
}
}
str[y] = '\0';
return ((char *) str);
}
//股票关键字解析
int AnalyStock(const char * s, string & retStockStr , int & iType )
{
string sStock = s;
int len = sStock.length();
if(0 == len){
return 0;
}
static const basic_string <char>::size_type npos = -1;//cannot be found
basic_string <char>::size_type ret1=sStock.find("GP");
basic_string <char>::size_type ret2=sStock.find("gp");
basic_string <char>::size_type ret3=sStock.find("STOCK");
basic_string <char>::size_type ret4=sStock.find("stock");
basic_string <char>::size_type ret5=sStock.find("股票");
basic_string <char>::size_type ret6=sStock.find("上证指数");
basic_string <char>::size_type ret7=sStock.find("上证");
basic_string <char>::size_type ret8=sStock.find("深证指数");
basic_string <char>::size_type ret9=sStock.find("深证");
char szWebFile[50] ={0};
if( ret1 != npos )
{
retStockStr = sStock ;
retStockStr.replace(ret1,2,"");
sprintf(szWebFile , "http://quote.jrj.com.cn//htmdata/html/%s.htm",retStockStr.c_str() );
retStockStr = szWebFile;
iType = 1 ;
return 1;
}
else if(ret2 != npos )
{
retStockStr = sStock ;
retStockStr.replace(ret2,2,"");
sprintf(szWebFile , "http://quote.jrj.com.cn//htmdata/html/%s.htm",retStockStr.c_str() );
retStockStr = szWebFile;
iType = 1 ;
return 1;
}
else if(ret3 != npos )
{
retStockStr = sStock ;
retStockStr.replace(ret3,5,"");
sprintf(szWebFile , "http://quote.jrj.com.cn//htmdata/html/%s.htm",retStockStr.c_str() );
retStockStr = szWebFile;
iType = 1 ;
return 1;
}
else if(ret4 != npos )
{
retStockStr = sStock ;
retStockStr.replace(ret4,5,"");
sprintf(szWebFile , "http://quote.jrj.com.cn//htmdata/html/%s.htm",retStockStr.c_str() );
retStockStr = szWebFile;
iType = 1 ;
return 1;
}
else if(ret5 != npos )
{
retStockStr = sStock ;
retStockStr.replace(ret5,4,"");
sprintf(szWebFile , "http://quote.jrj.com.cn//htmdata/html/%s.htm",retStockStr.c_str() );
retStockStr = szWebFile;
iType = 1 ;
return 1;
}
else if( ret6 != npos )
{
retStockStr = sStock ;
//retStockStr.replace(ret6,8,""); //上证指数
retStockStr ="http://quote.jrj.com.cn/htmdata/html/03.htm";
iType = 2 ;
return 1;
}
else if(ret7 != npos )
{
retStockStr = sStock ;
//retStockStr.replace(ret7,4,""); //上证
retStockStr ="http://quote.jrj.com.cn/htmdata/html/03.htm";
iType = 2 ;
return 1;
}
else if(ret8 != npos )
{
retStockStr = sStock ;
//retStockStr.replace(ret8,8,""); //深证指数
retStockStr ="http://quote.jrj.com.cn/htmdata/html/04.htm";
iType = 2 ;
return 1;
}
else if(ret9 != npos )
{
retStockStr = sStock ;
//retStockStr.replace(ret9,4,""); //深证
retStockStr ="http://quote.jrj.com.cn/htmdata/html/04.htm";
iType = 2 ;
return 1;
}
else
return -1;
}
//天气关键字解析
int AnalyWeather(const char * s , string &strWheather)
{
string sStock = s;
int len = sStock.length();
if(0 == len)
{
return 0;
}
static const basic_string <char>::size_type npos = -1;//cannot be found
basic_string <char>::size_type ret1=sStock.find("TQ");
basic_string <char>::size_type ret2=sStock.find("tq");
basic_string <char>::size_type ret3=sStock.find("今天天气");
basic_string <char>::size_type ret4=sStock.find("明天天气");
basic_string <char>::size_type ret5=sStock.find("后天天气");
basic_string <char>::size_type ret6=sStock.find("今日天气");
basic_string <char>::size_type ret7=sStock.find("明日天气");
basic_string <char>::size_type ret8=sStock.find("后日天气");
basic_string <char>::size_type ret9=sStock.find("天气");
if( ret1 != npos )
{
strWheather = sStock ;
strWheather.replace(ret1,2,""); //TQ
return 0;
}
else if(ret2 != npos )
{
strWheather = sStock ;
strWheather.replace(ret2,2,""); //tq
return 0;
}
else if(ret3 != npos )
{
strWheather = sStock ;
strWheather.replace(ret3,8,""); //今天天气
return 1;
}
else if(ret4 != npos )
{
strWheather = sStock ;
strWheather.replace(ret4,8,""); //明天天气
return 2;
}
else if(ret5 != npos )
{
strWheather = sStock ;
strWheather.replace(ret5,8,""); //后天天气
return 3;
}
else if( ret6 != npos )
{
strWheather = sStock ;
strWheather.replace(ret6,8,"");
return 1;
}
else if(ret7 != npos )
{
strWheather = sStock ;
strWheather.replace(ret7,8,"");
return 2;
}
else if(ret8 != npos )
{
strWheather = sStock ;
strWheather.replace(ret8,8,""); //后日天气
return 3;
}
else if(ret9 != npos )
{
strWheather = sStock ;
strWheather.replace(ret9,4,""); //天气
return 0;
}
else
return -1;
}
//Pro_IAC_Shell
//create procedure dbo.Pro_IAC_Shell(
//@Mobile varchar(20) output,
//@TelCode varchar(10) output,
//@Content varchar(200) output,
//@LinkID varchar(50) output,
//@Sender varchar(20) output,
//@ReturnValue int output
//)
int IACShell(const string & sTelCode , const string & sMobile, string &strContent ,\
const string & sLinkID, string &sSender)
//(sTelCode, sMobile, strContent ,sLinkID , sSender)
{
AdoSQL *pAdoSQL ;
pAdoSQL = new AdoSQL();
int iRet =0;
if(pAdoSQL->ExcuteIACShell(sTelCode.c_str() ,sMobile.c_str() , strContent ,sLinkID.c_str(), sSender, iRet))
return iRet;
else
return -1 ;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -