Inheritance: extends WxPayNotify
Exemple #1
0
 /**
  * 微信异步调用
  */
 public static function notify($callback)
 {
     self::debug("begin notify");
     $notify = new PayNotifyCallBack();
     $notify->callback = $callback;
     $notify->Handle(false);
 }
Exemple #2
0
 public function callback()
 {
     $log = $this->config->get('wxpay_log');
     if ($log) {
         $this->log->write('WxPay :: One: ');
     }
     $this->load->library('wxpayexception');
     if ($log) {
         $this->log->write('WxPay :: Two: ');
     }
     $this->load->library('wxpayconfig');
     if ($log) {
         $this->log->write('WxPay :: Three: ');
     }
     $this->load->library('wxpaydata');
     if ($log) {
         $this->log->write('WxPay :: Four: ');
     }
     $this->load->library('wxpaynotify');
     if ($log) {
         $this->log->write('WxPay :: Five: ');
     }
     $this->load->library('wxpayapi');
     if ($log) {
         $this->log->write('WxPay :: Six: ');
     }
     $this->load->library('wxpaynotifycallback');
     if ($log) {
         $this->log->write('WxPay :: Seven: ');
     }
     $notify = new PayNotifyCallBack();
     if ($log) {
         $this->log->write('WxPay :: Eight: ');
     }
     $notify->Handle(false);
     $getxml = $GLOBALS['HTTP_RAW_POST_DATA'];
     libxml_disable_entity_loader(true);
     $result = json_decode(json_encode(simplexml_load_string($getxml, 'SimpleXMLElement', LIBXML_NOCDATA)), true);
     if ($notify->GetReturn_code() == "SUCCESS") {
         if ($result["return_code"] == "FAIL") {
             $this->log->write("WxPay ::【通信出错】:\n" . $getxml . "\n");
         } elseif ($result["result_code"] == "FAIL") {
             $this->log->write("WxPay ::【业务出错】:\n" . $getxml . "\n");
         } else {
             $order_id = $result['out_trade_no'];
             if ($log) {
                 $this->log->write('WxPay :: Order ID: ' . $order_id);
             }
             $this->load->model('checkout/order');
             $order_info = $this->model_checkout_order->getOrder($order_id);
             if ($order_info) {
                 if ($log) {
                     $this->log->write('WxPay :: 1: ');
                 }
                 $order_status_id = $this->config->get('wxpay_trade_success_status_id');
                 if (!$order_info['order_status_id']) {
                     $this->model_checkout_order->addOrderHistory($order_id, $order_status_id, '', true);
                     $this->log->write('WxPay :: 2: ');
                 } else {
                     $this->model_checkout_order->addOrderHistory($order_id, $order_status_id, '', true);
                     $this->log->write('WxPay :: 3: ');
                 }
                 //清除sesssion,避免客户返回不到成功页面而无法清除原有的购物车等信息
                 $this->cart->clear();
                 unset($this->session->data['shipping_method']);
                 unset($this->session->data['shipping_methods']);
                 unset($this->session->data['payment_method']);
                 unset($this->session->data['payment_methods']);
                 unset($this->session->data['guest']);
                 unset($this->session->data['comment']);
                 unset($this->session->data['order_id']);
                 unset($this->session->data['coupon']);
                 unset($this->session->data['reward']);
                 unset($this->session->data['voucher']);
                 unset($this->session->data['vouchers']);
                 unset($this->session->data['totals']);
                 if (isset($this->session->data['cs_shipfrom'])) {
                     unset($this->session->data['cs_shipfrom']);
                 }
                 if (isset($this->sesssion->data['personal_card'])) {
                     unset($this->sesssion->data['personal_card']);
                 }
             } else {
                 if ($log) {
                     $this->log->write('WxPay :: Seven: ');
                 }
             }
         }
     } else {
         $this->log->write('WxPay :: Nine: ' . $result);
     }
 }
 public function weixin_balance()
 {
     App::import('Vendor', 'Weixinpay', array('file' => 'WxPay.Api.php'));
     $notify = new PayNotifyCallBack();
     $res = $notify->Handle(false);
     $xml = $GLOBALS['HTTP_RAW_POST_DATA'];
     $result = WxPayResults::Init($xml);
     $this->loadModel('PaymentApiLog');
     $out_trade_no = isset($result["out_trade_no"]) ? $result["out_trade_no"] : '';
     $out_trade_no_arr = split("_", $out_trade_no);
     $api_log_id = $out_trade_no_arr[0];
     $payment_api_log = $this->PaymentApiLog->find('first', array('conditions' => array('PaymentApiLog.id' => $api_log_id, 'is_paid' => '0')));
     if (!empty($payment_api_log)) {
         //充值支付
         $user_id = $payment_api_log['PaymentApiLog']['type_id'];
         $add_money = $payment_api_log['PaymentApiLog']['amount'];
         $user_Info = $this->User->find('first', array('conditions' => array('User.id' => $user_id)));
         if (!empty($user_Info)) {
             $user_money = $user_Info['User']['balance'];
             $user_money = $user_money + $add_money;
             $user_data['id'] = $user_id;
             $user_data['balance'] = $user_money;
             $this->User->save($user_data);
             $user_Info['User']['balance'] = $user_money;
             $_SESSION['User'] = $user_Info;
             $payment_api_log['PaymentApiLog']['is_paid'] = '1';
             $this->PaymentApiLog->save($payment_api_log);
             //添加资金日志
             $BalanceLog['UserBalanceLog']['user_id'] = $user_id;
             $BalanceLog['UserBalanceLog']['amount'] = $payment_api_log['PaymentApiLog']['amount'];
             $BalanceLog['UserBalanceLog']['admin_user'] = $user_Info['User']['balance'];
             $BalanceLog['UserBalanceLog']['admin_note'] = '';
             $BalanceLog['UserBalanceLog']['system_note'] = '用户余额:' . $user_data['balance'] . '元';
             $BalanceLog['UserBalanceLog']['log_type'] = 'B';
             $BalanceLog['UserBalanceLog']['type_id'] = $payment_api_log['PaymentApiLog']['id'];
             $BalanceLog['UserBalanceLog']['created'] = date('Y-m-d H:i:s', time());
             $this->UserBalanceLog->save($BalanceLog);
         }
     }
 }
