lua demo
ngx.header.content_type = "text/plain"
local cjson = require "cjson";
local funova_libs = require "funova_libs";
local Code_Result =
{
success = 1, --礼包领取成功
not_exists = 2, --礼包码无效
used = 3, --礼包码已被使用
channel_not_match = 4, --礼包码无效
channel_used = 5, --已经领取过此类礼包
channel_error = 6, --礼包码无效
error = 7 --兑换失败
}
redis_instance = funova_libs:redis_connect();
function UpdateCode(param)
local result = {}
if redis_instance then
local pid = param['pid'];
local code = param['code'];
local channel = param['ch'];
--ngx.say("pid:"..pid .. " code:"..code .. " ch:"..channel)
if pid and code and channel then
local usepid = redis_instance:hget("code_hash",code)
result["statu"] = 0;
if usepid == ngx.null then
result["msg"] = "Code not exists!";
result["statu"] = Code_Result.not_exists
elseif usepid ~= "0" then
result["msg"] = "Code has been used!";
result["statu"] = Code_Result.used
else
local code_type_ch = string.sub(code, 1,6)
local code_ch = string.sub(code, 4,6)
local ch = redis_instance:hget("channel_hash", code_ch)
if ch == ngx.null then
result["msg"] = "Code not exists, channel error";
result["statu"] = Code_Result.channel_error
elseif ch ~= channel then
result["msg"] = "Code can not use on this channel : "..ch;
result["statu"] = Code_Result.channel_not_match
else
local pid_code_type = pid.."|"..code_type_ch
local usecnt = redis_instance:hget("pid_use_code_hash",pid_code_type)
if usecnt == ngx.null then --默认 一种类型的激活码只能使用一次
redis_instance:hset("code_hash", code, pid)
redis_instance:hincrby("pid_use_code_hash", pid_code_type,1);
result["statu"] = Code_Result.success
result["msg"] = "ok";
elseif usecnt >= "1" then
result["msg"] = "Has been used code on this channel";
result["statu"] = Code_Result.channel_used
end
end
end
else
result["msg"] = "parm error"
result["statu"] = Code_Result.error
--ngx.say("{\"statu\" : 0, \"msg\" : 'param error'}")
end
else
result["msg"] = "redis connect error"
result["statu"] = Code_Result.error
end
res_json = cjson.encode(result)
ngx.say(res_json)
end
function GetArgs()
local request_method = ngx.var.request_method
local args = nil
if "GET" == request_method then
args = ngx.req.get_uri_args()
elseif "POST" == request_method then
ngx.req.read_body()
args = ngx.req.get_post_args()
end
return args;
end
local args = GetArgs()
UpdateCode(args)
lua demo的更多相关文章
- lua学习笔记(一)
lua是一种嵌入式的语言,首先安装. lua安装依赖于readline库,下载readline tar -zxvf readline-6.2.tar.gz cd readline-6.2 ./conf ...
- cocos2d-x 使用Lua
转自:http://www.benmutou.com/blog/archives/49 1. Lua的堆栈和全局表 我们来简单解释一下Lua的堆栈和全局表,堆栈大家应该会比较熟悉,它主要是用来让C++ ...
- 转载一篇将C/C++ 与lua混合使用入门讲的比较好的文章
转自 http://www.open-open.com/home/space-6246-do-blog-id-1426.html Lua是一个嵌入式的脚本语言,它不仅可以单独使用还能与其它语言混合调用 ...
- 一篇个人感觉比较好的lua入门的文章
原文转自www.cppprog.com,由三篇文章组成 Lua是一个嵌入式的脚本语言,它不仅可以单独使用还能与其它语言混合调用.Lua与其它脚本语言相比,其突出优势在于: 1. 可扩展性.Lua的扩 ...
- VS项目属性配置实验过程
(原创,转载注明出处:http://www.cnblogs.com/binxindoudou/p/4017975.html ) 一.实验背景 cocos2d-x已经发展的相对完善了,从项目的创建.编译 ...
- Lua-Async 协程的高级用法
Lua-Async 这是一个基于协程的异步调用库, 该库的设计思路类似JavaScript的Promise, 但相比Promise, 它有更多的灵活性. -- 引入Async local Async ...
- lua模块demo(redis,http,mysql,cjson,本地缓存)
1. lua模块demo(redis,http,mysql,cjson,本地缓存) 1.1. 配置 在nginx.conf中设置lua_shared_dict my_cache 128m; 开启ngi ...
- lua入门demo(HelloWorld+redis读取)
1. lua入门demo 1.1. 入门之Hello World!! 由于我习惯用docker安装各种软件,这次的lua脚本也是运行在docker容器上 openresty是nginx+lua的各种模 ...
- lua入门之环境搭建、第一个demo
前言 前段时间因为有些项目功能需要,自己研究了下lua,今天整理下,并以一个demo为示例演示 手机上的运行效果 分为几个步骤来逐步讲解. 1.lua介绍,为什么选择它? 2.环境安装 3.撸一个简单 ...
随机推荐
- 性能测试之工具对比-ngrinder jmeter loadunner及ngrinder安装使用方法
参考:https://blog.csdn.net/bear_w/article/details/78366078
- SQLSERVER调用DLL程序
在SQL Server中调用dll分为两个步骤 1.创建一个dll文件(dll文件分成3种类型,讲其中一种) 2.把dll文件放进SQL Server的程序集中.然后定义一个Function,就可以通 ...
- Linux Bash严重漏洞修复方法
日前Linux官方内置Bash中新发现一个非常严重安全漏洞,黑客可以利用该Bash漏洞完全控制目标系统并发起攻击,为了避免Linux服务器受影响,就要尽快修补该漏洞了.(漏洞参考https://acc ...
- uCOS-ii笔记
ucos ii system 文件结构 上层: 应用软件,用户代码 中层: 与处理器无关代码 与应用程序相关配置文件 与处理器有关代码 下层: 硬件(cpu,interupt,timer,gpio,i ...
- OS中处理机调度模型和调度算法
OS中处理机调度模型和调度算法 调度层次 1.1. 高级调度(长程调度,作业调度) 功能:依据某种算法.把在外存队列上处于后备队列的那些作业调入内存.以作业为操做对象. 作业:比程序更为广泛的概念,不 ...
- nginx linux 安装
nginx linux 安装 进入http://nginx.org/en/download.html 下载 n gcc 安装nginx需要先将官网下载的源码进行编译,编译依赖gcc环境,如果没有gc ...
- ArcGIS Engine读取GDB中的Shape
string gdbPath = @"D:\Documents\ArcGIS\Default.gdb"; FileGDBWorkspaceFactoryClass pFileGDB ...
- ES标准中的相等比较算法 SameValue SameValueZero
1.相等比较算法 The Abstract Equality Comparison Algorithm (==) The Strict Equality Comparison Algorithm (= ...
- iOS 计步器的几种实现方式
代码地址如下:http://www.demodashi.com/demo/11658.html 这篇文章介绍两种可以获取计步数据的方法,一种是采用CMPedometer获取手机计步器数据,另一种是采用 ...
- 放大的X 【杭电-2655】 附题
/* 放大的X Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Su ...