示例#1
0
static int lua_iso8583_unpack(lua_State *L)
{
	iso8583_userdata *iso8583u;
	unsigned char *iso8583_data;
	unsigned int iso8583_size;
	size_t data_len;
	char error[BUFSIZ];
	unsigned int i;
	int n = lua_gettop(L);

	if (n < 2) {
		lua_pushnil(L);
		lua_pushstring(L, "arguments error! too small!");
		return 2;
	}

	iso8583u = (iso8583_userdata *)luaL_checkudata(L, 1, "iso8583");

	if (!lua_isstring(L, 2)) {
        lua_pushnil(L);
        lua_pushstring(L, "argument error! data must be string!");
        return 2;
    }

	iso8583_data = (unsigned char *)lua_tolstring(L, -1, &data_len);

	iso8583_size = (unsigned int)data_len;

	if (iso8583_unpack(iso8583u->handle, iso8583_data, &iso8583_size) != ISO8583_OK) {
		lua_pushnil(L);
		snprintf(error, BUFSIZ, "unpack iso8583 error! %s", iso8583u->handle->error);
		lua_pushstring(L, error);
		return 2;
	}

	lua_createtable (L, 129, 0);

	for (i = 0; i < 129; i++) {
		const unsigned char *user_data;
		unsigned int user_size;

		if (iso8583_get(iso8583u->handle, i, &user_data, &user_size) != ISO8583_OK) {
			lua_pushnil(L);
			snprintf(error, BUFSIZ, "unpack iso8583 error! %s", iso8583u->handle->error);
			lua_pushstring(L, error);
			return 2;
		}

		if (user_data && user_size) {
			lua_pushinteger(L, (int)i);
			lua_pushlstring(L, (const char *)user_data, user_size);

			lua_settable (L, -3);
		}
	}

	lua_pushinteger(L, (int)iso8583_size);

	return 2;
}
示例#2
0
void main()
{
	typedef unsigned char* P_UBYTE;
	char buf1[100] = {0};
	ISO_MSG isomsg;/*[] = {{4, (unsigned char*)"\0"}, {8, (unsigned char*)"80000000"}, {4, (unsigned char*)"1234"}};*/
	iso8583_init(&isomsg);
	iso8583_set(&isomsg, 0, (P_UBYTE)"\0" , 4);
	iso8583_set(&isomsg, 1, (P_UBYTE)"  " , 8);
	iso8583_set(&isomsg, 2, (P_UBYTE)"ab1" , 22);
	iso8583_set(&isomsg, 10, (P_UBYTE)"defg12345" , 8);
	iso8583_pack(&isomsg, buf1);
	//iso8583_free(&isomsg);
	iso8583_init(&isomsg);
	iso8583_unpack(&isomsg, buf1);
	puts(buf1);
}
示例#3
0
int Bank_Query(TRUSERID *handle,ST_PACK *rPack,int *pRetCode,char *szMsg)
{

	int ret=0;
	int amt=0;
	double amt1=0.0;
	char temp[256]="";
	ST_CPACK aPack;	
	ST_PACK *out_pack = &(aPack.pack);
	ResetNormalCPack(&aPack,0,1);
	SetCol(handle,0);
	SetCol(handle,F_LVOL1,F_DAMT0,0);

	MSG8583 zgyh_req,zgyh_ans;
	memset(&zgyh_req,0x20,sizeof zgyh_req);
	memset(&zgyh_ans,0x20,sizeof zgyh_ans);

	ISO_MSG iso_zgyh_req,iso_zgyh_ans;
	iso8583_init(&iso_zgyh_req);
	iso8583_init(&iso_zgyh_ans);

	char zgyh_sbuf[2048]="";
	char zgyh_abuf[2048]="";

	char buf[2048]="";
	char bitmap[16]={0x60,0x20,0x00,0x00,0x20,0xc0,0x10,0x04};
	
	if(strlen(rPack->vsvarstr1)>0)	bitmap[4]=0x30;	//如果三磁道信息为空,三磁道的位图置空

	ret=iso8583_set(&iso_zgyh_req, 0, (unsigned char*)BANK_ZGYH_TRADE_CODE_QUERY_REQ, 4);
	if(ret<=0)
	{
		writelog(LOG_ERR,"iso8583_set error");
		return E_TRANS_UNKNOW_ERROR;
	}
	ret=iso8583_set(&iso_zgyh_req, 1, (unsigned char*)bitmap,8);
	if(ret<=0)
	{
		writelog(LOG_ERR,"iso8583_set error");
		return E_TRANS_UNKNOW_ERROR;
	}
	//写银行卡号
	memset(buf,0x00,sizeof buf);
	sprintf(buf,"%02d",strlen(rPack->scust_limit2));
	sprintf(buf+2,"%s",rPack->scust_limit2);
	ret=iso8583_set(&iso_zgyh_req, 2, (unsigned char*)rPack->scust_limit2,strlen(rPack->scust_limit2));
	if(ret<=0)
	{
		writelog(LOG_ERR,"iso8583_set error,rPack->scust_limit2=[%s]",rPack->scust_limit2);
		return E_TRANS_UNKNOW_ERROR;
	}
	//写银行处理代码-000000    3	处理代号		n6	 ME	  ME	(BCD)000000
	ret=iso8583_set(&iso_zgyh_req, 3, (unsigned char*)BANK_ZGYH_EXEC_CODE_QUERY_REQ, 6);
	if(ret<=0)
	{
		writelog(LOG_ERR,"iso8583_set error");
		return E_TRANS_UNKNOW_ERROR;
	}

	//写交易参考号-流水号-取交易参考号的后六位- 11 	系统跟踪号		n6	 ME	  ME	(BCD)
	memset(buf,0x00,sizeof buf);
	sprintf(buf,"%s",rPack->sholder_ac_no+8);
	ret=iso8583_set(&iso_zgyh_req,11,(unsigned char*)buf,6);
	if(ret<=0)
	{
		writelog(LOG_ERR,"iso8583_set error");
		return E_TRANS_UNKNOW_ERROR;
	}
	//写二磁道数据- 35	第二磁道数据	LLVAR	z..37	 C2		(BCD)
	ret=iso8583_set(&iso_zgyh_req,35,(unsigned char*)rPack->vsvarstr0,strlen(rPack->vsvarstr0));
	if(ret<=0)
	{
		writelog(LOG_ERR,"iso8583_set error,Second track data=[%s]",rPack->vsvarstr0);
		return E_TRANS_UNKNOW_ERROR;
	}
	//写三磁道数据- 36	第三磁道数据	LLLVAR	z..104	 C2		(BCD)
	if(strlen(rPack->vsvarstr1)>0)
	{
		ret=iso8583_set(&iso_zgyh_req,36,(unsigned char*)rPack->vsvarstr1,strlen(rPack->vsvarstr1));
		if(ret<=0)
		{
			writelog(LOG_ERR,"iso8583_set error,Second track data=[%s]",rPack->vsvarstr1);
			return E_TRANS_UNKNOW_ERROR;
		}
	}
	//写终端号- 41	POS终端号		ans8	 ME	  ME	(ASCII)
	ret=iso8583_set(&iso_zgyh_req,41,(unsigned char*)rPack->sorder2,8);
	if(ret<=0)
	{
		writelog(LOG_ERR,"iso8583_set error");
		return E_TRANS_UNKNOW_ERROR;
	}
	//写商户号- 42	商户号		ans15	 M		(ASCII)
	memset(buf,0,sizeof buf);
	sprintf(buf,"%s",BANK_ZGYH_MERCH_NO);
	ret=iso8583_set(&iso_zgyh_req,42,(unsigned char*)buf,15);
	if(ret<=0)
	{
		writelog(LOG_ERR,"iso8583_set error");
		return E_TRANS_UNKNOW_ERROR;
	}
	//写银行卡个人密码- 52	个人密码信息包	BIN	b64	 C3		ANSI X9.8标准Format 01
	ret=iso8583_set(&iso_zgyh_req,52,(unsigned char*)rPack->sbank_pwd,8);
	if(ret<=0)
	{
		writelog(LOG_ERR,"iso8583_set error");
		return E_TRANS_UNKNOW_ERROR;
	}
	//写交易参考号-  62	发票号	LLLVAR	ans999	 M		(ASCII)
	memset(buf,0x00,sizeof buf);
	sprintf(buf,"%s",rPack->sholder_ac_no+8);
	ret=iso8583_set(&iso_zgyh_req,62,(unsigned char*)buf,6);
	if(ret<=0)
	{
		writelog(LOG_ERR,"iso8583_set error");
		return E_TRANS_UNKNOW_ERROR;
	}
	
	ret=iso8583_pack(&iso_zgyh_req, zgyh_sbuf);
	if(ret<=0)
	{
		writelog(LOG_ERR,"Pack8583 error,errcode=[%d]",ret);
		return E_TRANS_UNKNOW_ERROR;
	}
	//memset(temp,0x00,sizeof temp);
	//des2src(temp,rPack->scust_auth);
	//ret=send_to_and_recv_from_bank((char *)zgyh_sbuf,ret,(char*)zgyh_abuf,200,(char*)temp,rPack->lvol0,rPack->lvol1);
	if(ret)
	{
		writelog(LOG_ERR,"send_to_and_recv_from_bank error,bank_id=[%d],errcode=[%d]",BANK_GSYH,ret);
		return E_TRANS_BANK_NOANSWER;
	}
	
	ret=iso8583_unpack(&iso_zgyh_ans, zgyh_abuf);
	if(ret<0)
	{
		writelog(LOG_ERR,"UnPack8583 error,errcode=[%d]",ret);
		return E_TRANS_UNKNOW_ERROR;
	}
	if(0!=strncmp((char *)iso_zgyh_ans.fld[39].buf,"00",2))
	{
		writelog(LOG_ERR,"Receive data return code error,error code= [%2.2s] ",iso_zgyh_ans.fld[39].buf);
		memcpy(temp,iso_zgyh_ans.fld[39].buf,2);
		temp[2]=0;
		switch(atoi(temp))
		{
			case 41:		//银行卡挂失
				//sprintf(pNode->RetCode,"%d",E_TRANS_BANKCARD_LOST);
				return	E_TRANS_BANKCARD_LOST;
			case 36:		//银行卡状态错误
				//sprintf(pNode->RetCode,"%d",E_TRANS_BANKACC_STATERR);
				return	E_TRANS_BANKACC_STATERR;
			case 51:		//银行卡金额不足
				//sprintf(pNode->RetCode,"%d",E_TRANS_BANKACC_NOMONEY);
				return	E_TRANS_BANKACC_NOMONEY;
			case 55:		//银行密码错误
				//sprintf(pNode->RetCode,"%d",E_TRANS_BANKCARD_PWDERR);
				return	E_TRANS_BANKCARD_PWDERR;
			case 96:		//银行处理超时
				//sprintf(pNode->RetCode,"%d",E_TRANS_BANK_NODECIDE);
				return	E_TRANS_BANK_NOANSWER;
			case 22:		//其他错误
				//sprintf(pNode->RetCode,"%d",E_TRANS_BANKCARD_PWDERR);
				return	E_TRANS_UNKNOW_ERROR;
			default:		//其他未知错误
				//sprintf(pNode->RetCode,"%d",E_TRANS_UNKNOW_ERROR);
				return	E_TRANS_UNKNOW_ERROR;
		}
	}
	
	memset(temp,0x00,sizeof temp);
	iso8583_get(&iso_zgyh_ans, 4, (unsigned char*)temp, 12);
	BCD2INT(&amt, (unsigned char*)temp, 12, 0);
	out_pack->damt0=amt/100.0;
	out_pack->lvol0=1;
	PutRow(handle,out_pack,pRetCode,szMsg);
	
	return 0;
}