Exemple #4
0
    public function Queryorder($transaction_id)
    {
        $input = new WxPayOrderQuery();
        $input->SetTransaction_id($transaction_id);
        $result = WxPayApi::orderQuery($input);
        Log::DEBUG("query:" . json_encode($result));
        if (array_key_exists("return_code", $result) && array_key_exists("result_code", $result) && $result["return_code"] == "SUCCESS" && $result["result_code"] == "SUCCESS") {
            return true;
        }
        return false;
    }
    //重写回调处理函数
    public function NotifyProcess($data, &$msg)
    {
        Log::DEBUG("call back:" . json_encode($data));
        $notfiyOutput = array();
        if (!array_key_exists("transaction_id", $data)) {
            $msg = "输入参数不正确";
            return false;
        }
        //查询订单,判断订单真实性
        if (!$this->Queryorder($data["transaction_id"])) {
            $msg = "订单查询失败";
            return false;
        }
        return true;
    }
}
Log::DEBUG("begin notify");
$notify = new PayNotifyCallBack();
$notify->Handle(false);
Exemple #5
0
    public function NotifyProcess($data, &$msg)
    {
        Log::DEBUG("call back :" . json_encode($data));
        $notfiyOutput = array();
        if (!array_key_exists("transaction_id", $data)) {
            $msg = "输入参数不正确";
            return false;
        }
        //查询订单,判断订单真实性
        if (!$this->Queryorder($data["transaction_id"])) {
            $msg = "订单查询失败";
            return false;
        }
        return true;
    }
}
Log::DEBUG("begin notify");
$notify = new PayNotifyCallBack();
$notify->Handle(false);
$result = $notify->GetReturn_code();
Log::DEBUG("query-test:" . "============test================" . $result . '|' . $this->order_id);
if ($result == "SUCCESS") {
    header("location:http://www.yujiaqu.com/paySuccess.php");
    exit;
} else {
    header("location:http://www.yujiaqu.com/paySuccess.php");
    exit;
}
?>

Exemple #6
0
 /**
  * 支付通知
  */
 public function notify_action()
 {
     $notify = new PayNotifyCallBack($this);
     $notify->Handle(false);
 }
