Open webpage (OpenUrl)
[Player Network SDK & MSDK] Opening a web page is mainly done through the WebView module to display a specified web page, and the WebView display is controlled according to different parameters.
MSDK does not currently support Windows.
Function Definition
- Unity
- Unreal Engine
void OpenUrl(string url,
int screenOrientation = 1,
bool fullScreenEnable = false,
bool encryptEnable = true,
bool systemBrowserEnable = false,
string extraJson = "{}");
static void OpenUrl(
const std::string &url,
int screen_orientation = 1,
bool full_screen_enable = false,
bool encrypt_enable = true,
bool system_browser_enable = false,
const std::string &extra_json = "{}");
Input Parameters
- Unity
- Unreal Engine
| Parameters | Type | Description |
|---|---|---|
| url | string | Webpage address Chinese in URL must be url encoded |
| screenOrientation | int | Auto = 1 Portrait = 2 Landscape = 3 |
| fullScreenEnable | bool | Whether the webpage is opened in full screen Default: false |
| encryptEnable | bool | Add Login State Data to the Link Default: true If encryptEnable is true and the user is logged in, the specified URL will be encrypted |
| systemBrowserEnable | bool | Whether to open using the system browser Default: false |
| extraJson | string | JSON format extended field, please see MSDK document or Player Network documentation. Default is empty |
| Parameters | Type | Description |
|---|---|---|
| url | std::string | Webpage address Chinese in URL must be url encoded |
| screen_orientation | int | Auto = 1 Portrait = 2 Landscape = 3 |
| full_screen_enable | bool | Whether the webpage is opened in full screen Default: false |
| encrypt_enable | bool | Add Login State Data to the Link Default: true If encryptEnable is true and the user is logged in, the specified URL will be encrypted |
| system_browser_enable | bool | Whether to open using the system browser Default: false |
| extra_json | std::string | JSON format extended field, please see MSDK document or Player Network documentation. Default is empty |
Event Page Parameters
| Parameters | Description |
|---|---|
| role_id | Role ID |
| role_name | Role name URL-encoded |
| area_id | Region ID |
| zone_id | Zone ID |
| lang_type | Language type (RFC 4646) For example, "en". For details, see Language Type Definition. |
Callback Handling
The callback handling interface is GUAWebViewResultObserver.The callback data structure is GUAWebViewRet.
- Unity
- Unreal Engine
The callback event is WebViewRetEvents. The callback ID is GUA_WEBVIEW_CLOSE_URL.
The callback event is OnWebViewOptNotify. Callback ID is kMethodIDWebViewURLClose.
Code Example
If the passed-in URL cannot be opened, please check if the provided URL is correct.
For example:
- Parameters must not contain spaces
- URLs containing Chinese must be url encoded
- Unity
- Unreal Engine
// Default effect to open URL
UnionAdapterAPI.GetWebViewService().OpenUrl("https://www.qq.com");
// Open URL and add login state data
UnionAdapterAPI.GetWebViewService().OpenUrl("https://www.qq.com", 1, false, true);
// Default effect to open event URL
UnionAdapterAPI.GetWebViewService().OpenUrl("https://www.qq.com?role_id=1&role_name=aaa&area_id=1&zone_id=1&lang_type=en");
// Open URL and adjust the width and height of Windows WebView
UnionAdapterAPI.GetWebViewService().OpenUrl("https://www.qq.com", 1, false, true, false, "{\"height\": 60, \"width\": 80}");
// Default effect to open URL
GUA_NAMESPACE::GUAWebViewService::OpenUrl("https://www.qq.com");
// Open URL and add login state data
GUA_NAMESPACE::GUAWebViewService::OpenUrl("https://www.qq.com", 1, false, true);
// Default effect to open event URL
GUA_NAMESPACE::GUAWebViewService::OpenUrl("https://www.qq.com?role_id=1&role_name=aaa&area_id=1&zone_id=1&lang_type=en");
// Open URL and adjust the width and height of Windows WebView
GUA_NAMESPACE::GUAWebViewService::OpenUrl("https://www.qq.com", 1, false, true, false, "{\"height\": 60, \"width\": 80}");
Adding login data to links
If you want the link to automatically include login state and other parameters, the user must be logged in and call OpenURL with encryptEnable=true.
- Unity
- Unreal Engine
GUA_NAMESPACE::GUAWebViewService::OpenUrl("https://www.qq.com", 1, false, true);
GUA_NAMESPACE::GUAWebViewService::OpenUrl("https://www.qq.com", 1, false, true);
-
If the user is not logged in and
OpenURLis called withencryptEnable = true, the opened link will be:https://www.qq.com -
If the user is not logged in and
OpenURLis called withencryptEnable = true, the opened link will be:https://www.qq.com?gameid=11&channelid=3&os=1&ts=1634707615&sdk_version=1.11.00.487&seq=11-3b61c8315b91d319eaa5622d72c474ec7ee395cee116d142a74b3455607e3d21-1634707615-14&encodeparam=C524E9DE27EB02E552CFBA9C54BFA301317DF66F49C5C02ED708D582B80A1B74DE8F0723731F0D66EBD12095E244097DC3AFAE1203A8FCD2A2821C1DEC9CD3AE254BAD99C93B095E8F39FCE414FBFB0A79F9EA8DF2E1B309190E5A8721A5AC8132E8E89506CDBA1ACBB1C17AA794A658502C5CCA6B25E6105049EABB44C408700FE2713FDD327217AF45A226F46FFD02
URL Parameters
| Parameters | Description |
|---|---|
| gameid | ID assigned to the game |
| channelid | Login channel ID |
| OS | Terminal operating system identifier 1 : Android 2 : iOS 3 : Web 4 : Linux 5 : Windows 6 : Switch |
| ts | Timestamp |
| sdk_version | MSDK or Player Network SDK version |
| seq | Sequence number |
| encodeparam | Encrypted fields for account OpenID and token Obtained via the [GetEncodeUrl interface(/docs/resources/api/UnionAdapter/WebViewService/GUAGetEncodeUrl) Decrypted and verified through backend APIs of MSDK or [Player Network SDK(/docs/resources/api/Backend/Auth/decrypt_aes#interface) to get the corresponding parameters. |
Open Event Page
To allow the event page to access in-game parameter information, when the game opens an in-game event through WebView, the Url needs to include the Event Page Parameters. For specific parameters, please contact MSDK or Player Network support.