|
@@ -212,58 +212,68 @@ class Payios extends Api
|
|
|
public function gold_notify_iosnew(){
|
|
|
|
|
|
//苹果内购的验证收据
|
|
|
-
|
|
|
$receipt_data = input('apple_receipt', '', 'trim');
|
|
|
- $order_no = input('order_no', '', 'trim');
|
|
|
- filePut('金币 ios充值:参数apple_receipt='.$receipt_data.',order_no='.$order_no);
|
|
|
- if (!$receipt_data || !$order_no) {
|
|
|
+ if (!$receipt_data) {
|
|
|
$this->error('缺少参数');
|
|
|
}
|
|
|
-
|
|
|
- Db::startTrans();
|
|
|
- // 查找订单
|
|
|
- $order_info = Db::name('pay_order')->where(['out_trade_no' => $order_no])->lock(true)->find();
|
|
|
- if (!$order_info) {
|
|
|
- Db::rollback();
|
|
|
- filePut('金币 ios充值:订单丢失out_trade_no='.$order_no);
|
|
|
- $this->error('订单丢失');
|
|
|
- }
|
|
|
- if ($order_info['order_status'] == 1) {
|
|
|
- Db::rollback();
|
|
|
- $this->success('充值成功');
|
|
|
- }
|
|
|
+ filePut("\r\n\r\n");
|
|
|
+ filePut('金币 ios充值:参数apple_receipt['.$receipt_data.']');
|
|
|
|
|
|
// 验证支付状态
|
|
|
$result = $this->validate_apple_pay($receipt_data);
|
|
|
if (!$result['status']) {// 验证不通过
|
|
|
- Db::rollback();
|
|
|
- filePut('金币 ios充值:验证out_trade_no='.$order_no.','.$result['message']);
|
|
|
+ filePut('金币 ios充值:验证'.$result['message']);
|
|
|
$this->error($result['message']);
|
|
|
}
|
|
|
|
|
|
$count = count($result['data']['receipt']['in_app']);
|
|
|
$use_count = $count - 1;
|
|
|
- $args = json_decode($order_info['args'],true);
|
|
|
- if ($result['data']['receipt']['in_app'][$use_count]['product_id'] != $order_info['bundle_id']) {
|
|
|
+ $product_id = $result['data']['receipt']['in_app'][$use_count]['product_id'];
|
|
|
+ $transaction_id = $result['data']['receipt']['in_app'][$use_count]['transaction_id'];
|
|
|
+
|
|
|
+
|
|
|
+ // 确认订单
|
|
|
+ $order_map = [
|
|
|
+ 'user_id' => $this->auth->id,
|
|
|
+ 'transaction_id' => $transaction_id,
|
|
|
+ 'bundle_id' => $product_id,
|
|
|
+ 'order_status' => 1,
|
|
|
+ ];
|
|
|
+ $order_check = Db::name('pay_order')->where($order_map)->find();
|
|
|
+ if (!empty($order_check)) {
|
|
|
+ filePut('金币 ios充值:检查到out_trade_no='.$order_check['out_trade_no'].',订单已支付,不需要重复');
|
|
|
+ $this->success('充值成功');
|
|
|
+ }
|
|
|
+
|
|
|
+ Db::startTrans();
|
|
|
+ // 查找订单
|
|
|
+ $order_map = [
|
|
|
+ 'user_id' => $this->auth->id,
|
|
|
+ 'bundle_id' => $product_id,
|
|
|
+ 'order_status' => 0,
|
|
|
+ ];
|
|
|
+ $order_info = Db::name('pay_order')->where($order_map)->order('id desc')->lock(true)->find();
|
|
|
+ if (!$order_info) {
|
|
|
Db::rollback();
|
|
|
- filePut('金币 ios充值:非法请求,请立刻停止out_trade_no='.$order_no.','.$result['message'].','.$result['data']['receipt']['in_app'][$use_count]['product_id'].'!='.$args['bundle_id']);
|
|
|
- $this->error('非法请求,请立刻停止');
|
|
|
+ filePut('金币 ios充值:订单不存在order_map='.json_encode($order_map));
|
|
|
+ $this->error('订单不存在');
|
|
|
}
|
|
|
+ $args = json_decode($order_info['args'],true);
|
|
|
|
|
|
//逻辑开始
|
|
|
//先充值
|
|
|
$result = model('Wallet')->lockChangeAccountRemain($order_info['user_id'],'gold',$args['gold'],10, '金币充值','pay_order',$order_info['id']);
|
|
|
if($result['status']===false)
|
|
|
{
|
|
|
- filePut('金币 ios充值:验证out_trade_no='.$order_no.',逻辑添加金币失败');
|
|
|
+ filePut('金币 ios充值:逻辑开始out_trade_no='.$order_info['out_trade_no'].',逻辑添加金币失败');
|
|
|
Db::rollback();
|
|
|
- return false;
|
|
|
+ $this->error('充值失败');
|
|
|
}
|
|
|
|
|
|
// 修改订单状态
|
|
|
- $ros = Db::name('pay_order')->where(['out_trade_no' => $order_no])->update(['order_status'=>1,'notifytime'=>time()]);
|
|
|
+ $ros = Db::name('pay_order')->where(['id' => $order_info['id']])->update(['order_status'=>1,'transaction_id' => $transaction_id,'notifytime'=>time()]);
|
|
|
if($ros === false) {
|
|
|
- filePut('金币 ios充值:充值失败out_trade_no='.$order_no.','.$result['message'].','.'修改订单状态失败');
|
|
|
+ filePut('金币 ios充值:订单修改out_trade_no='.$order_info['out_trade_no'].',修改订单状态失败');
|
|
|
Db::rollback();
|
|
|
$this->error('充值失败');
|
|
|
}
|
|
@@ -310,7 +320,7 @@ class Payios extends Api
|
|
|
$args = json_decode($order_info['args'],true);
|
|
|
if ($result['data']['receipt']['in_app'][$use_count]['product_id'] != $order_info['bundle_id']) {
|
|
|
Db::rollback();
|
|
|
- filePut('金币 ios充值:非法请求,请立刻停止out_trade_no='.$order_no.','.$result['message'].','.$result['data']['receipt']['in_app'][$use_count]['product_id'].'!='.$args['bundle_id']);
|
|
|
+ filePut('金币 ios充值:非法请求,请立刻停止out_trade_no='.$order_no.','.$result['message'].','.$result['data']['receipt']['in_app'][$use_count]['product_id'].'!='.$order_info['bundle_id']);
|
|
|
$this->error('非法请求,请立刻停止');
|
|
|
}
|
|
|
|
|
@@ -402,7 +412,12 @@ class Payios extends Api
|
|
|
// p($data);die;
|
|
|
|
|
|
if ($data['status'] == '21002') {
|
|
|
- $this->error('21002');
|
|
|
+// $this->error('21002');
|
|
|
+ $result = array(
|
|
|
+ 'status' => false,
|
|
|
+ 'message' => 'status:21002'
|
|
|
+ );
|
|
|
+ return $result;
|
|
|
}
|
|
|
|
|
|
// 如果是沙盒数据 则验证沙盒模式 21008;正式数据 21007
|