-------------------------------------------
-- 微信充值
-------------------------------------------

local Config = require("Config")
local Log = require("common.Log")
local Define = require("platform.Define")
Json = Json or require("common.Json")

-- logintype 登录类型：1 微信小程序（安卓）
function onBuy(human, msg)
    -- 构造参数
    local params = {}

    params.logintype = msg.logintype
    params.openid = msg.openid
    params.openkey = msg.openkey
    params.pf = msg.pf
    params.pfkey = "pfkey"
    params.zoneid = 1
    params.yuanbao = msg.yuanbao
    params.buyID = msg.buyID
    params.accountName = human.db.account 
    params.svrIndex = Config.SVR_INDEX
    _G.thread_http.send(Define.TENCENT_BUY_URL, Json.Encode(params)) 
    Log.write(Log.LOGID_OSS_TENCENT_BUY, human.db._id,human.db.account,human.db.name,msg.logintype,msg.openid,msg.openkey,msg.pf,msg.yuanbao,msg.buyID)	
end

local REFRESH_TIME = 300
function onRefresh(human)
    local nowTime = os.time()
    if human.tencentBuyRefreshTime and (nowTime - human.tencentBuyRefreshTime) < REFRESH_TIME then
        --Broadcast.sendErr(human, Lang.TENCENT_API_REFRESH_TIME)
        return
    end
    human.tencentBuyRefreshTime = nowTime

    local params = {}
    params.openid = human.vopenid or ""
    params.openkey = human.openkey or ""
    params.pf = human.pf or ""
    params.pfkey = "pfkey"
    params.zoneid = 1
    params.accountName = human.db.account 
    params.svrIndex = Config.SVR_INDEX  

    _G.thread_http.send(Define.TENCENT_BUY_REFRESH, Json.Encode(params))
    --Broadcast.sendErr(human, Lang.TENCENT_API_REFRESH_OK)  
end