📄 gpms.cpp
字号:
// 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"
#include "md5a.h"
#include "Xml\Packet.h"
using namespace std;
BOOL APIENTRY DllMain( HANDLE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved
)
{
return TRUE;
}
char * UCase(const char * s);
char * RSapce(const char * s, bool bLeft);
int AnalyStock(const char * s, string & , int & ) ; //股票关键字解析
int AnalyWeather(const char * s , string &) ; //天气关键字解析
bool IsDigit(const char * s);
int Analyse(const string &sTelCode, const string &sMobile, string &strContent ,const string &sLinkID , string &sSender, const string strContentOrigin );
int IACShell(const string &, const string &, string & ,const string & , string &); //互动
int AnalyseStock(const char * szStock , string & ) ;
int AnalyseWeather(const char * szWeather);
int AnalyseXiabanFun(const string & sMobile, string &strContent ,const string & sLinkID ,string &sSender, const string strContentOrigin );
//调用下班网接口返回值来处理平台的信息
int XiabanInterface(const char * szTelCode, const string strMobile, string &strContent, const string strLinkID, string &strSender, int iType);
//增加回调接口:IACCB
//typedef int(*IACCallBack)(const char *szTelCode, const char *szMobile, char **sContent ,const char *szLinkID , char **sSender) ; // 声明CallBack 类型的函数指针
string g_strTelCode ;
AdoSQL *pAdoSQL ;
//extern "C" _declspec(dllexport) int __stdcall IACCB(IACCallBack IacCB,const char *szTelCode, const char *szMobile, char **sContent ,\
// const char *szLinkID , char **sSender)
//
//{
// int i = IacCB(szTelCode, szMobile, sContent , szLinkID , sSender);
// return i;
//}
//_declspec(dllexport)
//extern "C" int __stdcall
extern "C" _declspec(dllexport) int __stdcall IAC(const char *szTelCode, const char *szMobile, char **sContent ,\
const char *szLinkID , char **sSender)
{
::CoInitialize(NULL);
int ilen =0;
ilen =strlen(szTelCode);
if( 0 == ilen )
return -1;
g_strTelCode = szTelCode ;
ilen = strlen(szMobile);
if ( 0 == ilen )
return -1;
string strContentOrigin = *sContent ;
strContentOrigin = RSapce(strContentOrigin.c_str(), true);
string strContent = *sContent ;
string strSender = *sSender ;
strContent = UCase(strContent.c_str());
strContent =RSapce(strContent.c_str(), true);
ilen = strContent.length();
int ilenS;
ilenS =strSender.length() ;
if( 0 == ilen && 0 == ilenS )
return -1;
Log("ParameterIn: Content=%s,Sender=%s",strContent.c_str(), strSender.c_str());
//如果sSender不为空并且不为数字则处理下一个业务
if( ilenS !=0 && IsDigit(strSender.c_str()))
{
int strLen = strSender.length();
if (strLen < 2)
{
return -1;
}
if ("90"==strSender.substr(0,2))
{
if( "2" == strContent.substr(0,1))
{
//调用获取商家ID过程 Pro_IAC_GetBiz_Shell
pAdoSQL = new AdoSQL();
int iBizID, RetVal;
if( pAdoSQL->ExcuSP_Pro_IAC_GetBiz_Shell(szTelCode, szMobile, strContent, szLinkID,strSender,iBizID, RetVal))
{
if( 1== RetVal)
{
char buffer[20] ={0};
_itoa( iBizID, buffer, 10 );
strContent = "WapPush" ;
strContent += buffer ;
if(!pAdoSQL->Excu_CTSI_SMS_Insert_Shell_IAC(szLinkID , szMobile , strContent ))
{
return -1;
}
}
strcpy(*sContent , strContent.c_str());
strcpy(*sSender , strSender.c_str());
Log("ParameterOut: Content=%s,Sender=%s",strContent.c_str(), strSender.c_str());
return 0;
}
}
else if( "3" == strContent.substr(0,1))
{
int iRet = XiabanInterface(szTelCode, szMobile, strContent, szLinkID, strSender, 90);
strcpy(*sContent , strContent.c_str());
strcpy(*sSender , strSender.c_str());
Log("ParameterOut: Content=%s,Sender=%s",strContent.c_str(), strSender.c_str());
return iRet;
}
else
{
int iRet = IACShell(szTelCode, szMobile, strContent ,szLinkID , strSender);
strcpy(*sContent , strContent.c_str());
strcpy(*sSender , strSender.c_str());
Log("ParameterOut: Content=%s,Sender=%s",strContent.c_str(), strSender.c_str());
return iRet;
}
}
else if ("80"==strSender.substr(0,2))
{
int iRet = XiabanInterface(szTelCode, szMobile, strContent, szLinkID, strSender, 80);
strcpy(*sContent , strContent.c_str());
strcpy(*sSender , strSender.c_str());
Log("ParameterOut: Content=%s,Sender=%s",strContent.c_str(), strSender.c_str());
return iRet;
//调用:CTSI_SMS_Insert_Shell_IAC
//CMd5A md5;
//char* cResultString;
//cResultString=md5.MDString((char *)szMobile);
////在回复内容前增加前缀:"XBK"+" "+"mobile的md5"
//string strTmp = "XBK ";
//strTmp += cResultString;
//strTmp += strContent;
//strContent = strTmp ;
//pAdoSQL->Excu_CTSI_SMS_Insert_Shell_IAC(szLinkID, szMobile, strContent);
//strcpy(*sContent , strContent.c_str());
}
//int iRet = IACShell(szTelCode, szMobile, strContent ,szLinkID , strSender);
////*sContent =(char *) strContent.c_str() ;
////*sSender = (char *) strSender.c_str() ;
//strcpy(*sContent , strContent.c_str());
//strcpy(*sSender , strSender.c_str());
//return iRet;
}
else
{
int iRet = Analyse(szTelCode, szMobile, strContent ,szLinkID , strSender, strContentOrigin);
strcpy(*sContent , strContent.c_str());
strcpy(*sSender , strSender.c_str());
Log("ParameterOut: Content=%s,Sender=%s",strContent.c_str(), strSender.c_str());
return iRet;
}
::CoUninitialize();
return 1;
}
int AnalyseStock(const char * szStock , string &strGet )
{
try
{
if ( 0 == strlen(szStock) )
{
strGet ="找不到该股票或连接服务器失败,请确认代码是否正确。";
return 0;
}
if(!getHTTPFile(szStock , strGet, 80) )
{
Sleep(10);
strGet ="格式错误.查个股格式:股票/GP/Stock+代码(如:GP000100);查指数格式:上证/上证指数/深证/深证指数.";
return 0;
}
Extract extract;
extract.funProcess(strGet);
}
catch(MyException e)
{
Log("Get Data From Web Error!");
return -1;
}
return 1;
}
int Analyse(const string &sTelCode, const string &sMobile, string &strContent ,\
const string &sLinkID , string &sSender,const string strContentOrigin)
{
int i =0;
string strContentTmp = "";
string strGet = "";
int iRetType = 0;
//i = AnalyStock(strContent.c_str(), strContentTmp);
int iRet ;
if( (i = AnalyseXiabanFun(sMobile.c_str(), strContent, sLinkID.c_str(), sSender, strContentOrigin)) != -1)
{
return 1;
}
else 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;
}
//执行股票相
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 )
{
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;
}
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, bool bLeft )
{
register int x ,y ;
int len;
unsigned char *str;
//bool bLeft = true;
len = strlen(s);
str = (unsigned char *) new char[ len + 1];
if(str == NULL){
return NULL;
}
if (bLeft)
{
for (x = 0 ,y =0; x < len ; x++ )
{
char szT = (unsigned char) s[x];
if (szT == 32 && bLeft )
{
;
}
else
{
str[y] = szT ;
y++ ;
bLeft = false;
}
}
}
else
{
for (x = 0 ,y =0; x < len ; x++ )
{
char szT = (unsigned char) s[x];
if (szT == 32 )
{
;
}
else
{
str[y] = szT ;
y++ ;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -