php 开发Google支付回调验证并发货

来源:互联网 发布:java四舍五入取整 编辑:程序博客网 时间:2024/05/16 15:22

主:开发国外接口一定要记得翻墙,本人开发就吃了这个亏,之前一直跑不通,并没有任何返回,也找不到报错原因,最终发现无法访问国外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"));}}}


参考地址0:https://developer.android.com/google/play/billing/billing_reference.html
参考地址1:https://developer.android.com/google/play/billing/billing_integrate.html#billing-security
php服务器订单校验参考地址:http://www.luanhailiang.cn/blog/?post=47

原创粉丝点击