Exemple #7
0
 public function callback()
 {
     $log = $this->config->get('wxpay_log');
     if ($log) {
         $this->log->write('WxPay :: One: ');
     }
     //$this->load->library('wxpayexception');
     require_once DIR_SYSTEM . 'library/wxpay/wxpayexception.php';
     if ($log) {
         $this->log->write('WxPay :: Two: ');
     }
     define('WXPAY_APPID', trim($this->config->get('wxpay_appid')));
     define('WXPAY_MCHID', trim($this->config->get('wxpay_mchid')));
     define('WXPAY_KEY', trim($this->config->get('wxpay_key')));
     define('WXPAY_APPSECRET', trim($this->config->get('wxpay_appsecret')));
     define('WXPAY_SSLCERT_PATH', DIR_SYSTEM . 'helper/wxpay_key/apiclient_cert.pem');
     define('WXPAY_SSLKEY_PATH', DIR_SYSTEM . 'helper/wxpay_key/apiclient_key.pem');
     define('WXPAY_CURL_PROXY_HOST', "0.0.0.0");
     define('WXPAY_CURL_PROXY_PORT', 0);
     define('REPORT_LEVENL', 1);
     //$this->load->library('wxpayconfig');
     require_once DIR_SYSTEM . 'library/wxpay/wxpayconfig.php';
     if ($log) {
         $this->log->write('WxPay :: Three: ');
     }
     //$this->load->library('wxpaydata');
     require_once DIR_SYSTEM . 'library/wxpay/wxpaydata.php';
     if ($log) {
         $this->log->write('WxPay :: Four: ');
     }
     //$this->load->library('wxpaynotify');
     require_once DIR_SYSTEM . 'library/wxpay/wxpaynotify.php';
     if ($log) {
         $this->log->write('WxPay :: Five: ');
     }
     //$this->load->library('wxpayapi');
     require_once DIR_SYSTEM . 'library/wxpay/wxpayapi.php';
     if ($log) {
         $this->log->write('WxPay :: Six: ');
     }
     //$this->load->library('wxpaynotifycallback');
     require_once DIR_SYSTEM . 'library/wxpay/wxpaynotifycallback.php';
     if ($log) {
         $this->log->write('WxPay :: Seven: ');
     }
     $notify = new PayNotifyCallBack();
     if ($log) {
         $this->log->write('WxPay :: Eight: ');
     }
     $notify->Handle(false);
     $getxml = $GLOBALS['HTTP_RAW_POST_DATA'];
     //$getxml = file_get_contents('php://input');
     libxml_disable_entity_loader(true);
     $result = json_decode(json_encode(simplexml_load_string($getxml, 'SimpleXMLElement', LIBXML_NOCDATA)), true);
     if ($notify->GetReturn_code() == "SUCCESS") {
         if ($result["return_code"] == "FAIL") {
             $this->log->write("WxPay ::【通信出错】:\n" . $getxml . "\n");
         } elseif ($result["result_code"] == "FAIL") {
             $this->log->write("WxPay ::【业务出错】:\n" . $getxml . "\n");
         } else {
             $order_id = $result['out_trade_no'];
             if ($log) {
                 $this->log->write('WxPay :: Order ID: ' . $order_id);
             }
             $this->load->model('checkout/order');
             $order_info = $this->model_checkout_order->getOrder($order_id);
             if ($order_info) {
                 if ($log) {
                     $this->log->write('WxPay :: 1: ');
                 }
                 $order_status_id = $this->config->get('wxpay_trade_success_status_id');
                 if (!$order_info['order_status_id']) {
                     $this->model_checkout_order->addOrderHistory($order_id, $order_status_id, '', true);
                     if ($log) {
                         $this->log->write('WxPay :: 2: ');
                     }
                 } else {
                     $this->model_checkout_order->addOrderHistory($order_id, $order_status_id, '', true);
                     if ($log) {
                         $this->log->write('WxPay :: 3: ');
                     }
                 }
                 //清除sesssion,避免客户返回不到成功页面而无法清除原有的购物车等信息
                 $this->cart->clear();
                 unset($this->session->data['shipping_method']);
                 unset($this->session->data['shipping_methods']);
                 unset($this->session->data['payment_method']);
                 unset($this->session->data['payment_methods']);
                 unset($this->session->data['guest']);
                 unset($this->session->data['comment']);
                 unset($this->session->data['order_id']);
                 unset($this->session->data['coupon']);
                 unset($this->session->data['reward']);
                 unset($this->session->data['voucher']);
                 unset($this->session->data['vouchers']);
                 unset($this->session->data['totals']);
                 if (isset($this->session->data['cs_shipfrom'])) {
                     unset($this->session->data['cs_shipfrom']);
                 }
                 if (isset($this->sesssion->data['personal_card'])) {
                     unset($this->sesssion->data['personal_card']);
                 }
             } else {
                 if ($log) {
                     $this->log->write('WxPay :: Seven: ');
                 }
             }
         }
     } else {
         if ($log) {
             $this->log->write('WxPay :: Nine: ' . $result);
         }
     }
 }
