PCClientApiDlg.cpp
上传用户:coffee44
上传日期:2018-10-23
资源大小:12304k
文件大小:10k
- // PCClientApiDlg.cpp : implementation file
- //
- #include "stdafx.h"
- #include "PCClientApi.h"
- #include "PCClientApiDlg.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- /////////////////////////////////////////////////////////////////////////////
- // CAboutDlg dialog used for App About
- // http://119.145.9.154:8080/api
- //119.145.9.154
- char TEST_SERVERURL[] = "http://192.168.194.67:8080/api";
- char APPKEY[] = "DEADKEY1234567890ABCDEFG1976";
- char APPSECRETKEY[] = "AA550987654321A5A5";
- char APPSESSIONKEY[] = "DEADAA550987654321A5A5";
- class CAboutDlg : public CDialog
- {
- public:
- CAboutDlg();
- // Dialog Data
- //{{AFX_DATA(CAboutDlg)
- enum { IDD = IDD_ABOUTBOX };
- //}}AFX_DATA
- // ClassWizard generated virtual function overrides
- //{{AFX_VIRTUAL(CAboutDlg)
- protected:
- virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
- //}}AFX_VIRTUAL
- // Implementation
- protected:
- //{{AFX_MSG(CAboutDlg)
- //}}AFX_MSG
- DECLARE_MESSAGE_MAP()
- };
- CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
- {
- //{{AFX_DATA_INIT(CAboutDlg)
- //}}AFX_DATA_INIT
- }
- void CAboutDlg::DoDataExchange(CDataExchange* pDX)
- {
- CDialog::DoDataExchange(pDX);
- //{{AFX_DATA_MAP(CAboutDlg)
- //}}AFX_DATA_MAP
- }
- BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
- //{{AFX_MSG_MAP(CAboutDlg)
- // No message handlers
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- // CPCClientApiDlg dialog
- CPCClientApiDlg::CPCClientApiDlg(CWnd* pParent /*=NULL*/)
- : CDialog(CPCClientApiDlg::IDD, pParent)
- {
- //{{AFX_DATA_INIT(CPCClientApiDlg)
- m_cstrKey = _T("userName");
- m_cstrUrl = _T("http://119.145.9.154:8080/api");
- //}}AFX_DATA_INIT
- // Note that LoadIcon does not require a subsequent DestroyIcon in Win32
- m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
- m_pApiClient = NULL;
- }
- void CPCClientApiDlg::DoDataExchange(CDataExchange* pDX)
- {
- CDialog::DoDataExchange(pDX);
- //{{AFX_DATA_MAP(CPCClientApiDlg)
- DDX_Control(pDX, IDC_COMBO, m_ctrCbxWay);
- DDX_Control(pDX, IDC_LIST, m_ctrLstValue);
- DDX_Text(pDX, IDC_EDIT_KEY, m_cstrKey);
- DDX_Text(pDX, IDC_EDIT_URL, m_cstrUrl);
- //}}AFX_DATA_MAP
- }
- BEGIN_MESSAGE_MAP(CPCClientApiDlg, CDialog)
- //{{AFX_MSG_MAP(CPCClientApiDlg)
- ON_WM_SYSCOMMAND()
- ON_WM_PAINT()
- ON_WM_QUERYDRAGICON()
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- // CPCClientApiDlg message handlers
- BOOL CPCClientApiDlg::OnInitDialog()
- {
- CDialog::OnInitDialog();
- // Add "About..." menu item to system menu.
- // IDM_ABOUTBOX must be in the system command range.
- ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
- ASSERT(IDM_ABOUTBOX < 0xF000);
- CMenu* pSysMenu = GetSystemMenu(FALSE);
- if (pSysMenu != NULL)
- {
- CString strAboutMenu;
- strAboutMenu.LoadString(IDS_ABOUTBOX);
- if (!strAboutMenu.IsEmpty())
- {
- pSysMenu->AppendMenu(MF_SEPARATOR);
- pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
- }
- }
- // Set the icon for this dialog. The framework does this automatically
- // when the application's main window is not a dialog
- SetIcon(m_hIcon, TRUE); // Set big icon
- SetIcon(m_hIcon, FALSE); // Set small icon
-
- // TODO: Add extra initialization here
- //初始化接口对象
- m_pApiClient = new CApiClient((char*)APPKEY,(char*)APPSECRETKEY,(char*)TEST_SERVERURL);
- //初始化list
- InitLst();
- m_ctrCbxWay.SetCurSel(0);
- return TRUE; // return TRUE unless you set the focus to a control
- }
- void CPCClientApiDlg::OnSysCommand(UINT nID, LPARAM lParam)
- {
- if ((nID & 0xFFF0) == IDM_ABOUTBOX)
- {
- CAboutDlg dlgAbout;
- dlgAbout.DoModal();
- }
- else
- {
- CDialog::OnSysCommand(nID, lParam);
- }
- }
- // If you add a minimize button to your dialog, you will need the code below
- // to draw the icon. For MFC applications using the document/view model,
- // this is automatically done for you by the framework.
- void CPCClientApiDlg::OnPaint()
- {
- if (IsIconic())
- {
- CPaintDC dc(this); // device context for painting
- SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
- // Center icon in client rectangle
- int cxIcon = GetSystemMetrics(SM_CXICON);
- int cyIcon = GetSystemMetrics(SM_CYICON);
- CRect rect;
- GetClientRect(&rect);
- int x = (rect.Width() - cxIcon + 1) / 2;
- int y = (rect.Height() - cyIcon + 1) / 2;
- // Draw the icon
- dc.DrawIcon(x, y, m_hIcon);
- }
- else
- {
- CDialog::OnPaint();
- }
- }
- // The system calls this to obtain the cursor to display while the user drags
- // the minimized window.
- HCURSOR CPCClientApiDlg::OnQueryDragIcon()
- {
- return (HCURSOR) m_hIcon;
- }
- BOOL CPCClientApiDlg::InitLst()
- {
- DWORD dwStyle;
-
- m_ctrLstValue.InsertColumn(0,_T("序号"),LVCFMT_LEFT,50);
- m_ctrLstValue.InsertColumn(1,_T("字段名_Key"),LVCFMT_LEFT,150);
- m_ctrLstValue.InsertColumn(2,_T("字段值_Value"),LVCFMT_LEFT,360);
- dwStyle = m_ctrLstValue.GetStyle();
- dwStyle = LVS_EX_GRIDLINES |LVS_EX_FULLROWSELECT|LVS_SHOWSELALWAYS ;
- m_ctrLstValue.SetExtendedStyle(dwStyle);
- m_ctrLstValue.SetBkColor(RGB(0xec,0xf1,0xfd));
- m_ctrLstValue.SetTextBkColor(RGB(0xfe,0xFF,0xc6));
- return TRUE;
- }
- BOOL CPCClientApiDlg::InsertDataToLst(list<string> lstStrValue)
- {
- m_ctrLstValue.DeleteAllItems();
- if (lstStrValue.empty())
- {
- return FALSE;
- }
- int nIndex = 0;
- list<string>::iterator lstIT;
-
- for ( lstIT = lstStrValue.begin(); lstIT != lstStrValue.end(); lstIT++)
- {
- string strTemp;
- strTemp = *lstIT;
- CString cstr;
- cstr.Format("%d",nIndex);
- m_ctrLstValue.InsertItem(nIndex, cstr);
-
- m_ctrLstValue.SetItemText(nIndex, 1, m_cstrKey);
- m_ctrLstValue.SetItemText(nIndex, 2, strTemp.data());
- nIndex++;
-
- TRACE("rn");
- TRACE(strTemp.data());
- }
- TRACE("rn----------------------List-------------------------rn");
- return TRUE;
- }
- void CPCClientApiDlg::OnOK()
- {
- if (NULL == m_pApiClient) return;
-
- GetDlgItem(IDOK)->EnableWindow(FALSE);
- UpdateData(TRUE);
- string strValue = "";
- list<string> lstStrValue;
- int nIndex = m_ctrCbxWay.GetCurSel();
- switch(nIndex)
- {
- case 0: // 登录服务器
- strValue = m_pApiClient->LoginUser("murron","murron");
- break;
- case 1: // 获取全部好友列表
- strValue = m_pApiClient->GetAllFrd("147","0","300");
- break;
- case 2: // 获取分组
- strValue = m_pApiClient->GetTeam("147", "0", "2");
- break;
- case 3: // 获取好友动态
- strValue = m_pApiClient->GetFrdNewsFeed("147", "0", "2");
- break;
- case 4: // 好友空间
- strValue = m_pApiClient->GetFrdSpace("147","10");
- break;
- case 5: // 获取店铺信息
- strValue = m_pApiClient->GetStoreMsg("147","3272");
- break;
- case 6: // 获取店铺所有应用(按照设置方式排行)
- strValue = m_pApiClient->GetStoreUse("147","217501","0","2","time","desc");
- break;
- case 7: // 获取掌柜推荐
- strValue = m_pApiClient->GetShopKeeperRecom("147","3272", "0","2");
- break;
- case 8: // 订阅店铺
- strValue = m_pApiClient->SubscribeStore("147","3272");
- break;
- case 9: // 获取买家须知
- strValue = m_pApiClient->GetBuyerNotice("147","327");
- break;
- case 10: // 获取应用(按照某类行为)
- strValue = m_pApiClient->GetMyApp("147","0","2","down");
- break;
- case 11: // 获取推荐信息(按照范围和排序)
- strValue = m_pApiClient->GetRecomMsg("147", "0", "2", "time", "desc", "all");
- break;
- case 12: // 你可能喜欢的
- strValue = m_pApiClient->GuessYouLike("147","3");
- break;
- case 13: // 获取应用分类列表
- strValue = m_pApiClient->GetAppGroup("147", "0", "3");
- break;
- case 14: // 获取店铺排行(按照各种标准排序)
- strValue = m_pApiClient->GetStoreRanking("147","0","2","app","desc");
- break;
- case 15: // 获取精品店铺列表
- strValue = m_pApiClient->GetBoutiqueList("147", "0", "2");
- break;
- case 16: // 收件箱信息列表
- strValue = m_pApiClient->CollectionList("147", "0", "5");
- break;
- case 17: // 发信息
- strValue = m_pApiClient->SendMsg("147","10","测试程序2009");
- break;
- case 18: // 回复信息
- strValue = m_pApiClient->ResendMsg("10","147","10 ReTO 147 好好学习");
- break;
- case 19: // 应用搜索
- break;
- case 20: // 店铺搜索
- break;
- case 21: // 添加收藏(包括应用和店铺)
- strValue = m_pApiClient->AddCollection("147","217430","app");
- break;
- case 22: // 删除收藏(包括应用和店铺)
- strValue = m_pApiClient->DelCollection("147","217430","app");
- break;
- case 23: // 根据应用ID获取附件ID
- strValue = m_pApiClient->GetAffixByApp("147","106");
- break;
- case 24: // 设置推荐应用(按照范围)
- strValue = m_pApiClient->SetRecomUse("147","106","all","10");
- break;
- case 25: // 评价应用
- strValue = m_pApiClient->EvaluateUse("147","106","4.0","good");
- break;
- case 26: // 获取应用详情
- strValue = m_pApiClient->GetUseDetail("147","106");
- break;
- case 27: // 获取相关应用
- strValue = m_pApiClient->GetOtherUse("147","106","0","2");
- break;
- case 28: // 获取评价详情
- strValue = m_pApiClient->GetEvaluateDetail("147","106","0","2");
- break;
- case 29: // 留言簿
- strValue = m_pApiClient->VisitorBook("147","106","0","2");
- break;
- case 30: // 获取应用排行榜(按照各种标准排序)
- strValue = m_pApiClient->GetUseRanking("147","87", "0","2","topCharge","desc");
- break;
- case 31: // 获取超市动态列表(WEB)
- strValue = m_pApiClient->GetStoreDymList("147","0","2");
- break;
- case 32: // 获取全部个性桌面
- strValue = m_pApiClient->GetAllDesktopInfos("tttt","tttt");
- break;
- case 33: // 删除个性桌面
- strValue = m_pApiClient->RemoveDesktopInfo("tttt","tttt","20090806032458578");
- break;
- case 34: // 上传个性桌面
- strValue = m_pApiClient->UpDesktopInfo("tttt","tttt","20090806032458578", "ftp://192.168.191.23//147/20090729200015921.zip");
- break;
- case 35: // 查询个性桌面
- strValue = m_pApiClient->GetDesktopInfos("tttt","tttt","20090806032458578");
- break;
- case 36: // 购买应用
- strValue = m_pApiClient->BuyUse("147","106","244");
- break;
- case 37: // 下载应用
- strValue = m_pApiClient->DownloadUse("147","106","244");
- break;
- default: //
- break;
- };
- //分析数据
- m_cstrKey.TrimLeft();
- m_cstrKey.TrimRight();
- lstStrValue.clear();
- m_pApiClient->AnalyzeRespMsg(strValue, m_cstrKey, lstStrValue);
- //向list控件插入数据
- InsertDataToLst(lstStrValue);
- GetDlgItem(IDOK)->EnableWindow(TRUE);
- //CDialog::OnOK();
- }
- BOOL CPCClientApiDlg::DestroyWindow()
- {
- // TODO: Add your specialized code here and/or call the base class
- if (NULL != m_pApiClient)
- {
- delete m_pApiClient;
- m_pApiClient = NULL;
- }
- return CDialog::DestroyWindow();
- }