跳到主要内容

game_server.leiting_notification

简介

用于游戏服务器响应雷霆平台的推送通知

组件接口

leiting_notification.gs

雷霆平台通知消息处理模块

使用例子看sample说明

目前有以下几个大类型的通知消息:

  1. GM通知消息
  2. sky_eye图片审核通知消息
  3. sdk通知消息
  4. 充值通知消息
函数原型函数作用
void setup(map para)雷霆平台通知消息处理模块初始化
void dump()调试输出
bool is_whitelist_ip(string ip)判断ip是否在白名单列表中
mixed sequential_invoke(string id, function func, ...)相同标识的函数调用按顺序不并发执行(比如对同一个订单的操作不允许并发保证安全)
mixed unique_invoke(string request_id, function func, ...)相同标识的函数只能调用一次(重复调用后返回nil)
void set_gm_notify_handler(string cmd, mixed handler)设置雷霆平台GM通知消息处理函数
void set_sky_eye_picture_audit_notify_handler(mixed handler)设置雷霆平台sky_eye图片审核通知消息处理函数
void set_sdk_antiaddiction_logout_notify_handler(mixed handler)设置雷霆平台sdk沉迷登出通知处理函数
void set_sdk_pay_order_notify_handler(mixed handler)设置雷霆平台sdk订单通知处理函数
void set_sdk_pay_apple_refund_notify_handler(mixed handler)设置雷霆平台sdk苹果ios退款通知处理函数
void set_charge_charge_notify_handler(mixed handler)设置雷霆平台充值通知处理函数
void set_qr_login_get_code_notify_handler(mixed handler)设置雷霆平台PC扫码登录获取二维码通知处理函数
void set_subscribe_subscribe_notify_handler(mixed handler)设置雷霆平台订阅通知处理函数
void set_doudian_create_order_notify_handler(mixed handler)设置雷霆平台抖店创建订单通知处理函数
void set_doudian_shipment_notify_handler(mixed handler)设置雷霆平台抖店发货通知处理函数

样例

sample.gs
public void test()
{
// 启动httpserver
object http_ob = httpserver.listen(22222);
test_equal(!! http_ob, true);
defer {
http_ob.close();
}

// 初始化
leiting_notification.setup({
"httpserver_port": 22222,
"gm" : {
"key" : "testKey",
},
"sky_eye" : {
"key" : "testKey",
"path_prefix" : "sky_eye"
},
"sdk" : {
"key" : "testKey",
"path_prefix" : "sdk"
},
"charge" : {
"key" : "testKey",
"path_prefix" : "charge"
},
"qr_login" : {
"key" : "testKey",
"path_prefix" : "qr_login"
},
"subscribe" : {
"key" : "testKey",
"path_prefix" : "subscribe"
},
"doudian" : {
"key" : "testKey",
"path_prefix" : "doudian"
}
//"unique_invoke" : {}
});

// 设置GM消息itemList的处理函数
leiting_notification.set_gm_notify_handler("itemList", (: on_gm_notify_item_list :));

// 设置gm消息roleCoreData的处理函数
leiting_notification.set_gm_notify_handler("roleCoreData", (: on_gm_notify_role_core_data :));

// 设置sky_eye消息处理函数
leiting_notification.set_sky_eye_picture_audit_notify_handler((: on_sky_eye_notify_picture_audit :));

// 设置sdk消息处理函数
leiting_notification.set_sdk_antiaddiction_logout_notify_handler((: on_sdk_notify_anti_addiction_logout :));

// 设置充值消息处理函数
leiting_notification.set_charge_charge_notify_handler((: on_charge_notify_charge :));

// 设置PC扫码登录消息处理函数
leiting_notification.set_qr_login_get_code_notify_handler((: on_qr_login_notify_get_code :));

// 设置订阅通知消息处理函数
leiting_notification.set_subscribe_subscribe_notify_handler((: on_subscribe_notify_subscribe :));

// 设置抖店创建订单消息处理函数
leiting_notification.set_doudian_create_order_notify_handler((: on_doudian_notify_create_order :));

// 设置抖店订单返货消息处理函数
leiting_notification.set_doudian_shipment_notify_handler((: on_doudian_notify_shipment :));

// 设置qr_login消息处理函数


// 模拟雷霆平台推送
post_gm_notify();

post_sky_eye_notify();

post_sdk_notify();

post_charge_notify();
}

void post_gm_notify()
{
map para = {
"requestId" : "123456",
"sign" : "afc3217d2b23745b89f4c84ee53a5f49"
};
printf("Send gm notify 1: %O\n", para);
mixed result1 = httpclient.post("http://127.0.0.1:22222/itemList", para);
printf("Result 1: %O\n", result1.parse_data());

printf("Send gm notify 2: %O\n", para);
mixed result2 = httpclient.post("http://127.0.0.1:22222/itemList", para);
printf("Result 2: %O\n", result2.parse_data());

printf("Send gm notify 3: %O\n", para);
mixed result3 = httpclient.post("http://127.0.0.1:22222/roleCoreData", para);
printf("Result 3: %O\n", result3.parse_data());
}

