12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788 |
- local logger = require "logger"
- local redisdriver = require "skynet.db.redis"
- local stringify = require "stringify"
- local skynet = require "skynet"
- local queue = require "skynet.queue"
- local asset = require "model.asset"
- local synchronized = queue()
- local cjson = require "cjson"
- local md5 = require "md5"
- local trace = logger.trace
- --local trace = function(...) end
- local authz = {acc = "yytx", pwd = "lee@YY-Games.520"}
- -- Generate request data
- local content = {acc = authz.acc, pwd = authz.pwd, sign = false}
- content.sign = string.sub(md5.sumhexa(content.acc .. content.pwd), 9, 24)
- local whitelist = {
- ["127.0.0.1"] = true,
- ["39.97.97.91"] = true, -- IOS 测试服
- ["192.168.101.41"] = true, -- 淡心服务器
- ["222.212.88.4"] = true,
- }
- local redis
- local start
- local rechargeser
- local INDENT = "indent:"
- local KEYGEN_PAY = "%s:%s"
- local function start_pay()
- local conf = assert(option.redis)
- redis = redisdriver.connect(conf)
- redis:select(3)--切换到数据库db1
- rechargeser = rechargeser or skynet.localname(".recharge")
- return 1
- end
- --192.168.1.44:9001/recharge?cfid=128&uid=9999&orderid=98756
- local recharge = function(args, ipaddr)
- return synchronized(function()
- start = start or start_pay()
- trace("处理来自主机 %s 的充值请求", ipaddr)
- if not whitelist[ipaddr] then
- -- return { code=403, msg="Forbidden" }
- end
- -- 验证gm账号
- -- local code = string.sub(args.code, 1, 16)
- -- if code ~= content.sign then
- -- return cjson.encode({state = 403, msg = "账号或密码错误"})
- -- end
- trace("开始处理充值信息:%s",stringify(args))
- local uid = args.uid
- local cfid = tonumber(args.cfid)
- local orderid = args.orderid
- local appname = args.appname or "NULL"
- local giftid = tonumber(args.product_id)
-
- if not uid or not cfid or not orderid or not giftid then
- return { code=1 }--数据不足
- end
- local key = INDENT..string.format(KEYGEN_PAY,uid,orderid)
- -- HEXISTS
- if redis:hexists(key,"uid") == 1 then
- return { code=2 }--已存在
- end
- -- test recharge
- if not asset.RechargeConfig_proto[cfid] then
- return { code=3 }--错误的cfid
- end
- if not asset.GiftConfig_proto[giftid] then
- return { code=4 }--错误的礼包id
- end
- skynet.send(rechargeser,"lua", "orderid_record", uid, cfid, orderid, appname, giftid)
- return { code=0 }
- end)
- end
- return recharge
|