PowerBuilder
PowerBuilder
UniPin Game List
See more UniPin Examples
Demonstrates how to send a POST with the hash_hmac(sha256,partnerid+timestamp+path,secretkey) authentication.Chilkat PowerBuilder Downloads
integer li_rc
integer li_Success
oleobject loo_Http
oleobject loo_Dt
string ls_Timestamp
string ls_PartnerId
oleobject loo_Crypt
oleobject loo_SbMacData
string ls_Auth
oleobject loo_Resp
oleobject loo_SbResponseBody
oleobject loo_JResp
integer li_RespStatusCode
string ls_Game_category
string ls_Game_code
string ls_Game_name
string ls_Icon_url
string ls_Game_status
string ls_Updated_at
integer li_Status
string ls_Reason
integer i
integer li_Count_i
li_Success = 0
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
loo_Http = create oleobject
li_rc = loo_Http.ConnectToNewObject("Chilkat.Http")
if li_rc < 0 then
destroy loo_Http
MessageBox("Error","Connecting to COM object failed")
return
end if
// Implements the following CURL command:
// curl --request POST 'https://dev-api.unipin.com/in-game-topup/list' \
// --header 'partnerid: 587e3675-e0ed-4e9e-9b39-099b11498fdc' \
// --header 'timestamp: 1566552295' \
// --header 'path: in-game-topup/list' \
// --header 'auth: 1d9f5e7aca9f3c14da7c957d6977447739877cebfc10fcf3682bd32da47a2bda' \
// --header 'Content-Type: application/json'
// Use the following online tool to generate HTTP code from a CURL command
// Convert a cURL Command to HTTP Source Code
loo_Dt = create oleobject
li_rc = loo_Dt.ConnectToNewObject("Chilkat.CkDateTime")
loo_Dt.SetFromCurrentSystemTime()
ls_Timestamp = loo_Dt.GetAsUnixTimeStr(0)
// Change this to your actual partner ID.
ls_PartnerId = "587e3675-e0ed-4e9e-9b39-099b11498fdc"
loo_Http.SetRequestHeader("path","in-game-topup/list")
loo_Http.SetRequestHeader("timestamp",ls_Timestamp)
loo_Http.SetRequestHeader("partnerid",ls_PartnerId)
loo_Http.SetRequestHeader("Content-Type","application/json")
// Calculate the auth header using hash_hmac(sha256,partnerid+timestamp+path,secretkey)
loo_Crypt = create oleobject
li_rc = loo_Crypt.ConnectToNewObject("Chilkat.Crypt2")
loo_Crypt.MacAlgorithm = "hmac"
loo_Crypt.HashAlgorithm = "sha256"
loo_Crypt.EncodingMode = "hexlower"
// Change this to your actual secret key..
loo_Crypt.SetMacKeyEncoded("wabc123asljdgadlgd3","us-ascii")
loo_SbMacData = create oleobject
li_rc = loo_SbMacData.ConnectToNewObject("Chilkat.StringBuilder")
loo_SbMacData.Append(ls_PartnerId)
loo_SbMacData.Append(ls_Timestamp)
loo_SbMacData.Append("in-game-topup/list")
ls_Auth = loo_Crypt.MacStringENC(loo_SbMacData.GetAsString())
loo_Http.SetRequestHeader("auth",ls_Auth)
loo_Resp = create oleobject
li_rc = loo_Resp.ConnectToNewObject("Chilkat.HttpResponse")
li_Success = loo_Http.HttpNoBody("POST","https://dev-api.unipin.com/in-game-topup/list",loo_Resp)
if li_Success = 0 then
Write-Debug loo_Http.LastErrorText
destroy loo_Http
destroy loo_Dt
destroy loo_Crypt
destroy loo_SbMacData
destroy loo_Resp
return
end if
loo_SbResponseBody = create oleobject
li_rc = loo_SbResponseBody.ConnectToNewObject("Chilkat.StringBuilder")
loo_Resp.GetBodySb(loo_SbResponseBody)
loo_JResp = create oleobject
li_rc = loo_JResp.ConnectToNewObject("Chilkat.JsonObject")
loo_JResp.LoadSb(loo_SbResponseBody)
loo_JResp.EmitCompact = 0
Write-Debug "Response Body:"
Write-Debug loo_JResp.Emit()
li_RespStatusCode = loo_Resp.StatusCode
Write-Debug "Response Status Code = " + string(li_RespStatusCode)
if li_RespStatusCode >= 400 then
Write-Debug "Response Header:"
Write-Debug loo_Resp.Header
Write-Debug "Failed."
destroy loo_Http
destroy loo_Dt
destroy loo_Crypt
destroy loo_SbMacData
destroy loo_Resp
destroy loo_SbResponseBody
destroy loo_JResp
return
end if
// Sample JSON response:
// (Sample code for parsing the JSON response is shown below)
// {
// "game_list": [
// {
// "game_category": "MLBB_ID",
// "game_code": "MLBBD_ID",
// "game_name": "Mobile Legends Diamonds",
// "icon_url": "http://dev-backoffice.unipin.com/images/icon_direct_topup_games/1565343343-icon-1548659712-icon-Mobile legend 300x300 px.png",
// "game_status": "active",
// "updated_at": "2019-08-09 16:35:43"
// },
// {
// "game_category": "MLBB_ID",
// "game_code": "MLBBS_ID",
// "game_name": "Mobile Legends Starlight Member",
// "icon_url": "http://dev-backoffice.unipin.com/images/icon_direct_topup_games/1565343258-icon-1548659712-icon-Mobile legend 300x300 px.png",
// "game_status": "active",
// "updated_at": "2019-08-09 16:34:18"
// },
// ...
// ...
// ],
// "status": 1,
// "reason": "Successful"
// }
// Sample code for parsing the JSON response...
// Use the following online tool to generate parsing code from sample JSON:
// Generate Parsing Code from JSON
li_Status = loo_JResp.IntOf("status")
ls_Reason = loo_JResp.StringOf("reason")
i = 0
li_Count_i = loo_JResp.SizeOfArray("game_list")
do while i < li_Count_i
loo_JResp.I = i
ls_Game_category = loo_JResp.StringOf("game_list[i].game_category")
ls_Game_code = loo_JResp.StringOf("game_list[i].game_code")
ls_Game_name = loo_JResp.StringOf("game_list[i].game_name")
ls_Icon_url = loo_JResp.StringOf("game_list[i].icon_url")
ls_Game_status = loo_JResp.StringOf("game_list[i].game_status")
ls_Updated_at = loo_JResp.StringOf("game_list[i].updated_at")
i = i + 1
loop
destroy loo_Http
destroy loo_Dt
destroy loo_Crypt
destroy loo_SbMacData
destroy loo_Resp
destroy loo_SbResponseBody
destroy loo_JResp