Custom code to convert

0 votes

Please convert your php code with a custom code.

function getCurl($fUrl,$fMethod,$fParam) {
$sUrl = $fUrl.(($fParam && strtolower($fMethod)=="get") ? "?$fParam": "");
$sMethod = (strtolower($fMethod)=="get") ? "0" : "1" ;
$sParam = (strtolower($fMethod)=="get") ? "" : $fParam ;
 
$ch = curl_init();
curl_setopt ($ch, CURLOPT_URL,"$sUrl"); //접속할 URL 주소
curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, FALSE); // 인증서 체크같은데 true 시 안되는 경우가 많다.
curl_setopt ($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
// default 값이 true 이기때문에 이부분을 조심 (https 접속시에 필요)
curl_setopt ($ch, CURLOPT_SSLVERSION,3); // SSL 버젼 (https 접속시에 필요)
curl_setopt ($ch, CURLOPT_HEADER, 0); // 헤더 출력 여부
curl_setopt ($ch, CURLOPT_POST, $sMethod); // Post Get 접속 여부
curl_setopt ($ch, CURLOPT_POSTFIELDS, "$fParam"); // Post 값  Get 방식처럼적는다.
curl_setopt ($ch, CURLOPT_TIMEOUT, 30); // TimeOut 값
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1); // 결과값을 받을것인지
$result = curl_exec ($ch);
curl_close ($ch);
return $result;
}
$_GET[code] = "5번의 과정을 통해 생성된 code";
if ($_GET[code]) {
$sParam = "";
$sParam .= "code=$_GET[code]";
$sParam .= "&client_id={3번 항목에서 생성한 Client ID}";
$sParam .= "&client_secret={3번 항목에서 생성한 Client Secret}";
$sParam .= "&redirect_uri={3번 항목에서 입력한 Redirect URL}";
$sParam .= "&grant_type=authorization_code"; // authorization_code 는 OAuth 2 에서는 고정값입니다.
$rResult = getCurl("https://accounts.google.com/o/oauth2/token","post","$sParam");
echo "<br />token 생성<br />$rResult<hr>";
}
 
 
function getCurl($fUrl,$fMethod,$fParam) {
$sUrl = $fUrl.(($fParam && strtolower($fMethod)=="get") ? "?$fParam": "");
$sMethod = (strtolower($fMethod)=="get") ? "0" : "1" ;
$sParam = (strtolower($fMethod)=="get") ? "" : $fParam ;
 
$ch = curl_init();
curl_setopt ($ch, CURLOPT_URL,"$sUrl"); //접속할 URL 주소
curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, FALSE); // 인증서 체크같은데 true 시 안되는 경우가 많다.
curl_setopt ($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
// default 값이 true 이기때문에 이부분을 조심 (https 접속시에 필요)
curl_setopt ($ch, CURLOPT_SSLVERSION,3); // SSL 버젼 (https 접속시에 필요)
curl_setopt ($ch, CURLOPT_HEADER, 0); // 헤더 출력 여부
curl_setopt ($ch, CURLOPT_POST, $sMethod); // Post Get 접속 여부
curl_setopt ($ch, CURLOPT_POSTFIELDS, "$fParam"); // Post 값  Get 방식처럼적는다.
curl_setopt ($ch, CURLOPT_TIMEOUT, 30); // TimeOut 값
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1); // 결과값을 받을것인지
$result = curl_exec ($ch);
curl_close ($ch);
return $result;
}
 
$sFileName = dirname(__FILE__)."/token";
$sResult = json_decode(file_get_contents($sFileName),true);
$refresh_token = addslashes($sResult["refresh_token"]);
$regdate = $sResult["regdate"];
 
 
$sResult = "";
if ((time()-$regdate)>1800) {
 
$sParam = "";
$sParam .= "refresh_token=".$refresh_token;
$sParam .= "&client_id={3번의 항목에서 생성한 Client ID}";
$sParam .= "&client_secret={3번의 항목에서 생성한 Client Secret}";
$sParam .= "&grant_type=refresh_token";
$rResult = getCurl("https://accounts.google.com/o/oauth2/token","post","$sParam");
 
$sResult = json_decode($rResult,true);
$sResult["regdate"] = "".time()."";
$sResult["refresh_token"] = $refresh_token;
 
$rResult = json_encode($sResult);
$fp=fopen($sFileName,'w');
fwrite($fp,$rResult);
fclose($fp);
 
//echo $rResult;
}
 
 
$sFileName = "token";
$sResult = json_decode(file_get_contents($sFileName),true);
 
$sUrl .= "applications/$_GET[packageName]/";
$sUrl .= "inapp/$_GET[productId]/";
$sUrl .= "purchases/$_GET[purchaseToken]/";
$sUrl .= "?access_token=$sResult[access_token]";
$rResult = file_get_contents("$sUrl");
if ($rResult == false or $rResult=="") {
echo "에러";
}
else {
echo "정상";
}
 
asked Jul 15, 2015 in App42 Cloud API-BaaS by ww1 (10 points)

1 Answer

0 votes

Hi,

Custom code is a feature where developer can write there own logic to achieve any particular requirement such as Server-Side IAP validation in your case. Writing a custom code has very easy steps which is explained here in detail. You can also get the guidelines for writing server side IAP validation from the following links:

http://developer.android.com/google/play/billing/billing_integrate.html

http://developer.android.com/google/play/billing/billing_best_practices.html"

Let us know if you face any problem.

Thanks.

answered Jul 15, 2015 by rajeev.etc (1,660 points)
Download Widgets
Welcome to ShepHertz Product line forum, where you can ask questions and receive answers from the community. You can also reach out to us on support@shephertz.com
...