跳到主要内容

直充

一、后端对接

请完成后端直充支付的接入,在后端实现对应接口后,再执行下一步操作。

未实现后端接口就进行页面对接,可能会触发平台服务器的告警。

二、客户端对接

用户充值在一个网页完成,因此客户端需要使用 SDK 在 WebView 打开指定支付页面。

SDK 方法名称

XL_OpenPayUrlXL_OpenPayUrlW(宽字符接口)

调用示例

// 以下代码依赖 Windows API
#include <windows.h>

// 打开支付页面的接口导出为 XL_OpenPayUrl
HMODULE hModule = GetModuleHandle(_T("XLGameLauncher.dll"));
if (hModule || (hModule = LoadLibrary(_T("XLGameLauncher.dll"))))
{
void(WINAPI * XL_OpenPayUrl)(LPCSTR, LPCSTR);

(PVOID &)XL_OpenPayUrl = GetProcAddress(hModule, "XL_OpenPayUrl");

if (XL_OpenPayUrl)
{
// 第一个参数是支付链接,链接格式见下方文档解释
XL_OpenPayUrl("https://youxi.xunlei.com/gamepay?gameId=xxxx&serverId=xxxx&roleId=xxxx", userId);
}
}

// 打开支付页面的宽字符接口导出为 XL_OpenPayUrlW
HMODULE hModule = GetModuleHandle(_T("XLGameLauncher.dll"));
if (hModule || (hModule = LoadLibrary(_T("XLGameLauncher.dll"))))
{
void(WINAPI * XL_OpenPayUrlW)(LPCWSTR, LPCWSTR);

(PVOID &)XL_OpenPayUrlW = GetProcAddress(hModule, "XL_OpenPayUrlW");

if (XL_OpenPayUrlW)
{
// 第一个参数是支付链接,链接格式见下方文档解释
XL_OpenPayUrlW(L"https://youxi.xunlei.com/gamepay?gameId=xxxx&serverId=xxxx&roleId=xxxx", userId);
}
}

调用参数说明

参数类型说明
支付链接string详见支付链接章节
userIdstring平台的用户 ID

支付链接

支付链接格式为:https://youxi.xunlei.com/gamepay?gameId=xxxx&serverId=xxxx&roleId=xxxx,链接中的 gameId serverId roleId 参数请根据下方说明替换为实际值。

链接参数说明

参数类型必选说明
gameIdstring平台的游戏
serverIdstring游戏的区服 ID
roleIdstring游戏的角色 ID(如果没有可不填)

Unity C# 代码示例

using System;
using System.Runtime.InteropServices;
using UnityEngine;

public partial class XLGamePlatform : MonoBehaviour
{
private const string DLL_NAME = "XLGameLauncher.dll";

#region DLL Import for Payment

[DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Ansi)]
private static extern void XL_OpenPayUrl(
[MarshalAs(UnmanagedType.LPStr)] string url,
[MarshalAs(UnmanagedType.LPStr)] string userId
);

[DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Unicode)]
private static extern void XL_OpenPayUrlW(
[MarshalAs(UnmanagedType.LPWStr)] string url,
[MarshalAs(UnmanagedType.LPWStr)] string userId
);

#endregion

#region Public Payment API

/// <summary>
/// 打开直充支付页面
/// </summary>
/// <param name="url">支付链接</param>
/// <param name="userId">平台的用户 ID</param>
public static void OpenPayUrl(string url, string userId)
{
if (!IsDllLoaded())
{
Debug.LogError("[XLGamePlatform] 迅雷游戏平台 DLL 未加载");
Debug.LogError("[XLGamePlatform] 游戏需要从迅雷游戏客户端启动才能正确使用 DLL,如有疑问请联系迅雷游戏平台技术人员");
return;
}
Debug.Log($"[XLGamePlatform] XL_OpenPayUrlW({url}, {userId})");
XL_OpenPayUrlW(url, userId);
}

/// <summary>
/// 打开直充支付页面(ANSI 版本)
/// </summary>
public static void OpenPayUrlAnsi(string url, string userId)
{
if (!IsDllLoaded())
{
Debug.LogError("[XLGamePlatform] 迅雷游戏平台 DLL 未加载");
return;
}
Debug.Log($"[XLGamePlatform] XL_OpenPayUrl({url}, {userId})");
XL_OpenPayUrl(url, userId);
}

#endregion

#region Helper Methods

/// <summary>
/// 检查迅雷游戏平台 DLL 是否已经加载
/// </summary>
public static bool IsDllLoaded()
{
return GetModuleHandle(DLL_NAME) != IntPtr.Zero;
}

#endregion

#region Windows API

[DllImport("kernel32.dll")]
private static extern IntPtr GetModuleHandle(string lpModuleName);

#endregion

#region Charge Example

/// <summary>
/// 示例:打开直充支付链接
/// </summary>
public void OpenChargeUrl(string gameId, string serverId, string roleId, string userId)
{
// 构建直充支付 URL
string payUrl = $"https://youxi.xunlei.com/gamepay?gameId={gameId}&serverId={serverId}&roleId={roleId}";

// 调用 SDK 打开支付页面
OpenPayUrl(payUrl, userId);
}

#endregion
}