JSSDK API

Step1: Load JSSDK

<script type="text/javascript" src="https://h-cdn.pengpengla.com/up/opengamejs/1.4.0/assets/seed.js"></script>

Step2: Initialize JSSDK

Call openSdk.init before any other API.

openSdk.init(Object object)

Parameters

Parameter Required Default Description
env No pro stage = test, pro = production
client_id Yes Application ID
game_id Yes Game ID
mode Yes diamond / gold / ad

Example

openSdk.init({
env: 'stage',
client_id: 'CLIENT_ID',
game_id: 'GAME_ID',
mode: 'diamond'
});

Step3: APIs

openSdk.oauth(Object object)

Re-authorize when credentials expire. After success, code is appended to the game URL.

Parameters

Parameter Required Description
redirect_url Yes Callback URL (usually current page)

Example

openSdk.oauth({
redirect_url: 'http://xxxx/index.html'
});

openSdk.recharge(Object object)

Open recharge UI.

Parameters

Parameter Required Description
upliveCode Yes User Funpepper code
countryCode Yes Country for payment channel (e.g. tw:mycard, id:codapay, in:paytm, other:PayPal)
lang Yes Language code from URL _lang
success No Success callback
fail No Failure callback
cancel No Cancel callback

Example

openSdk.recharge({
upliveCode: 'funpepper',
countryCode: 'TW',
lang: 'en-US',
success: function(){},
fail: function(){},
cancel: function(){}
});

openSdk.ping(Object object)

Required — report PV/UV when user enters the game.

Parameters

| Parameter | Required | Description |
| – | – | – |
| open_id | Yes | User open_id in your game |
| success | No | Success callback |

Example

openSdk.ping({
open_id: 'OPEN_ID',
success: function(){}
});


### openSdk.quitGame()

Exit game and return to lobby.

openSdk.quitGame();


### openSdk.receiveGold(object object)

Required in gold mode

Claim daily free gold (once per user per day). Not used in U Diamond mode.

Parameters

Parameter Required Description
open_id Yes User open_id
getGoldSuccess Yes Callback after claim; refresh balance here

Example

openSdk.receiveGold({
open_id: 'OPEN_ID',
getGoldSuccess: function(){}
});

openSdk.rechargeGold()

Open gold recharge page (gold mode only).

openSdk.rechargeGold();

openSdk.ads.showLandingVideo(object object)

Landing page with intro and video ad.

Parameters

Parameter Required Description
start Yes Callback when user taps “Start game”

Example

openSdk.ads.showLandingVideo({
start: function() {
alert('Enter game');
}
});

openSdk.ads.showRewardVideo(object object)

Rewarded video ad.

Parameters

Parameter Required Description
open_id Yes User open_id
success Yes User completed video; grant reward on server
close Yes true if finished and closed; false if closed early
error Yes Ad load failed

Example

openSdk.ads.showRewardVideo({
open_id: 'OPEN_ID',
success: function() {
alert('Grant reward on server')
},
close: function(status){
if (status) {
alert('Closed after complete');
} else {
alert('Closed before complete');
}
},
error: function() {
alert('Ad load failed');
}
});

Step4: Upgrade v1.2.2 → v1.2.3

Gold mode

  • Removed: openSdk.receiver(Number)
  • Added: openSdk.rechargeGold()
  • Renamed: openSdk.getGoldopenSdk.receiveGold (call on each game entry)

U Diamond mode

No changes; v1.2.2 still works for U Diamond games.

Step5: Upgrade v1.2 → v1.3.0

inviteFriendsPlayGame

Parameters

Parameter Required Description
direction Yes 0 bottom, 1 bottom-left mirror, 2 bottom-right mirror
gameId Yes Game ID (1h share limit per game per recipient)
gameIcon Yes Icon URL
inviteGameUrl Yes Share link
titleList Yes Invite titles by locale
contentList Yes Descriptions
highlightContentList Yes Highlight text
jsCallback Yes Protocol callback

Example

openSdk.inviteFriendsPlayGame({
direction: 0,
gameId: 103,
gameIcon,
inviteGameUrl,
titleList: {"en-US":"Invite title",....},
contentList: {"en-US":"Description",....},
highlightContentList: {"en-US":"Highlight",....},
jsCallback,
})