void operator()(boost::system::error_code ec, std::size_t bytes_transfered) { pt::ptree jsonobj; std::istream jsondata( m_buffer.get() ); /** * Here, we got a json object like this: * {"retcode":0,"result":{"uiuin":"","account":615050000,"uin":954663841}} * */ //处理! try { pt::json_parser::read_json( jsondata, jsonobj ); //TODO, group members if( jsonobj.get<int>( "retcode" ) == 0 ) { m_this_group->qqnum = jsonobj.get<std::string>( "result.account" ); BOOST_LOG_TRIVIAL(debug) << "qq number of group " << utf8_to_local_encode(m_this_group->name) << " is " << m_this_group->qqnum; m_webqq->siggroupnumber(m_this_group); m_handler(boost::system::error_code()); return ; }else{ BOOST_LOG_TRIVIAL(error) << literal_to_localstr("获取群的QQ号码失败"); pt::json_parser::write_json(std::cerr, jsonobj); } } catch( const pt::ptree_error & jserr ) { } // 返回错误 m_handler(error::make_error_code(error::failed_to_fetch_group_qqnumber)); }
//获得数据 void CHecheng::getdata() { Message* revMsg = (Message*)CData::getCData()->m_dictionary->objectForKey(tpy); CData::getCData()->m_dictionary->removeObjectForKey(tpy); // CCLOG("势力revMsg==%s",revMsg); if(revMsg) { this->unschedule(schedule_selector(CHecheng::getdata)); this->removeChild(load); char * ditu=revMsg->data; CCLog("%s",ditu); //解析数据 if(ditu) { CCLOG("得到物品的信息:%s",ditu); jsondata(ditu); } // else // this->schedule(schedule_selector(CHecheng::getdata)); } }
void operator()(boost::system::error_code ec, std::size_t bytes_transfered) { pt::ptree jsonobj; std::istream jsondata( m_buffer.get() ); /** * Here, we got a json object like this: * {"retcode":0,"result":{"uiuin":"","account":615050000,"uin":954663841}} * */ //处理! try { pt::json_parser::read_json( jsondata, jsonobj ); //TODO, group members if( jsonobj.get<int>( "retcode" ) == 0 ) { m_this_group->qqnum = jsonobj.get<std::string>( "result.account" ); BOOST_LOG_TRIVIAL(debug) << "qq number of group " << console_out_str(m_this_group->name) << " is " << m_this_group->qqnum; // 写缓存 pt::json_parser::write_json(std::string("cache/group_qqnumber") + m_this_group->gid, jsonobj); //start polling messages, 2 connections! BOOST_LOG_TRIVIAL(info) << "start polling messages"; m_webqq->siggroupnumber(m_this_group); m_handler(boost::system::error_code()); return ; }else{ BOOST_LOG_TRIVIAL(error) << console_out_str("获取群的QQ号码失败"); pt::json_parser::write_json(std::cerr, jsonobj); } } catch( const pt::ptree_error & jserr ) { } try{ // 读取缓存 pt::json_parser::read_json(std::string("cache/group_qqnumber") + m_this_group->gid, jsonobj); m_this_group->qqnum = jsonobj.get<std::string>( "result.account" ); BOOST_LOG_TRIVIAL(debug) << "(cached) qq number of group" << console_out_str(m_this_group->name) << "is" << m_this_group->qqnum << std::endl; // 向用户报告一个 group 出来了. m_webqq->siggroupnumber(m_this_group); m_handler(boost::system::error_code()); return; }catch (const pt::ptree_error & jserr){ boost::delayedcallsec( m_webqq->get_ioservice() , 500 + boost::rand48()() % 100 , boost::bind( &make_update_group_qqnumber_op, m_webqq, m_this_group, m_handler) ); } }