Exemple #8
0
/**
 * 系统回调
 */
function notify()
{
    Log::DEBUG("begin notify");
    $notify = new PayNotifyCallBack();
    $notify->Handle(false);
}
Exemple #9
0
            foreach ($orders as $order) {
                $isOk &= $this->changeOrderStatusSub($order->id);
            }
        }
        return $isOk;
    }
    public function changeOrderStatusSub($id_order)
    {
        Log::DEBUG("change:1." . $id_order);
        if ($id_order) {
            Log::DEBUG("change:2." . $id_order);
            $lastHistory = OrderHistory::getLastOrderState($id_order);
            if ($lastHistory->id == Configuration::get('PS_OS_PAYMENT')) {
                Log::DEBUG("change:2.1." . $id_order);
                return true;
            }
            $history = new OrderHistory();
            $history->id_order = (int) $id_order;
            $history->changeIdOrderState(Configuration::get('PS_OS_PAYMENT'), (int) $id_order);
            Log::DEBUG("change:3." . $id_order);
            if ($history->addWithemail()) {
                Log::DEBUG("change:4." . $id_order);
                return true;
            }
        }
        return false;
    }
}
Log::DEBUG("call back:begin notify");
$notify = new PayNotifyCallBack();
$notify->handle(false);
 public function actionWxpayOrderNotify()
 {
     Yii::$app->response->format = Response::FORMAT_RAW;
     require_once Yii::getAlias('@vendor') . "/payment/wxpay/class/PayNotifyCallBack.php";
     $notify = new \PayNotifyCallBack();
     $notify->Handle(false);
 }
