1. 程式人生 > >php 開發Google支付回撥驗證併發貨

php 開發Google支付回撥驗證併發貨

主:開發國外介面一定要記得翻牆,本人開發就吃了這個虧,之前一直跑不通,並沒有任何返回,也找不到報錯原因,最終發現無法訪問國外Google伺服器。。。。

public function JpGooglePay(){
	$google_public_key = "你的公鑰(google後臺在你的應用下獲取)";
	$inapp_purchase_data  = $_REQUEST['signtureTemp']; 
	$inapp_data_signature = $_REQUEST['signtureDataTemp'];
	$requestData 	= json_decode($inapp_purchase_data,TRUE);
	$goodsid  		= $requestData['productId'];
	$paytime 		= $requestData['purchaseTime']; 
	$paytime 		= substr($paytime,0,10);
	$paytype 		= $requestData['purchaseState']; 
	$transaction_id = $requestData['developerPayload'].'-'.$requestData['purchaseTime'];
	$gameOrderId	= $requestData['developerPayload'];
	
	$key 		= "-----BEGIN PUBLIC KEY-----\n".chunk_split($google_public_key, 64,"\n").'-----END PUBLIC KEY-----';
	$key 		= openssl_pkey_get_public($key); 
	$signature 	= base64_decode($inapp_data_signature);
    $ok 		= openssl_verify($inapp_purchase_data,$signature,$key,OPENSSL_ALGO_SHA1);
	
	$ExityCurrorder = $this->googleVerifiyRepeatOrder($transaction_id); //重複訂單驗證
	if($ExityCurrorder != 0 ){
		echo  json_encode(array("resoult"=>102,"msg"=>"repeat order"));
	}
	else
	{
		/*$file = "C:\\Error\\msg.txt";	
		$info =  "\r\n\r\n"."ok:".$ok.
				 "\r\n"."signture:".$inapp_data_signature.
				 "\r\n"."signtureData:".$inapp_purchase_data.
				 "\r\n"."time:".date('Y-m-d H:i:s',time());
		file_put_contents($file, $info, FILE_APPEND); */
		
		if (1 == $ok) {
			// 支付驗證成功!
			$verifiyOredr = $this->GetOrderInfo_SelfRecharge($transaction_id); //發貨重複訂單驗證
			if($verifiyOredr == 0){
				//通知發貨
				echo  json_encode(array("resoult"=>0,"msg"=>"success"));
			}
			else {
				echo  json_encode(array("resoult"=>102,"msg"=>"repeat order"));
			}
		}else{
			echo  json_encode(array("resoult"=>101,"msg"=>"invalid order"));
		}
	}			
}