# Initialization
Initialization is the first step of all API calls and requires two parameters, appid
and version
.
- * appid: allocated by the company platform
- * version: main version number of the game app (strictly adhere to software version numbering rules and principles; package version numbers (opens new window))
GHomeAPI::getInstance()->Init("791000xxx", "1.0.0");
1
# Login
Call ShowLogin
with two parameters: the scene to display it in and a callback function that returns true if successful (with user information) or false if failed.
GHomeAPI::getInstance()->ShowLogin(scene, [](bool success, GHUserInfo user) {
if (success) {
auto scene = GameScene::createScene();
Director::getInstance()->replaceScene(scene);
GHToast::ShowToast(u8"Login successful");
} else {
GHToast::ShowToast(u8"Login failed");
Director::getInstance()->end();
}
});
1
2
3
4
5
6
7
8
9
10
2
3
4
5
6
7
8
9
10
# Logout
Logout can be performed by calling logout
.
GHomeAPI::getInstance()->Logout();
1
# Get Ticket
After a successful login, use GetTicket
to obtain the ticket. In the callback, if true is returned, it means the ticket was successfully obtained; false indicates failure.
GHomeAPI::getInstance()->GetTicket([](bool success, std::string ticket) {
if (success) {
GHToast::ShowToast(StringUtils::format(u8"[demo] ticket: %s", ticket.c_str()));
} else {
GHToast::ShowToast(u8"[demo] Failed to get ticket");
}
});
1
2
3
4
5
6
7
2
3
4
5
6
7
# Payment
Payment is initiated by calling Pay
which opens the browser for payment.
void Pay(cocos2d::Scene *scene, const std::string &areaId, const std::string &groupId, const std::string &productId, const std::string &gameOrder, const std::string &extend, const ghomePayCallback callback);
1
- areaId: required parameter
- groupId: required parameter
- productId: required parameter
- gameOrder: required parameter
- extend: pass an empty string if not needed
- callback: payment callback
GHomeAPI::getInstance()->Pay(scene, "10001", "1", "com.ghsdk.demo.product1", "1", "1", [](long code, std::string msg) {
if (code == 404 && msg.empty()) {
msg.append("404");
}
});
1
2
3
4
5
2
3
4
5
# Compile demo
Before compiling, install cmake
.
# Mac application, Xcode project
cd proj.ios_mac/mac
cmake ../../ -GXcode
open cocos-ghome-sdk.xcodeproj
1
2
3
2
3
# Windows application, Visual Studio project
cd proj.win32
cmake .. -G"Visual Studio 15 2017" -A win32
1
2
2
Open cocos-ghome-sdk.sln
.
# Mac/Linux application, manual compilation
mkdir build && cd build
cmake ..
make -j8
1
2
3
2
3
# Appendix
# Cocos version
It is recommended to use cocos 2dx 4.0 environment for running.
# Download instructions
- cocos 2dx download summary: https://www.cocos.com/cocos2dx-download (opens new window)
- /cocos 2dx 4.0 download: https://cocos2d-x.org/filedown/cocos2d-x-v4.0 (opens new window)