#include "stdafx.h"
#include "CSysConfig.h"
#include "CManageNetWork.h"
CSysConfig::CSysConfig()
{
	userbuylink.empty();
	userattrlink.empty();
	useronlinekflink.empty();
	user_tag = 0;
}

CSysConfig::~CSysConfig()
{
}

bool CSysConfig::Inti(std::string data)
{
	if (data.empty())
	{
		return false;
	}

	try
	{
		nlohmann::json j = nlohmann::json::parse(data.begin(), data.end());

		if (j["ret"].get<int>() == 1)
		{
			//
			auto stime = j["data"]["user_login_url"].get<std::string>();
			userbuylink = j["data"]["user_login_url"].get<std::string>();
			userattrlink = j["data"]["affurl"].get<std::string>();
			useronlinekflink = j["data"]["user_ticket"].get<std::string>();
			user_reg = j["data"]["user_reg"].get<std::string>();
			user_reset = j["data"]["user_reset"].get<std::string>();
			user_tutorial = j["data"]["user_tutorial"].get<std::string>();
			user_tag = j["data"]["tag"].get<int>();
			return true;

		}
		else
		{
			this->m_error_msg = S_CA2W(j["msg"].get<std::string>().c_str(), CP_UTF8).GetBuffer(0);
			return false;
		}


	}
	catch (...)
	{
		this->m_error_msg = L"½âÎöÊý¾Ý´íÎó";
		return false;
	}
	return false;
}

SStringW CSysConfig::GetBuyLink()
{
	if (user_tag == 1)
	{
		return S_CA2W(userbuylink.c_str(), CP_UTF8);
	}
	return  SStringW().Format(L"%s?email=%s&password=%s", S_CA2W(userbuylink.c_str(), CP_UTF8).GetBuffer(0), CManageNetWork::getSingletonPtr()->GetUsername(), CManageNetWork::getSingletonPtr()->GetPassWord());
}


SStringW CSysConfig::GetOnlineLink()
{
	if (user_tag == 1)
	{
		return S_CA2W(useronlinekflink.c_str(), CP_UTF8);
	}
	return  SStringW().Format(L"%s?email=%s&password=%s", S_CA2W(useronlinekflink.c_str(), CP_UTF8).GetBuffer(0), CManageNetWork::getSingletonPtr()->GetUsername(), CManageNetWork::getSingletonPtr()->GetPassWord());
}


SStringW CSysConfig::GetAffLink()
{
	if (user_tag == 1)
	{
		return S_CA2W(userattrlink.c_str(), CP_UTF8);
	}
	return  SStringW().Format(L"%s?email=%s&password=%s", S_CA2W(userattrlink.c_str(), CP_UTF8).GetBuffer(0), CManageNetWork::getSingletonPtr()->GetUsername(), CManageNetWork::getSingletonPtr()->GetPassWord());
}

SStringW CSysConfig::GetTutorialLink()
{
	return S_CA2W(user_tutorial.c_str(), CP_UTF8).GetBuffer(0);
}
