#define BOOST_TEST_MODULE acsystrategy
#include "acsy/util/commondef.h"
#include "acsy/interface/StrategyFactory.h"
#include "acsy/net/acsypeernode.h"
#include "acsy/util/publictools.h"
#include "acsy/util/algorithm.h"
#include "acsy/util/dbconn.h"
#include "acsy/util/uvhelper.h"
#include"boost/asio.hpp"
#include<avhttp/avhttp.hpp>
#include <boost/graph/properties.hpp>
#include <boost/graph/graph_traits.hpp>
#include <boost/graph/adjacency_list.hpp>
#include <boost/graph/dijkstra_shortest_paths.hpp>
#include <boost/property_map/property_map.hpp>
#include <boost/uuid/uuid_generators.hpp>
#include <boost/variant.hpp>
#include <boost/any.hpp>
#include <boost/signals2.hpp>
#include <boost/graph/adjacency_list.hpp>
#include <boost/core/demangle.hpp>
#include <boost/array.hpp>
#include <boost/regex.hpp>
#include <json/value.h>
#include <json/reader.h>
#include <typeinfo>
#include <iostream>
#include <sql.h>
#include <sqlext.h>
#include <boost/property_tree/ptree.hpp>
#include <boost/property_tree/xml_parser.hpp>
int main_weixin(){
std::string sFilename = "E:\\trade\\config\\acsyconf002.xml";
boost::property_tree::ptree m_pt;
boost::property_tree::xml_parser::read_xml(sFilename, m_pt);
std::string str;
std::vector<std::string> vecXml;
for (auto &m : m_pt)
{
if (m.first == "group")
{
std::string xml = m.second.get("account","00");
vecXml.push_back(xml);
for (auto &m_child:m.second)
if (m_child.first == "user")
{
str = m_child.second.get_value<std::string >();
vecXml.push_back(str);
}
}
for (int i = 0; i < vecXml.size(); ++i){
std::cout<<vecXml[i]<<std::endl;
}
vecXml.clear();
}
//std::string swebport(m_pt.get("config.swebport", "8006"));
//int nwebport = std::atoi(swebport.c_str());
boost::asio::io_service io;
boost::system::error_code ec;
std::string account_id = "900102109";
// 构造查询IP的URL.
std::string query_url = "https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid=wxc609ee4479347bb9&corpsecret=JfT9Ro5Bl3yhQqD_G9m85WPmbuq1v2tc8WK8Ct-5PaSfPdSb4T2p2pkvH8UDV2Ce";
avhttp::http_stream h(io);
h.open(query_url, ec);
if (ec)
{
return -1;
}
std::string result;
boost::asio::streambuf response;
std::string access_token;
Json::Value v;
Json::Reader jr;
try
{
{
std::istream is(&h);
if (is.good())
{
std::getline(is, result);
ACSY_LOG_TRIVIAL(info) << result;
jr.parse(result, v);
access_token = v["access_token"].asString();
}
}
h.close();
avhttp::request_opts opts;
//for (int i = 1; i < vecXml.size(); ++i){
// std::string touser = vecXml[i];
//}
query_url = "https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token=" + access_token;
std::string str_post = R"(
{
"touser":"01",
"toparty":"kaifa",
"msgtype":"text",
"agentid":"0",
"text":{
"content":"test4hello!!!"
}
"safe":"0"
}
)";
opts.insert(avhttp::http_options::request_method, "POST");
opts.insert(avhttp::http_options::content_type, "text/json;charset=utf-8");
opts.insert(avhttp::http_options::request_body, str_post );
opts.insert(avhttp::http_options::content_length, acsy::util::strprintf("%d", str_post.length() ) );
h.request_options(opts);
h.open(query_url);
//int nwr = h.write_some(boost::asio::buffer(str_post) );
//ACSY_LOG_TRIVIAL(info) << "written : " << nwr;
{
std::istream is(&h);
if (is.good())
{
std::getline(is, result);
std::cout << result;
jr.parse(result, v);
//access_token = v["access_token"].asString();
}
}
h.close();
}
catch (std::exception& e)
{
std::cerr << e.what() << std::endl;
return -1;
}
}
微信接口开发
最新推荐文章于 2020-03-04 21:04:00 发布