Commit b6ed652b414b2c6cc32f1e2bad29ff952dde6f4b
1 parent
fcb34e1f
充值
Showing
3 changed files
with
88 additions
and
13 deletions
Show diff stats
src/ProtocolCode.lua
... | ... | @@ -174,6 +174,9 @@ actionCodes = { |
174 | 174 | Store_rechargeRpc = 550, |
175 | 175 | Store_dailyBuyRpc = 551, |
176 | 176 | Store_dinerBuyRpc = 552, |
177 | + Store_googleRechargeRpc = 553, | |
178 | + Store_purchaseOrderResult = 554, | |
179 | + | |
177 | 180 | |
178 | 181 | Email_listRpc = 600, |
179 | 182 | Email_drawAllAttachRpc = 601, | ... | ... |
src/actions/StoreAction.lua
1 | 1 | local _M = {} |
2 | 2 | |
3 | 3 | local serverId = tonumber(skynet.getenv("servId")) |
4 | +local md5 = require "md5" | |
4 | 5 | |
5 | -function _M.rechargeRpc(agent , data) | |
6 | +local function makeOrder(roleId, rechargeId) | |
7 | + local orderId = redisproxy:hincrby("autoincrement_set", "order", 1) | |
8 | + local partnerOrderId = string.format("%d_%d_%d", serverId, roleId, orderId) | |
9 | + local orderKey = string.format("order:%d:%d", roleId, orderId) | |
10 | + redisproxy:del(orderKey) | |
11 | + local order = require("models.Order").new({ | |
12 | + key = orderKey, | |
13 | + order = partnerOrderId, | |
14 | + rechargeId = rechargeId, | |
15 | + }) | |
16 | + order:create() | |
17 | + redisproxy:sadd(string.format("role:%d:orders", roleId), partnerOrderId) | |
18 | + return partnerOrderId | |
19 | +end | |
6 | 20 | |
21 | +-- 入口在正式服关闭 -- mock 充值 | |
22 | +function _M.rechargeRpc(agent , data) | |
7 | 23 | local role = agent.role |
8 | 24 | local msg = MsgPack.unpack(data) |
9 | 25 | local id = msg.id |
10 | 26 | local dataSet = csvdb["shop_rechargeCsv"][id] |
11 | - local roleId = role:getProperty("id") | |
12 | 27 | if not dataSet then return end |
13 | - | |
28 | + local roleId = role:getProperty("id") | |
29 | + | |
14 | 30 | --创建订单号 |
15 | - local orderId = redisproxy:hincrby("autoincrement_set", "order", 1) | |
16 | - local partnerOrderId = string.format("%d_%d_%d", serverId, roleId, orderId) | |
17 | - local orderKey = string.format("order:%d:%d", roleId, orderId) | |
18 | - redisproxy:del(orderKey) | |
31 | + local partnerOrderId = makeOrder(roleId, id) | |
32 | + SendPacket(actionCodes.Store_rechargeRpc, MsgPack.pack({ order = partnerOrderId })) | |
19 | 33 | |
20 | - local order = require("models.Order").new({ key = orderKey, order = partnerOrderId, rechargeId = dataSet.id }) | |
21 | - order:create() | |
22 | - redisproxy:sadd(string.format("role:%d:orders", roleId), partnerOrderId) | |
34 | + -- 测试的 直接发奖励了 | |
35 | + skynet.timeout(10, function () | |
36 | + role:handlePurchase({ | |
37 | + order = partnerOrderId, | |
38 | + amount = dataSet.rmb, | |
39 | + game_money = dataSet.diamond, | |
40 | + product_id = dataSet.productId, | |
41 | + pay_time = skynet.timex(), | |
42 | + transactionId = "onlyTest", | |
43 | + }) | |
44 | + end) | |
45 | + | |
46 | + return true | |
47 | +end | |
48 | + | |
49 | +local function table_keys( t ) | |
50 | + local keys = {} | |
51 | + for k, _ in pairs( t ) do | |
52 | + keys[#keys + 1] = k | |
53 | + end | |
54 | + return keys | |
55 | +end | |
56 | + | |
57 | +local function signPms(params, secret_key) | |
58 | + local keys = table_keys(params) | |
59 | + table.sort(keys) | |
60 | + local urlCode = "" | |
61 | + for index, key in ipairs(keys) do | |
62 | + urlCode = urlCode .. params[key] | |
63 | + end | |
64 | + return md5.sumhexa(urlCode .. secret_key):lower() | |
65 | +end | |
66 | + | |
67 | + | |
68 | +-- google 充值 入口 | |
69 | +function _M.googleRechargeRpc(agent, data) | |
70 | + local role = agent.role | |
71 | + local msg = MsgPack.unpack(data) | |
72 | + local id = msg.id | |
73 | + local dataSet = csvdb["shop_rechargeCsv"][id] | |
74 | + if not dataSet then return end | |
75 | + local roleId = role:getProperty("id") | |
23 | 76 | |
24 | - -- 暂时忽略心跳检查 | |
25 | 77 | role.ignoreHeartbeat = true |
26 | - SendPacket(actionCodes.Store_rechargeRpc, MsgPack.pack({ order = partnerOrderId })) | |
78 | + --创建订单号 | |
79 | + local partnerOrderId = makeOrder(roleId, id) | |
80 | + -- 签名 | |
81 | + local secret_key = "b7657fa7ccd44c16a35e3f454ac7a075" | |
82 | + local need = { | |
83 | + out_trade_no = partnerOrderId, | |
84 | + money = dataSet.rmb, | |
85 | + game_money = dataSet.diamond, | |
86 | + product_id = dataSet.productId, | |
87 | + } | |
88 | + local sign = signPms(need, secret_key) | |
89 | + | |
90 | + SendPacket(actionCodes.Store_googleRechargeRpc, MsgPack.pack({ order = partnerOrderId, sign = sign})) | |
27 | 91 | return true |
28 | 92 | end |
29 | 93 | |
94 | + | |
30 | 95 | function _M.purchaseOrderResult(agent, data) |
31 | 96 | local role = agent.role |
32 | 97 | ... | ... |
src/models/RolePlugin.lua
... | ... | @@ -1399,6 +1399,14 @@ function RolePlugin.bind(Role) |
1399 | 1399 | |
1400 | 1400 | |
1401 | 1401 | -- 充值 -- |
1402 | + --[[ | |
1403 | + request.order = data.out_trade_no | |
1404 | + request.amount = data.money / 100 | |
1405 | + request.game_money = data.game_money | |
1406 | + request.product_id = data.product_id | |
1407 | + request.pay_time = data.pay_time | |
1408 | + request.transactionId = data.order_no | |
1409 | + ]] | |
1402 | 1410 | function Role:handlePurchase(params) |
1403 | 1411 | local roleId = self:getProperty("id") |
1404 | 1412 | local partnerOrderStr = params.order |
... | ... | @@ -1417,7 +1425,6 @@ function RolePlugin.bind(Role) |
1417 | 1425 | return |
1418 | 1426 | end |
1419 | 1427 | |
1420 | - | |
1421 | 1428 | local rechargeData = csvdb["shop_rechargeCsv"][orderObject:getProperty("rechargeId")] |
1422 | 1429 | if rechargeData.rmb ~= tonumber(params.amount) then |
1423 | 1430 | skynet.error(string.format("fake order: %s, roleId: %d, order: %s", | ... | ... |