parallel void on_gm_notify_item_list(LtGmItemListNotifyResult result, LtGmItemListNotify gm_notify)
{
printf("RECV gm notify: %O\n", gm_notify);
leiting_notification.unique_invoke(gm_notify.requestId, () {
for (int i = 1 upto 10)
{
LtGmItemConfig ic = LtGmItemConfig.new();
ic.itemId = sprintf("item%d", i);
ic.name = sprintf("武器%d", i);
result.add_item(ic);
}

// 处理成功,设置返回值
result.status = 0;
});
}

parallel void on_gm_notify_role_core_data(LtGmRoleCoreDataNotifyResult result, LtGmRoleCoreDataNotify gm_notify)
{
result.add_tag("标签1");
result.add_tag("标签2");
result.add_tag("标签3");
result.add_label("角色");
result.add_sub_label_data("角色", "基本信息", {
"key" : "气血",
"value" : 89341,
"type" : "text"
});
result.add_sub_label_data("角色", "基本信息", {
"key" : "法力",
"value" : 38001,
"type" : "text"
});
result.add_sub_label_data("角色", "攻击属性", {
"key": "攻速",
"value": 0,
"type": "text"
});
result.add_sub_label_data("角色", "攻击属性", {
"key": "暴击",
"value": 420,
"type": "text"
});

result.add_label("宠物");
result.add_sub_label_data("宠物", "小火龙", {
"key" : "攻击力",
"value" : 4000,
"type" : "text"
});
result.add_sub_label_data("宠物", "小火龙", {
"key" : "防御力",
"value" : 5000,
"type" : "text"
});
result.add_sub_label_data("宠物", "九尾狐", {
"key" : "攻击力",
"value" : 6000,
"type" : "text"
});
result.add_sub_label_data("宠物", "九尾狐", {
"key" : "防御力",
"value" : 3000,
"type" : "text"
});
result.status = 0;
}

void post_sky_eye_notify()
{
map para = {
"auditResult" : 1,
"mid" : "123456",
"sign" : "afc3217d2b23745b89f4c84ee53a5f49"
};
printf("Send sky_eye notify: %O\n", para);
mixed result = httpclient.post("http://127.0.0.1:22222/sky_eye/pictureAudit", para);
printf("Result: %O\n", result.parse_data());
}

parallel void on_sky_eye_notify_picture_audit(LtResult result, LtPictureAuditNotify sky_eye_notify)
{
printf("RECV sky_eye notify: %O\n", sky_eye_notify);

if (sky_eye_notify.is_audit_result_ok())
{
printf("pictureAudit ok\n");
}
else
if (sky_eye_notify.is_audit_result_failed())
{
printf("pictureAudit failed\n");
}

// 处理成功,设置返回值
result.status = 0;
}

void post_sdk_notify()
{
map para = {
"age" : 18,
"game" : "game",
"roleId" : "roleId",
"isHoliday" : 1,
"onlineTime" : 180000,
"timeStamp" : 1,
"type" :3,
"sign" : "6bd439ffe3b420da05acb119c9d0011c"
};
printf("Send sdk notify: %O\n", para);
mixed result = httpclient.post("http://127.0.0.1:22222/sdk/antiAddictionLogout", para);
printf("Result: %O\n", result.parse_data());
}

parallel void on_sdk_notify_anti_addiction_logout(LtResult result, LtAntiAddictionLogoutNotify sdk_notify)
{
printf("Recv sdk notify: kicked by gm: %M, age: %d\n", sdk_notify.is_kicked_off_by_gm(), sdk_notify.age);

// 处理成功,设置返回值
result.status = 0;
}

// 模拟一个充值通知
void post_charge_notify()
{
map para = {
"money" : 10000,
"channelNo" : "channelNo",
"currency" : "CNY",
"productId" : "productId",
"roleId" : "roleId",
"userId" : "userId",
"serverId" : "serverId",
"chargeChannel" :11,
"sign" : "6bd439ffe3b420da05acb119c9d0011c"
};
printf("Send charge notify: %O\n", para);
mixed result = httpclient.post("http://127.0.0.1:22222/charge/charge", para);
printf("Result: %O\n", result.parse_data());
}

parallel void on_charge_notify_charge(LtChargeNotifyResult result, LtChargeNotify charge_notify)
{
// 如果需要保证顺序
leiting_notification.sequential_invoke(charge_notify.roleId, () {
printf("RECV charge notify: %O\n", charge_notify);

// 处理成功,设置返回值
result.status = 0;
});
}

parallel void on_qr_login_notify_get_code(LtQrLoginGetCodeNotifyResult result, LtQrLoginGetCodeNotify qr_login_notify)
{
result.succeed();
}

parallel void on_subscribe_notify_subscribe(LtSubscribeNotifyResult result, LtSubscribeNotify subscribe_notify)
{
result.succeed();
}

parallel void on_doudian_notify_create_order(LtDouDianCreateOrderNotifyResult result, LtDouDianCreateOrderNotify doudian_notify)
{
result.succeed();
}

parallel void on_doudian_notify_shipment(LtResult result, LtDouDianShipmentNotify doudian_notify)
{
result.status = 0;
}