|
@@ -0,0 +1,132 @@
|
|
|
+<?php
|
|
|
+namespace app\api\controller;
|
|
|
+
|
|
|
+use app\common\controller\Api;
|
|
|
+use think\Db;
|
|
|
+use addons\epay\library\Service;
|
|
|
+
|
|
|
+ * 订单支付回调
|
|
|
+ */
|
|
|
+class Notify extends Api
|
|
|
+{
|
|
|
+ protected $noNeedLogin = ['*'];
|
|
|
+ protected $noNeedRight = ['*'];
|
|
|
+
|
|
|
+
|
|
|
+ public function recharge_notify_base(){
|
|
|
+
|
|
|
+
|
|
|
+ $paytype = input('paytype','hitpay');
|
|
|
+ $notify_file = $this->notify_log_start($paytype);
|
|
|
+ $pay = Service::checkNotify($paytype);
|
|
|
+ if (!$pay) {
|
|
|
+ echo '签名错误';
|
|
|
+ exit;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ $data = $pay->verify();
|
|
|
+ $out_trade_no = $data['out_trade_no'];
|
|
|
+
|
|
|
+ $info = Db::name('pay_order')->where('out_trade_no',$out_trade_no)->find();
|
|
|
+
|
|
|
+ if(empty($info)){
|
|
|
+ echo $pay->success();
|
|
|
+ exit;
|
|
|
+ }
|
|
|
+
|
|
|
+ if($info['order_status'] != 0)
|
|
|
+ {
|
|
|
+ echo $pay->success();
|
|
|
+ exit;
|
|
|
+ }
|
|
|
+
|
|
|
+ $rs = $this->recharge_notify_do($out_trade_no);
|
|
|
+ if($rs === false){
|
|
|
+
|
|
|
+ echo $pay->success();
|
|
|
+ exit;
|
|
|
+ }else{
|
|
|
+
|
|
|
+ echo $pay->success();
|
|
|
+ exit;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ echo $pay->success();
|
|
|
+ exit;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ private function recharge_notify_do($out_trade_no){
|
|
|
+
|
|
|
+ Db::startTrans();
|
|
|
+ $orderInfo = Db::name('pay_order')->where(['out_trade_no' => $out_trade_no])->lock(true)->find();
|
|
|
+ if (empty($orderInfo)) {
|
|
|
+ Db::rollback();
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ if($orderInfo['order_status'] != 0){
|
|
|
+ Db::rollback();
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ $args = json_decode($orderInfo['args'],true);
|
|
|
+ $result = model('Wallet')->lockChangeAccountRemain($orderInfo['user_id'],'gold',$args['gold'],10, '金币充值','pay_order',$orderInfo['id']);
|
|
|
+ if($result['status']===false)
|
|
|
+ {
|
|
|
+ Db::rollback();
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ $ros = Db::name('pay_order')->where(['out_trade_no' => $out_trade_no])->update(['order_status'=>1,'notifytime'=>time()]);
|
|
|
+ if($ros === false) {
|
|
|
+ Db::rollback();
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ Db::commit();
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ private function notify_log_start($paytype = 'wechat'){
|
|
|
+
|
|
|
+ ignore_user_abort();
|
|
|
+ set_time_limit(30);
|
|
|
+
|
|
|
+ $log_base_dir = '../paylog/'.$paytype.'/';
|
|
|
+ if (!is_dir($log_base_dir))
|
|
|
+ {
|
|
|
+ mkdir($log_base_dir, 0770, true);
|
|
|
+ @chmod($log_base_dir, 0770);
|
|
|
+ }
|
|
|
+ $notify_file = $log_base_dir.'notify.txt';
|
|
|
+ if(!file_exists($notify_file)) {
|
|
|
+ @touch($notify_file);
|
|
|
+ @chmod($notify_file, 0770);
|
|
|
+ }
|
|
|
+ if(filesize($notify_file)>5242880)
|
|
|
+ {
|
|
|
+ rename($notify_file, $log_base_dir.'notify_'.date('Y_m_d_H_i_s').'.txt');
|
|
|
+ }
|
|
|
+ if(!file_exists($notify_file)) {
|
|
|
+ @touch($notify_file);
|
|
|
+ @chmod($notify_file, 0770);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ $xml = file_get_contents("php://input");
|
|
|
+ file_put_contents($notify_file, "\r\n\r\n".date('Y-m-d H:i:s')." [notify][入口接收php://input流原始数据] \n".$xml, FILE_APPEND);
|
|
|
+
|
|
|
+ ini_set('display_errors','On');
|
|
|
+
|
|
|
+ return $notify_file;
|
|
|
+
|
|
|
+ }
|
|
|
+}
|