1.注册企业微信,企业有企业corpid,建立一个组,组内有个corpsecret
2.组内添加组员
3.发送一个get的https协议,根据企业corpid和组的corpsecret得到一个json数据,json数据内部有个access_token, 这个access_token过段时间会刷新一次。
https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid= &corpsecret=
CURL *curl;
CURLcode res;
curl = curl_easy_init();
if(curl) {
curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "GET");
curl_easy_setopt(curl, CURLOPT_URL, "https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid=wwfad38a43e06e8581&corpsecret=QoE-ir3wy_P3xyWpzgc9aKmA3HZ29KgUMbMvDe4sw5s");
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
curl_easy_setopt(curl, CURLOPT_DEFAULT_PROTOCOL, "https");
struct curl_slist *headers = NULL;
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
res = curl_easy_perform(curl);
}
curl_easy_cleanup(curl);
4通过秘钥access_token,然后发送通过https去post一个json数据,即可实现
https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token=
CURL *curl;
CURLcode res;
curl = curl_easy_init();
if(curl) {
curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "POST");
curl_easy_setopt(curl, CURLOPT_URL, "https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token=Bo5Nz7D3fJkLOcPKHwctSPU3FQmCXlrknQ3k7gK7WEIe7z2sCpTHOUukq5mGKBiOUi16zmfTpzbwM8zoNUu1j5QckQb7pJV6YXt9qTjAdZg_3WqJh7X3OjhXGvKlRNQ908Otf_JS4wTX3-W9gC6tRsGfnLEOwgeMZZabs-k093Dr0AsEVMbqzg66tEmO5DHnwPLn4u-tfhmDlKNAc7hbVw");
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
curl_easy_setopt(curl, CURLOPT_DEFAULT_PROTOCOL, "https");
struct curl_slist *headers = NULL;
headers = curl_slist_append(headers, "Content-Type: application/json");
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
const char *data = "{
\n \"touser\" : \"@all\",
\n \"toparty\" : \"@all\",
\n \"totag\" : \"@all\",
\n \"msgtype\" : \"text\",
\n \"agentid\" : 1000002,
\n \"text\" : {
\n \"content\" : \"你的快递已到,请携带工卡前往邮件中心领取。\\n出发前可查看<a href=\\\"http://work.weixin.qq.com\\\">邮件中心视频实况</a>,聪明避开排队。\"
\n },
\n \"safe\":0,
\n \"enable_id_trans\": 0,
\n \"enable_duplicate_check\": 0,
\n \"duplicate_check_interval\": 1800
\n}";
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, data);
res = curl_easy_perform(curl);
}
curl_easy_cleanup(curl);
C++推荐使用库 libcurl,
libcurl链接地址
openssl
cjson