支付请求
收藏我的收藏
TT.OpenAwemeCustomerService
6.0.0 开始支持本方法
通过客服页面发起支付。
前提条件 |
fail im disable)
|
业务背景 | 无 |
使用限制 |
|
注意事项 |
save_amt 的变化来确定是否充值成功。
|
相关教程 | 支付能力接入:支付能力接入介绍 钻石支付接入:钻石兑换介绍及接入指引 |
语法
public static void OpenAwemeCustomerService(OpenAwemeCustomerServiceParam param)
注意:
以下示例代码对应 TTSDK 版本<
6.1.1,已过时。public static void OpenAwemeCustomerService(JsonData options, Action success, Action<int, string> failed);
参数说明
属性名 | 类型 | 默认值 | 必填 | 说明 |
options | JsonData | -- | 是 | 格式详情 |
success | Action | -- | 是 | 打开客服页成功 |
failed | Action<int, string> | -- | 是 | 打开客服聊天页回调,参数为是否成功,true表示成功,false表示失败。 |
JsonData 内容格式:
| 格式 | 默认值 | 是否必填 | 说明 |
buyQuantity | number | -- | 是 | 金币购买数量,金币数量必须满足:金币数量*金币单价 = 限定价格等级(详见下方 buyQuantity 限制说明。) |
customId | string | -- | 是 | 游戏开发者自定义的唯一订单号,订单支付成功后通过服务端支付结果回调回传 |
currencyType | string | -- | 否 | 币种,枚举值 •DIAMOND - 表示钻石,目前仅支持该类型 |
zoneId | string | 1 | 否 | 游戏服务区 id,开发者自定义。游戏不分大区则默认填写"1"。如果应用支持多角色,则角色 ID 接在分区 ID 后,用"_"连接 |
extraInfo | string | null | 否 | 游戏开发者自定义的其他信息,订单支付成功后通过服务端支付结果回调回传。字符串长度最大不能超过 256。(强烈建议传入) |
goodType | number | | 否 | 支付场景 |
goodName | string | | 否 | goodType为道具直购场景时,代表道具名称,长度限制小于等于10个字符,用于区分道具类型 |
orderAmount | number | | 否 | goodType为道具直购场景时必传,代表道具现金价格,单位为【分】,如道具价格为0.1元,则回传10 |
buyQuantity 限制说明:
购买游戏币的数量,开发者可以在字节小游戏平台的“支付”tab 设置游戏币单价,换算成 RMB 必须满足以下价格档位, 即 buyQuantity * 游戏币单价 = 限定价格等级。如:游戏币单价为 0.1 元,一次购买数量至少是 10 个。
限定价格等级(单位:元) | 1 3 6 8 12 18 25 30 40 45 50 60 68 73 78 88 98 108 118 128 148 168 188 198 328 648 998 1998 2998 |
orderAmount 参数说明:
由于 goodType 需要在 TTSDK 6.0.8 及以上版本、基础库版 本 3.47.0 及以上才可支持,可使用:
CanIUse.OpenAwemeCustomerServiceParams.GoodType
来判断是否支持,与其他支付方式做好版本兼容。
goodType 合法值:
- •0:默认值,表示游戏币场景
- •1:游戏币场景
- •2:道具直购场景
错误码
OpenAwemeCustomerServiceParam
6.1.1版本开始支持
语法
public class OpenAwemeCustomerServiceParam { /// <summary> /// 必填(道具直购场景除外) 金币购买数量,金币数量必须满足:金币数量*金币单价 = 限定价格等级(详见下方 buyQuantity 限制说明。开发者可以在字节小游戏平台的“支付”tab 设置游戏币单价) /// </summary> public int BuyQuantity; /// <summary> /// 必填 游戏开发者自定义的唯一订单号,订单支付成功后通过服务端支付结果回调回传 /// </summary> public string CustomId; /// <summary> /// 非必填 币种, 目前仅为"DIAMOND" /// </summary> public string CurrencyType; /// <summary> /// 非必填 游戏服务区 id,默认值为1,开发者自定义。游戏不分大区则默认填写"1"。如果应用支持多角色,则角色 ID 接在分区 ID 后,用"_"连接 /// </summary> public string ZoneId; /// <summary> /// 非必填 游戏开发者自定义的其他信息,订单支付成功后通过服务端支付结果回调回传。字符串长度最大不能超过 256。(强烈建议传入) /// </summary> public string ExtraInfo; /// <summary> /// 非必填(道具直购场景必填) 默认游戏币。 游戏币:0 | 1,道具直购:2。若goodType为道具直购场景,不可传buyQuantity /// </summary> public int GoodType; /// <summary> /// 非必填(道具直购场景必填) 道具价格,人民币,单位分 /// </summary> public int OrderAmount; /// <summary> /// 非必填 道具名称 /// </summary> public string GoodName; /// <summary> /// 非必填 (礼包场景必填)礼包Id /// </summary> public string GoodsId; /// <summary> /// OpenAwemeCustomer 成功回调 /// </summary> public OpenAwemeCustomerSuccessCallback Success; /// <summary> /// OpenAwemeCustomer 失败回调 /// </summary> public Action<ErrorInfo> Fail; /// <summary> /// 接口调用完成回调 /// </summary> public Action Complete; } public class OpenAwemeCustomerSuccessResult { /// <summary> /// 错误信息 /// </summary> public string ErrMsg; /// <summary> /// 支付时间 /// </summary> public long PayTime; }
代码示例
if (CanIUse.OpenAwemeCustomerServiceParams.GoodType) { // 道具直购 var param = new OpenAwemeCustomerServiceParam { CustomId = (TimeUtils.GetCurrentTimeMs() / 1000).ToString(), CurrencyType = "DIAMOND", ZoneId = "1", ExtraInfo = "sc diamond pay test extra", GoodType = 2, GoodName = "测试商品", OrderAmount = int.Parse(inputPrice.text), Success = successResult => { Debug.Log($"OpenAwemeCustomerService Success , errMsg: {successResult.ErrMsg}, " + $"GiftId: {successResult.Gift?.GiftId} , GiftCode: {successResult.Gift?.GiftCode}, status: {successResult.Gift?.Status}" ); }, Fail = failResult => { Debug.Log($"OpenAwemeCustomerService Fail , errMsg: {failResult.ErrMsg}, " + $"errCode: {failResult.ErrorCode} , errorType: {failResult.ErrorType}"); }, Complete = () => { Debug.Log("OpenAwemeCustomerService Complete"); } }; TT.OpenAwemeCustomerService(param); } else { // 钻石支付 var param = new OpenAwemeCustomerServiceParam { BuyQuantity = int.Parse(inputPrice.text), CustomId = (TimeUtils.GetCurrentTimeMs() / 1000).ToString(), CurrencyType = "DIAMOND", ZoneId = "1", ExtraInfo = "sc diamond pay test extra", Success = successResult => { Debug.Log($"OpenAwemeCustomerService Success , errMsg: {successResult.ErrMsg}, " + $"GiftId: {successResult.Gift?.GiftId} , GiftCode: {successResult.Gift?.GiftCode}, status: {successResult.Gift?.Status}" ); }, Fail = failResult => { Debug.Log($"OpenAwemeCustomerService Fail , errMsg: {failResult.ErrMsg}, " + $"errCode: {failResult.ErrorCode} , errorType: {failResult.ErrorType}"); }, Complete = () => { Debug.Log("OpenAwemeCustomerService Complete"); } }; TT.OpenAwemeCustomerService(param); }
注意
以下示例代码对应 TTSDK 版本<
6.1.1,已过时。if (CanIUse.OpenAwemeCustomerServiceParams.GoodType) { var quantity = int.Parse(inputPrice.text); var options = new JsonData { ["customId"] = (TimeUtils.GetCurrentTimeMs() / 1000).ToString(), ["currencyType"] = "DIAMOND", ["zoneId"] = "1", ["extraInfo"] = "sc diamond pay test extra", ["goodType"] = 2, ["orderAmount"] = quantity, ["goodName"] = "测试商品" }; TT.OpenAwemeCustomerService(options, () => { Debug.Log("OpenAwemeCustomerService success"); }, (errCode, errMsg) => { Debug.Log($"OpenAwemeCustomerService failed, errCode: {errCode}, errMsg: {errMsg}"); }); } else { var quantity = int.Parse(inputPrice.text); var options = new JsonData { ["buyQuantity"] = quantity, ["customId"] = (TimeUtils.GetCurrentTimeMs() / 1000).ToString(), ["currencyType"] = "DIAMOND", ["zoneId"] = "1", ["extraInfo"] = "sc pay test extra" }; TT.OpenAwemeCustomerService(options, () => { Debug.Log("OpenAwemeCustomerService success"); }, (errCode, errMsg) => { Debug.Log($"OpenAwemeCustomerService failed, errCode: {errCode}, errMsg: {errMsg}"); }); }
TT.RequestGamePayment
6.0.0 开始支持本方法,WebGL也支持该方法
发起支付。
支付接入流程:
抖音开发者平台接口文档:
提示异常情况下,充值有可能存在游戏币延迟到账问题,建议游戏在收到支付结果回调后,向服务端轮询最新游戏币余额,间隔 3 秒,持续约 1 分钟,可以根据返回值的 save_amt 的变化来确定是否充值成功。 同时也存在一些异常情况,导致充值成功后结果回调失败,因此建议游戏在启用游戏时主动查询游戏币余额,并且提供给用户主动刷新余额的功能。(不要将查询余额作为进入游戏的必要条件,查询失败时,可在显示余额的界面显示异常,不要拒绝用户进入游戏,更不要直接显示 0) 强烈建议请求中填入 customId 和 extraInfo 字段(字段意义见下方表格),如果未填,支付结果回调将不包含游戏开发者的订单号,导致开发者无法确定回调是对应哪个订单,从而影响游戏道具发放。如果遇到此类问题,开发者可调用queryPayState 接口进行订单状态确认。以上三条均属建议,供游戏参考。
语法
public static void RequestGamePayment(RequestGamePaymentParam param)
注意:
以下示例代码对应 TTSDK 版本<
6.1.1,已过时。public static void RequestGamePayment(Dictionary<string, object> orderInfo, Action payCallback = null, Action<int, string> errCallback = null)
参数说明
属性名 | 类型 | 默认值 | 必填 | 说明 |
orderInfo | Dictionary<string, object> | - |