Exemple #11
0
            $msg = "订单查询失败";
            return false;
        }
        // 纪录错误信息
        if (!empty($msg) && $msg !== 'OK') {
            Log::ERROR(sprintf('call NotifyProcess error::%s|file:%s|line:%s', $msg, __FILE__, __LINE__));
        }
        return true;
    }
}
try {
    // 初始化日志
    $logHandler = new CLogFileHandler(Config::PAY_LOG_PATH . date('Y-m-d') . '.log');
    $log = Log::Init($logHandler, Config::PAY_LOG_LEVER);
    $log::DEBUG("=============begin notify==============");
    $notify = new PayNotifyCallBack();
    $notify->Handle(true);
    // 先判断协议状态return_code,再判断业务状态result_code
    if ($notify->query_data['return_code'] == 'SUCCESS') {
        //$data['id'] = $orderId = substr($notify->query_data['out_trade_no'], 14);
        $data['id'] = $orderId = $notify->query_data['out_trade_no'];
        $data['pay_type'] = Config::ORDER_PAY_TYPE;
        $data['pay_status'] = Config::ORDER_PAY_FAILED_CODE;
        if ($notify->query_data['result_code'] == 'SUCCESS') {
            $data['pay_status'] = Config::ORDER_PAY_SUCCESS_CODE;
        }
        //$data['pay_discount'] = Config::ORDER_PAY_DISCOUNT;
        // 微信会轮训回调通知接口,更新订单支付状态前需要先查询订单是否已经更改
        $order_info = Order::get_order_by_id($data['id']);
        if ((int) $order_info['pay_status'] !== Config::ORDER_PAY_WAITTINT_CODE) {
            return;
Exemple #12
0
 /**
  * 支付结果回调通知
  * 
  * @param callable $callback
  */
 public static function nofify($callback)
 {
     Log::DEBUG("begin notify");
     $notify = new PayNotifyCallBack($callback);
     $notify->Handle(false);
 }
Exemple #13
0
 public function on_wxpay_notify()
 {
     $notify = new PayNotifyCallBack($this);
     $notify->Handle(false);
 }
 /**
  * 接收微信支付返回用户支付的信息
  * @author 罗江涛
  * @DateTime 2016-01-13T11:33:43+0800
  */
 public function getWeixinPayPost()
 {
     require "./Application/Index/Service/weixinPayApi/notify.php";
     $notify = new \PayNotifyCallBack();
     $notify->Handle(false);
     $weixinData2 = $notify->weixinData;
     /*
             
             array (
      'appid' => 'wx496cb85dab14e08d',
      'attach' => 'SetAttach',
      'bank_type' => 'CFT',
      'cash_fee' => '1',
      'fee_type' => 'CNY',
      'is_subscribe' => 'N',
      'mch_id' => '1261968001',
      'nonce_str' => 'pwut1tcpex06vgqceoql410nmq9xjo6p',
      'openid' => 'oSI0dt-cEmFZF5fSTvSBG4LKNE_A',
      'out_trade_no' => 'SetOut_trade_no20160506162337',
      'result_code' => 'SUCCESS',
      'return_code' => 'SUCCESS',
      'sign' => 'B3E9BA1AA56ED63109D930B79B84D959',
      'time_end' => '20160506162420',
      'total_fee' => '1',
      'trade_type' => 'NATIVE',
      'transaction_id' => '4009052001201605065568684581',
             )
     */
     //验证是否交易成功
     if ($weixinData2['result_code'] != 'SUCCESS') {
         $result = $this->getStandResult(0, '交易失败', '');
         $this->json($result);
         return;
     }
     $attach = explode("|", $weixinData2['attach']);
     $userId = $attach[0];
     $goodsId = $attach[1];
     $payment = array('userId' => $userId, 'goodsId' => $goodsId, 'time' => date("Y-m-d h:i:s"), 'content' => '无内容', 'price' => $weixinData2['total_fee'], 'paymentMethod' => 'weixin', 'orderNumber' => $weixinData2['transaction_id'], 'email' => '', 'weixin' => '');
     $file = './1.txt';
     $str = var_export($weixinData2, true);
     file_put_contents($file, $str);
     // 添加数据
     $result = M('payment')->add($payment);
     // 添加失败
     if (!$result) {
         $result = $this->getStandResult(0, '添加数据失败', '添加数据失败');
         $this->json($result);
         return;
     }
     // 组装并输出标准接口数据
     $result = $this->getStandResult(1, '添加数据成功', '', $payment);
     $this->json($result);
 }
Exemple #15
0
 /**
  * 微支付通知
  * @return array|bool
  */
 public static function wxpayNotifyVerify()
 {
     require_once __DIR__ . "/../wxpay/PayNotifyCallBack.php";
     $notify = new \PayNotifyCallBack();
     $notify->Handle(false);
     if ($data = $notify->getPostData()) {
         $out_trade_no = substr($data['out_trade_no'], 10);
         return ['appid' => $data['appid'], 'mch_id' => $data['mch_id'], 'device_info' => $data['device_info'], 'device_info' => $data['device_info'], 'nonce_str' => $data['nonce_str'], 'sign' => $data['sign'], 'result_code' => $data['result_code'], 'err_code' => $data['err_code'], 'err_code_des' => $data['err_code_des'], 'openid' => $data['openid'], 'is_subscribe' => $data['is_subscribe'], 'trade_type' => $data['trade_type'], 'bank_type' => $data['bank_type'], 'total_fee' => $data['total_fee'], 'settlement_total_fee' => $data['settlement_total_fee'], 'fee_type' => $data['fee_type'], 'cash_fee' => $data['cash_fee'], 'cash_fee_type' => $data['cash_fee_type'], 'coupon_fee' => $data['coupon_fee'], 'coupon_count' => $data['coupon_count'], 'coupon_type_$n' => $data['coupon_type_$n'], 'coupon_id_$n' => $data['coupon_id_$n'], 'coupon_fee_$n' => $data['coupon_fee_$n'], 'transaction_id' => $data['transaction_id'], 'out_trade_no' => $out_trade_no, 'attach' => $data['attach'], 'time_end' => $data['time_end']];
     } else {
         return false;
     }
 }