此SDK已停止维护,请开发者对接 RestApi V2
接口名称 | 支持推送类型 | 说明 |
---|---|---|
pushMessageToSingle | 透传(payload)、点击通知启动应用、点击通知打开网页等 | 对单个用户(clientid)推送 |
pushMessageToSingleByReqId | 与pushMessageToSingle支持类型相同 | 异常重试发送使用 |
正常推送不需要传requestId,如果发生异常重试时将requestId传入,具体用法详见示例代码
static void pushByRequestIdDemo() {
//准备数据
Message msg = {0};
msg.isOffline = true;//是否离线下发
msg.offlineExpireTime = 1000*3600*2;//离线下发有效期 毫秒
msg.pushNetWorkType = 0;//0不限 1wifi
SingleMessage singleMsg = {0};
singleMsg.msg = msg;
//目标用户
Target target = {0};
target.appId = appId;
target.clientId = cid;
//target.alias = "test";
IPushResult result = {0};
NotyPopLoadTemplate tmpl= {0};
NotyPopLoadTemplateDemo(& tmpl);
char *reqId ="random request id"; //reqId每次推送应唯一
try {
result = pushMessageToSingleByReqId(appKey, &singleMsg, &tmpl, NotyPopLoad, &target, reqId);
} catch (const exception &e) {
result = pushMessageToSingleByReqId(appKey, &singleMsg, &tmpl, NotyPopLoad, &target, reqId);
}
}
#include "IGtPush.h"
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#ifdef WIN32
#include <windows.h>
#endif
using namespace std;
static void printResult(IPushResult &result);
static void NotificationTemplateDemo(NotificationTemplate* templ)
// http的域名
//static char *host ="http://api.getui.com/apiex.htm";
//https的域名
static char *host ="https://api.getui.com/apiex.htm";
//定义常量, appId、appKey、masterSecret 采用本文档 "第二步 获取访问凭证 "中获得的应用配置
static char *appId = "";
static char *appKey = "";
static char *masterSecret = "";
static char *cid = ""; //要推送用户的cid
//static char *alias = ""; //要推送用户的别名
void tosingletest();
void tosingletest(){
//准备数据
Message msg = {0};
msg.isOffline = true;//是否离线下发
msg.offlineExpireTime = 1000*3600*2;//离线下发有效期 毫秒
msg.pushNetWorkType = 0;//0不限 1wifi 2:4G/3G/2G
SingleMessage singleMsg = {0};
singleMsg.msg = msg;
//目标用户
Target target = {0};
target.appId = appId;
target.clientId = cid;
//别名推送方式
// target.alias = alias;
IPushResult result = {0};
NotificationTemplate tmpl= {0};
NotificationTemplateDemo(& tmpl);
result = pushMessageToSingle(appKey, &singleMsg, &tmpl, Notification, &target);
printResult(result);
}
/* 通知消息模板 */
void NotificationTemplateDemo(NotificationTemplate* templ)
{
templ->t.appId = APPID;
templ->t.appKey = APPKEY;
//通知栏标题
templ->title = "请填写通知标题";
//通知栏内容
templ->text = "请填写通知内容";
//应用启动类型,1:强制应用启动 2:等待应用启动
templ->transmissionType = 2;
//透传内容
templ->transmissionContent = "请填写透传内容";
templ->logo = "push.png";
//接收到消息是否响铃,GT_ON:响铃 GT_OFF:不响铃
templ->isRing = GT_ON;
//接收到消息是否震动,GT_ON:震动 GT_OFF:不震动
templ->isVibrate = GT_ON;
//接收到消息是否可清除,GT_ON:可清除 GT_OFF:不可清除
templ->isClearable = GT_ON;
}
static void printResult(IPushResult &result) {
cout << "print result:-------------" << endl;
for (int i = 0; i < result.size; i++) {
cout << result.entry[i].key << ": " << result.entry[i].value << endl;
}
cout << "print end:----------------" << endl;
}
int main(){
// 注意:接口传入字符必须为UTF-8编码,因ASCII字符UTF-8编码后与原先一样,所以可以不编码,但中文等非ASCII字符必须编码
// 如果返回的类似错误"post http data failed, code=6",错误码可百度CURL返回的错误码是什么意思,如http://www.cnblogs.com/wainiwann/p/3492939.html
////程序运行前只需初始化一遍,若已经初始化过即可不用,"编码"两个字为固定写法,不需要做转换
Result r = pushInit(host, appKey, masterSecret, "编码");
if(r!=SUCCESS){
printf("pushInit for app failed: ret=%d\n", r);
return -1;
}
tosingletest();
return 0;
}
字段 | 返回码 |
---|---|
result | 请查询返回值 |
客户端展示 |
如果仅对单个用户推送务必使用单推接口,否则会严重影响推送性能,如果对少量甚至几个用户推送同样的消息,建议使用单推实现,性能会更高
接口名称 | 支持推送类型 | 说明 |
---|---|---|
pushMessageToList | 透传(payload)、点击通知启动应用、点击通知打开网页等 | (通过ClientID列表)群推,可查看clientid列表中每个用户的在线状态 |
#include "IGtPush.h"
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#ifdef WIN32
#include <windows.h>
#endif
using namespace std;
static void printResult(IPushResult &result);
static void NotificationTemplateDemo(NotificationTemplate* templ)
// http的域名
//static char *host ="http://api.getui.com/apiex.htm";
//https的域名
static char *host ="https://api.getui.com/apiex.htm";
//定义常量, appId、appKey、masterSecret 采用本文档 "第二步 获取访问凭证 "中获得的应用配置
static char *appId = "";
static char *appKey = "";
static char *masterSecret = "";
static char *cid1 = ""; //要推送用户的cid1
static char *cid2 = ""; //要推送用户的cid2
//static char *alias1 = ""; //要推送用户的别名alias1
//static char *alias2 = ""; //要推送用户的别名alias2
void tolisttest();
void tolisttest(){
//准备数据
Message msg = {0};
msg.isOffline = true;//是否离线下发
msg.offlineExpireTime = 1000*3600*2;//离线下发有效期 毫秒
msg.pushNetWorkType = 0;//0不限 1wifi 2:4G/3G/2G
ListMessage listMsg = {0};
listMsg.msg = msg;
NotificationTemplate tmpl= {0};
NotificationTemplateDemo(& tmpl);
Result ret;
char contentId[50] = "";
ret = getContentId(appKey, &listMsg, &tmpl, Notification, contentId, sizeof(contentId));
if (ret == SUCCESS) {
Target* targetList = new Target[2];
memset((void*)targetList, 0, sizeof(Target));
targetList[0].appId = appId;
targetList[0].clientId = cid1;
// targetList[0].alias = alias;
targetList[1].appId = appId;
targetList[1].clientId = cid2;
// targetList[1].alias = "bbb";
PushDetail details[1] = {0};
//cout << "============pushMessageToList============" << endl;
IPushResult result = {0};
result = pushMessageToList(appKey, contentId, targetList,1, details);
cout<<details->cid<<","<<details->ret<<endl;
printResult(result);
ret = cancelContentId(appKey, contentId);
cout << "cancelContentId ret=" << ret << endl;
}
}
}
/* 通知消息模板 */
void NotificationTemplateDemo(NotificationTemplate* templ)
{
templ->t.appId = APPID;
templ->t.appKey = APPKEY;
//通知栏标题
templ->title = "请填写通知标题";
//通知栏内容
templ->text = "请填写通知内容";
//应用启动类型,1:强制应用启动 2:等待应用启动
templ->transmissionType = 2;
//透传内容
templ->transmissionContent = "请填写透传内容";
templ->logo = "push.png";
//接收到消息是否响铃,GT_ON:响铃 GT_OFF:不响铃
templ->isRing = GT_ON;
//接收到消息是否震动,GT_ON:震动 GT_OFF:不震动
templ->isVibrate = GT_ON;
//接收到消息是否可清除,GT_ON:可清除 GT_OFF:不可清除
templ->isClearable = GT_ON;
}
static void printResult(IPushResult &result) {
cout << "print result:-------------" << endl;
for (int i = 0; i < result.size; i++) {
cout << result.entry[i].key << ": " << result.entry[i].value << endl;
}
cout << "print end:----------------" << endl;
}
int main(){
// 注意:接口传入字符必须为UTF-8编码,因ASCII字符UTF-8编码后与原先一样,所以可以不编码,但中文等非ASCII字符必须编码
// 如果返回的类似错误"post http data failed, code=6",错误码可百度CURL返回的错误码是什么意思,如http://www.cnblogs.com/wainiwann/p/3492939.html
//程序运行前只需初始化一遍,若已经初始化过即可不用,"编码"两个字为固定写法,不需要做转换
Result r = pushInit(host, appKey, masterSecret, "编码");
if(r!=SUCCESS){
printf("pushInit for app failed: ret=%d\n", r);
return -1;
}
tolisttest();
return 0;
}
字段 | 返回码 |
---|---|
result | 请查询返回值 |
客户端展示 |
注:此接口有频次控制,申请修改请点击右侧“技术咨询”了解详情 。
接口名称 | 支持推送类型 | 说明 |
---|---|---|
pushMessageToApp | 透传(payload)、点击通知启动应用、点击通知打开网页等 | (通过应用AppID)群推,给所有符合条件的客户端用户推送 |
#include "IGtPush.h"
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#ifdef WIN32
#include <windows.h>
#endif
using namespace std;
static void printResult(IPushResult &result);
static void NotificationTemplateDemo(NotificationTemplate* templ)
// http的域名
//static char *host ="http://api.getui.com/apiex.htm";
//https的域名
static char *host ="https://api.getui.com/apiex.htm";
//定义常量, appId、appKey、masterSecret 采用本文档 "第二步 获取访问凭证 "中获得的应用配置
static char *appId = "";
static char *appKey = "";
static char *masterSecret = "";
void toapptest();
void toapptest(){
//准备数据
Message msg = {0};
msg.isOffline = 0;//是否离线下发
msg.offlineExpireTime = 1000*3600*2;//离线下发有效期 毫秒
msg.pushNetWorkType = 0;//0不限 1wifi 2:4G/3G/2G
AppMessage appMsg = {0};
appMsg.msg = msg;
appMsg.speed = 10000;//定速
char* appList[] = {appId};
appMsg.appIdList = appList;
appMsg.appIdListSize = 1;
//通知接收者的手机操作系统类型
char* phoneTypeList[] = {"ANDROID","IOS"};
appMsg.phoneTypeList = phoneTypeList;
char* provinceList[] = {"浙江","上海","北京"};
appMsg.provinceList = provinceList;
char* tagList[] = {"happy"};
appMsg.tagList = tagList;
IPushResult result = {0};
//通知模板
NotificationTemplate tmpl= {0};
NotificationTemplateDemo(& tmpl);
result = pushMessageToApp(appKey, &appMsg, &tmpl, Notification);
//打印结果
printResult(result);
}
/* 通知消息模板 */
void NotificationTemplateDemo(NotificationTemplate* templ)
{
templ->t.appId = APPID;
templ->t.appKey = APPKEY;
//通知栏标题
templ->title = "请填写通知标题";
//通知栏内容
templ->text = "请填写通知内容";
//应用启动类型,1:强制应用启动 2:等待应用启动
templ->transmissionType = 2;
//透传内容
templ->transmissionContent = "请填写透传内容";
templ->logo = "push.png";
//接收到消息是否响铃,GT_ON:响铃 GT_OFF:不响铃
templ->isRing = GT_ON;
//接收到消息是否震动,GT_ON:震动 GT_OFF:不震动
templ->isVibrate = GT_ON;
//接收到消息是否可清除,GT_ON:可清除 GT_OFF:不可清除
templ->isClearable = GT_ON;
}
static void printResult(IPushResult &result) {
cout << "print result:-------------" << endl;
for (int i = 0; i < result.size; i++) {
cout << result.entry[i].key << ": " << result.entry[i].value << endl;
}
cout << "print end:----------------" << endl;
}
int main(){
// 注意:接口传入字符必须为UTF-8编码,因ASCII字符UTF-8编码后与原先一样,所以可以不编码,但中文等非ASCII字符必须编码
// 如果返回的类似错误"post http data failed, code=6",错误码可百度CURL返回的错误码是什么意思,如http://www.cnblogs.com/wainiwann/p/3492939.html
Result r = pushInit(host, appKey, masterSecret, "编码");//"编码"两个字为固定写法,不需要做转换
if(r!=SUCCESS){
printf("pushInit for app failed: ret=%d\n", r);
return -1;
}
toapptest();
return 0;
}
字段 | 返回码 |
---|---|
result | 请查询返回值 |
客户端展示 |
注:此接口有频次控制,申请修改请点击右侧“技术咨询”了解详情 。
一个应用同时下发了n个推送任务,为了更好地跟踪这n个任务的推送效果,可以把他们组成一个任务组,在查询数据时,只需要输入该任务组名即可同时查到n个任务的数据结果。
命名同一个应用的不同taskid为同一个任务组名,任务组名由第三方填写。tolist(对指定用户列表推送消息)、toapp(对指定应用群推消息)接口支持该功能。
void toListGroupName(char *host, char *appkey, char *mastersecret, ListMessage *message, void *templ,
TemplateType templateType, char *contentId, char *taskGroupname, Target * targetList, PushDetail *details) {
Result r = pushInit(host, appKey, masterSecret, "编码");
if(r!=SUCCESS){
printf("pushInit for app failed: ret=%d\n", r);
return;
}
getContentIdByGroup(appKey, message, templ, Notification, contentId, sizeof(contentId), taskGroupname);
pushMessageToList(appkey, contentId, targetList, sizeof(targetList), details);
}
void toAppGroupName(char *host, char *appkey, char *mastersecret, AppMessage *message, void *templ,
TemplateType templateType, char *taskGroupname) {
Result r = pushInit(host, appKey, masterSecret, "编码");
if(r!=SUCCESS){
printf("pushInit for app failed: ret=%d\n", r);
return;
}
pushMessageToAppByGroupName(appKey, message, templ, templateType, taskGroupname);
}
正确返回 | 返回码 | 结果说明 |
---|---|---|
successed_online | 用户在线,消息在线下发 | |
successed_offline | 用户离线,消息存入离线系统 | |
Ok | 发送成功 | |
details | 返回用户状态的详细信息 | |
contentId | 任务ID(当result值为ok时,有此字段) |
错误返回 | 返回码 | 结果说明 |
---|---|---|
Error | 请求信息填写有误 | |
action_error | 未找到对应的action动作 | |
appkey_error | Appkey填写错误 | |
domain_error | 填写的域名错误或者无法解析 | |
sign_error | Appkey与ClientId不匹配,鉴权失败 | |
AppidNoMatchAppKey | appid和鉴权的appkey不匹配 | |
PushMsgToListOrAppTimesOverLimit | 群推次数超过最大值 | |
PushTotalNumOverLimit | 推送个数总数超过最大值 | |
AppIdNoUsers | 该AppId下的用户总数为0 | |
SendError | 消息推送发送错误 | |
SynSendError | 报文发送错误 | |
flow_exceeded | 接口消息推送流量已超限 | |
TargetListIsNullOrSizeIs0 | 推送target列表为空 | |
PushTotalNumOverLimit | 推送消息个数总数超限 | |
TokenMD5NoUsers | target列表没有有效的clientID | |
NullMsgCommon | 未找到contentId对应的任务 | |
TaskIdHasBeanCanceled | 任务已经被取消 | |
AppidError | clientid绑定的appid与推送的appid不符 | |
successed_ignore | 无效用户,消息丢弃 | |
TokenMD5Error | clientID填写有误 | |
SendError | 消息发送错误 | |
AppidNoAppSecret | appid未找到对应的appSecret | |
OtherError | 未知错误,无法判定错误类型 |
以上文档对您是否有帮助?