Skip to content

DeveloperStoreService

继承自:

描述

开发者商店服务节点,专门用于处理游戏内虚拟商品交易。提供商品信息查询、商品购买、订单管理、库存操作等功能。支持开发者产品配置、玩家购买记录查询、迷你币支付、订单状态同步等特性,是游戏内购系统的核心服务节点

成员函数

voidGetDeveloperStoreItems ()
查询当前地图开发者商店列表
tableGetProductInfo (int productId)
查询指定商品(开发者商店中商品)的信息
voidMiniCoinRecharge ()
打开Mini币充值弹窗
voidBuyDeveloperStoreGoods (int goodsId, int goodsNum, string extra, string desc)
购买开发者商店商品,调起购买弹窗,仅客机可调用
voidBuyDeveloperStoreGoodsByItemID (int itemId, int goodsNum, string extra, string desc)
根据开发者自定义的商品ID购买开发者商店商品,调起购买弹窗。仅客机可调用,游戏版本需大于1.53
根据开发者自定义的商品ID获取商品id。游戏版本需大于1.53
查询并批量提取仓库物品,仅服务端执行,用于处理开发者添加的道具,或者购买不到账时重新触发,调用后会查询玩家仓库物品,并逐个触发 OnDeveloperStoreGoods 事件
voidAddStoreGoods (int uin, int goodsId, int goodsNum, string extra)
给指定玩家添加仓库物品,仅服务端执行,目标玩家可以不在线,须再次调用 ApplyStoreItems 来触发购买道具的回调
voidAddStoreItem (int uin, int itemId, int itemNum, string extra)
给指定玩家添加仓库物品,仅服务端执行,目标玩家可以不在线,须再次调用 ApplyStoreItems 来触发购买道具的回调

事件

SBXSignalOnDeveloperStoreGoods (int uin, int code, string errorMsg, table orderInfo)
仅服务端监听,用于通知购买结果

代码示例

lua
--[[
错误码定义:
  0 - 成功
  1 ~ 1000 - 开发者平台返回的错误码
  1001 - 地图未上传
  1002 - 用户取消购买
  1003 - 此商品查询失败
  1004 - 请求失败
  1005 - 迷你币不足
  1006 - 开发者商店商品为空
  1100 ~ 1109 - 请求失败(可能为网络问题或主机问题)
  1110及以上 - 解析失败或主机返回的数据有误
]]

--客户端脚本LocalScript

local store = game:GetService("DeveloperStoreService")

-- 购买开发者商店某个商品
local function BuyGoodsByItemID(goods_id, num, extra_args, desc)
	store:BuyDeveloperStoreGoods(goods_id, num, extra_args, desc)
end

-- 服务端脚本 Script

DeveloperStoreService.OnDeveloperStoreGoods:Connect(function(playerId, code, msg, orderInfo)
    print("BuyDeveloperStoreGoodsV3", playerId, code, msg)
    -- 根据错误码判断购买结果
    if code == 0 then
        print("购买成功")
    elseif code == 1002 then
        print("用户取消购买")
    elseif code == 1005 then
        print("迷你币不足")
    else
        print("购买失败,错误码:", code)
    end
    
    if orderInfo then
        for k, v in pairs(orderInfo) do
            print(k .. " = " .. tostring(v))
	end
    end
end)

local function AddStoreItemToPlayer(playerId, itemId, num, extra)
	local succ, msg = DeveloperStoreService:AddStoreItem(playerId, itemId, num, extra)
	if not succ then
		print("AddStoreItemToPlayer failed", msg)
		return
		end
	-- 待玩家在线后, 调用 ApplyStoreItems 来触发购买道具的回调 OnDeveloperStoreGoods
	print("AddStoreItemToPlayer success", msg)
	return succ, msg
end