苹果返回

更新时间:2023-03-20 04:52:47 阅读: 评论:0

正宗红烧肉-鸭舌

苹果返回
2023年3月20日发(作者:校园礼仪)

ios苹果内购订单验证---php实现

验证函数:

functionappleVerify($receipt_data,$o大将军韩信 rderId=0)

{

/*

*21000AppStore不能读取你提供的JSON对象

*21002receipt-data域的数据有问题

*21003receipt⽆法通过验证

*21004提供的sharedcret不匹配你账号中的sharedcret

*21005receipt服务器当前不可⽤

*21006receipt合法,但是订阅已过期。服务器接收到这个状态码时,re皮衣清洗 ceipt数据仍然会解码并⼀起发送

*21007receipt是Sandboxreceipt,但却发送⾄⽣产系统的验证服务

*21008receipt是⽣产receipt,但却发送⾄Sandbox环境的验证服务

*$receipt_data苹果返回的⽀付凭证

*正式:/verifyReceipt

*沙箱:/verifyReceipt

*/

$env=App::environment();

if($env=='online'){

//线上环境

$url='/verifyReceipt';

}el{

//沙盒环境

$url='/verifyReceipt';

}

$num=0;

while(1){

$num++;

$respon=Curl::to($url)

->withData(array('receipt-data'=>$receipt_data))

->asJson(true)

->post();

if($respon['status']!=21005||$num>=3){

break;

}

}

//$respon=json_decode($respon,true);

//$data['status']==0成功

//$data['receipt']['in_app'][0]['transaction_id']苹果订单号

//$data['receipt']['in_app'][0]['product_id'];商品价格

//$data['receipt']['in_app'][0]['purcha_date_ms']

$status=0;

$purchaTime=0;

if($respon['status']==0){

$status=1;

try{

$inapps=$respon['receipt']['in_app'];

$purchaTime=$inapps[0]['purcha_date_ms'];

if(!empty($orderId)){

foreach($inappsas$item){

if($orderId==$item['transaction_id']){

$purchaTime=$item['purcha_date_ms'];

break;

}

}

}

}catch(Exception$e){

return['status'=>0,'purcaTime'=>0];

}

}

return['status'=>$status,'purcaTime'=>$purchaTime];

}

参数说明:

//$receipt_data:ios购买时苹果服务器返回的订单信息

//$orderId:订单号,验证订单是返回的内购订单数据可能会有多条($respon['receipt']['in_app']有多条数据),所以需要遍历每条记录,找到跟订单ID⼀样的那⼀条数据的观海听涛书法 购买时间。

$receipt_data="";

$orderId="1339";

返回数据:验证订单获取的数据$respon:(其中in_app有多个)。

{

"receipt":{

"receipt_type":"Production",

"adam_id":127345,

"app_item_id":12732445,

"bundle_id":"",

"application_version":"62"感动中国十大人物事迹 ,

"download_id":6703453,

"version_external_identifier":829054,

"receipt_creation_date":"2019-03-2902:03:00Etc/GMT",

"receipt_creation_date_ms":"1553820000",

"receipt_creation_date_pst":"2019-03-2819:03:00America/Los_Angeles",

"request_date":"2019-04-0307:04:10Etc/GMT",

"request_date_ms":"80",

"request_date_pst":"2019-04-0300:04:10America/Los_Angeles",

"original_purcha_date":"2017-10-2719:28:27Etc/GMT",

"original_purcha_date_ms":"15",

"original_purcha_date_pst":"2017-10-2712:28:27America/Los_Angeles",

"original_application_version":"3",

"in_app":[

{

"quantity":"1",

"product_id":"2",

"transaction_id":"27",

"original_transaction_id":"27",

"purcha_date":"2019-03-2902:02:59Etc/GMT",

"purcha_date_ms":"1553879000",

"purcha_date_pst":"2019-03-2819:02:59America/Los_Angeles",

"o婴儿吐奶怎么办 riginal_purcha_date":"2019-03-2902:02:59Etc/GMT",

"original_purcha_date_ms":"00",

"original_purcha_date_pst":"2019-03-2819:02:59America/Los_Angeles",

"is_trial_period":"fal"

},

{

"quantity":"1",

"product_id":"ads10",

"transaction_id":"2700005471",

"original_transaction_id":"27005471",

"purcha_date":"2017-11-1616:44:珍珠鸟课文 08Etc/GMT",

"purcha_date_ms":"151",

"purcha_date_pst":"2017-11-1608:44:08America/Los_Angeles",

"original_purcha_date":"2017-11-1616:44:08Etc/GMT",

"original_purcha_date_ms":"151",

"original_purcha_date_pst":"2017-11-1608:44:08America/Los_Angeles",

"is_trial_period":"fal"

}

]

},

"status":0,

"environment":"Production"

}

本文发布于:2023-03-20 04:52:45,感谢您对本站的认可!

本文链接:https://www.wtabcd.cn/fanwen/zuowen/1679259167317285.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

本文word下载地址:苹果返回.doc

本文 PDF 下载地址:苹果返回.pdf

上一篇:社会效果
下一篇:返回列表
标签:苹果返回
相关文章
留言与评论(共有 0 条评论)
   
验证码:
推荐文章
排行榜
Copyright ©2019-2022 Comsenz Inc.Powered by © 专利检索| 网站地图