/**
  * 微信支付回调处理接口(j接口要保持可以访问,微信才会发数据包过来)
  */
 public function order()
 {
     //格式化post_data
     $orderxml = $_POST;
     if (!$orderxml) {
         $postStr = file_get_contents("php://input");
         if (!empty($postStr)) {
             $orderxml = (array) simplexml_load_string($postStr, 'SimpleXMLElement', LIBXML_NOCDATA);
         } else {
             return false;
         }
     }
     //记录日志
     $info = json_encode($orderxml);
     $this->payLog($info);
     //验证是否重复
     $isRepeat = $this->table('record')->where(['wxPay_sn' => $orderxml['out_trade_no']])->get(['id'], true);
     if ($isRepeat) {
         $this->returnFail("重复流水号!", $info);
     }
     /* 调用微信支付验证签名类 */
     $this->vendor('WxPay.JsApi_pub');
     $notify = new \Notify_pub();
     $this->notify = $notify;
     //存储微信的回调
     $xml = $GLOBALS['HTTP_RAW_POST_DATA'];
     $notify->saveData($xml);
     //验证签名
     if ($notify->checkSign() == FALSE) {
         $this->returnFail("签名失败", $info);
     }
     // 保存数据到数据库
     $this->V(['id' => ['egNum', null, false]]);
     $attach = json_decode($orderxml['attach'], true);
     $orderSn = $attach['goods_sn'];
     $isGoods = $this->table('goods')->where(array('goods_sn' => $orderSn, 'is_on' => 1))->get(['id', 'thematic_id'], true);
     $data['goods_id'] = $isGoods['id'];
     $data['thematic_id'] = $isGoods['thematic_id'];
     $isUser = $this->table('user')->where(array('openid' => $orderxml['openid']))->get(['id'], true);
     $data['user_id'] = $isUser['id'];
     $data['wxPay_sn'] = $orderxml['out_trade_no'];
     $data['add_time'] = time();
     $count = $this->table('code')->where(['is_on' => 1, 'is_use' => 0, 'goods_id' => $data['goods_id']])->get(['code'], false);
     //$data['num'] = count($count);
     $data['num'] = $orderxml['total_fee'];
     $data['ms_time'] = sprintf("%03d", floor(microtime() * 1000));
     $record = $this->table('record')->save($data);
     $record_id = $this->table('record')->where(array('wxPay_sn' => $data['wxPay_sn'], 'is_on' => 1))->get(['id'], true);
     //分配认购码给用户,生成购物流水单
     $roll = $this->generateCodeToUser($data['user_id'], $data['goods_id'], $data['thematic_id'], $data['num'], $record_id['id']);
     //通知微信已支付成功
     $callback = $this->returnSuccess('支付成功!', $info);
     if (!$callback) {
         $this->R('', 40001);
     }
     $this->R(['callback' => $data]);
     exit;
 }
Esempio n. 2
0
 public function asyncCallback($callbackData, &$paymentId, &$money, &$message, &$orderNo)
 {
     //使用通用通知接口
     $notify = new Notify_pub();
     $xml = $GLOBALS['HTTP_RAW_POST_DATA'];
     $notify->saveData($xml);
     //验证签名,并回应微信。
     //对后台通知交互时,如果微信收到商户的应答不是成功或超时,微信认为通知失败,
     //微信会通过一定的策略(如30分钟共8次)定期重新发起通知,
     //尽可能提高通知的成功率,但微信不保证通知最终能成功。
     $payment = new Payment($paymentId);
     $paymentInfo = $payment->getPayment();
     $paymentInfo['partner_key'];
     if ($notify->checkSign($paymentInfo['partner_key']) == FALSE) {
         $notify->setReturnParameter("return_code", "FAIL");
         //返回状态码
         $notify->setReturnParameter("return_msg", "签名失败");
         //返回信息
         echo $notify->returnXml();
     } else {
         $notify->setReturnParameter("return_code", "SUCCESS");
         //设置返回码
         $this->returnXml = $notify->returnXml();
     }
     if ($notify->checkSign($paymentInfo['partner_key']) == TRUE) {
         if ($notify->data["return_code"] == "SUCCESS" && $notify->data["return_code"] == "SUCCESS") {
             $orderNo = $notify->data['out_trade_no'];
             $money = $notify->data['total_fee'] / 100;
             return true;
         }
     }
     return false;
 }
Esempio n. 3
0
 /**
  * 微信支付Notify
  */
 function wxpay_notify()
 {
     //使用通用通知接口
     $notify = new Notify_pub();
     //存储微信的回调
     $xml = $GLOBALS['HTTP_RAW_POST_DATA'];
     $notify->saveData($xml);
     //验证签名,并回应微信。
     //对后台通知交互时,如果微信收到商户的应答不是成功或超时,微信认为通知失败,
     //微信会通过一定的策略(如30分钟共8次)定期重新发起通知,
     //尽可能提高通知的成功率,但微信不保证通知最终能成功。
     if ($notify->checkSign() == FALSE) {
         $notify->setReturnParameter("return_code", "FAIL");
         //返回状态码
         $notify->setReturnParameter("return_msg", "签名失败");
         //返回信息
     } else {
         $notify->setReturnParameter("return_code", "SUCCESS");
         //设置返回码
     }
     $returnXml = $notify->returnXml();
     echo $returnXml;
     //==商户根据实际情况设置相应的处理流程,此处仅作举例=======
     //以log文件形式记录回调信息
     $log_type = "wxpay_notify";
     //log文件路径
     $this->log_result($log_type, "【接收到的notify通知】:\n" . $xml . "\n");
     if ($notify->checkSign() == TRUE) {
         if ($notify->data["return_code"] == "FAIL") {
             //此处应该更新一下订单状态,商户自行增删操作
             $this->log_result($log_type, "【通信出错】:\n" . $xml . "\n");
         } elseif ($notify->data["result_code"] == "FAIL") {
             //此处应该更新一下订单状态,商户自行增删操作
             $this->log_result($log_type, "【业务出错】:\n" . $xml . "\n");
         } else {
             //此处应该更新一下订单状态,商户自行增删操作
             $this->log_result($log_type, "【支付成功】:\n" . $xml . "\n");
             $out_trade_no = $notify->data['out_trade_no'];
             $trade_no = $notify->data['transaction_id'];
             $order = $this->order_model->get_order_info($out_trade_no);
             //echo "trade_no: $trade_no<br/> out_trade_no: $out_trade_no";print_r($order);
             if ($order['TradeStatus'] != 'TRADE_FINISHED' && $order['TradeStatus'] != 'TRADE_SUCCESS') {
                 $data = array('TradeStatus' => 'TRADE_SUCCESS', 'TradeNo' => $trade_no, 'PayTime' => time(), 'PayType' => 'wxpay');
                 $this->order_model->update_order_info($out_trade_no, $data);
             }
         }
     }
 }
Esempio n. 4
0
 function respond()
 {
     $payment = get_payment('wx_new_qrcode');
     $notify = new Notify_pub();
     $xml = $GLOBALS['HTTP_RAW_POST_DATA'];
     if ($payment['logs']) {
         $this->log(ROOT_PATH . '/data/wx_new_log.txt', "传递过来的XML\r\n" . var_export($xml, true));
     }
     $notify->saveData($xml);
     if ($notify->checkSign() == TRUE) {
         if ($notify->data["return_code"] == "FAIL") {
             //此处应该更新一下订单状态,商户自行增删操作
             if ($payment['logs']) {
                 $this->log(ROOT_PATH . '/data/wx_new_log.txt', "return_code失败\r\n");
             }
         } elseif ($notify->data["result_code"] == "FAIL") {
             //此处应该更新一下订单状态,商户自行增删操作
             if ($payment['logs']) {
                 $this->log(ROOT_PATH . '/data/wx_new_log.txt', "result_code失败\r\n");
             }
         } else {
             //此处应该更新一下订单状态,商户自行增删操作
             if ($payment['logs']) {
                 $this->log(ROOT_PATH . '/data/wx_new_log.txt', "支付成功\r\n");
             }
             $total_fee = $notify->data["total_fee"];
             $log_id = $notify->data["attach"];
             $sql = 'SELECT order_amount FROM ' . $GLOBALS['ecs']->table('pay_log') . " WHERE log_id = '{$log_id}'";
             $amount = $GLOBALS['db']->getOne($sql);
             if ($payment['logs']) {
                 $this->log(ROOT_PATH . '/data/wx_new_log.txt', '订单金额' . $amount . "\r\n");
             }
             /* 检查支付的金额是否相符 */
             if (intval($amount * 100) != $total_fee) {
                 if ($payment['logs']) {
                     $this->log(ROOT_PATH . '/data/wx_new_log.txt', '订单金额不符' . "\r\n");
                 }
                 echo 'fail';
                 return false;
             }
             order_paid($log_id, 2);
             return true;
         }
     } else {
         $this->log(ROOT_PATH . '/data/wx_new_log.txt', "签名失败\r\n");
     }
     return false;
 }
Esempio n. 5
0
 public function notify($req)
 {
     //使用通用通知接口
     $notify = new Notify_pub($this->wxConfig);
     //存储微信的回调
     $xml = urldecode(file_get_contents('php://input'));
     $notify->saveData($xml);
     //验证签名,并回应微信。
     //对后台通知交互时,如果微信收到商户的应答不是成功或超时,微信认为通知失败,
     //微信会通过一定的策略(如30分钟共8次)定期重新发起通知,
     //尽可能提高通知的成功率,但微信不保证通知最终能成功。
     if ($notify->checkSign() == FALSE) {
         $notify->setReturnParameter("return_code", "FAIL");
         //返回状态码
         $notify->setReturnParameter("return_msg", "签名失败");
         //返回信息
     } else {
         //$returnXml = $notify->returnXml();
         //echo $returnXml;
         if ($notify->data["return_code"] == "FAIL") {
             $notify->setReturnParameter("return_code", "FAIL");
             //此处应该更新一下订单状态,商户自行增删操作
             //$log_->log_result($log_name,"【通信出错】:\n".$xml."\n");
         } elseif ($notify->data["result_code"] == "FAIL") {
             $notify->setReturnParameter("return_code", "FAIL");
             //此处应该更新一下订单状态,商户自行增删操作
             //$log_->log_result($log_name,"【业务出错】:\n".$xml."\n");
         } else {
             //处理订单状态
             $uid = (new \Mall\Mdu\OrderModule())->setOrderStatus($notify->data['out_trade_no'], $_SERVER['REQUEST_TIME']);
             if ($uid != 0) {
                 (new \Mall\Mdu\OrderLogsModule())->addOrderLogBySn($notify->data['out_trade_no'], $this->di['sysconfig']['orderActType']['successPayment'], $uid, '用户', '支付成功');
                 $notify->setReturnParameter("return_code", "SUCCESS");
                 //设置返回码
             } else {
                 $notify->setReturnParameter("return_code", "FAIL");
             }
             //此处应该更新一下订单状态,商户自行增删操作
             //$log_->log_result($log_name,"【支付成功】:\n".$xml."\n");
         }
         $returnXml = $notify->returnXml();
         echo $returnXml;
     }
 }
Esempio n. 6
0
 public function wxwebnotify()
 {
     include_once "/mnt/meilimei/weixinpay/WxPayPubHelper.php";
     //使用通用通知接口
     $notify = new Notify_pub();
     //存储微信的回调
     $xml = $GLOBALS['HTTP_RAW_POST_DATA'];
     $notify->saveData($xml);
     //验证签名,并回应微信。
     //对后台通知交互时,如果微信收到商户的应答不是成功或超时,微信认为通知失败,
     //微信会通过一定的策略(如30分钟共8次)定期重新发起通知,
     //尽可能提高通知的成功率,但微信不保证通知最终能成功。
     if ($notify->checkSign() == FALSE) {
         $notify->setReturnParameter("return_code", "FAIL");
         //返回状态码
         $notify->setReturnParameter("return_msg", "签名失败");
         //返回信息
     } else {
         $notify->setReturnParameter("return_code", "SUCCESS");
         //设置返回码
     }
     // 	    $returnXml = $notify->returnXml();
     // 	    echo $returnXml;
     //==商户根据实际情况设置相应的处理流程,此处仅作举例=======
     if ($notify->checkSign() == TRUE) {
         if ($notify->data["return_code"] == "FAIL") {
         } elseif ($notify->data["result_code"] == "FAIL") {
         } else {
             $this->tehuiDB->where('pay_id', $notify->data['attach']);
             $order = $this->tehuiDB->get('order')->row_array();
             if ($order['origin'] != $notify->data['total_fee'] * 0.01) {
                 echo 'error';
                 exit;
             }
             $this->tehuiDB->where('pay_id', $notify->data['attach']);
             $this->tehuiDB->update('order', array('state' => 'pay', 'money' => $notify->data['total_fee'] * 0.01, 'service' => 'wxpay', 'trade_no' => $notify->data['out_trade_no'], 'pay_time' => time()));
             $this->payCall($order);
             echo "success";
         }
     }
 }
Esempio n. 7
0
 public function notify()
 {
     vendor('Weixinpay.WxPayPubHelper');
     //使用通用通知接口
     $notify = new \Notify_pub();
     // 存储微信的回调
     $xml = $GLOBALS['HTTP_RAW_POST_DATA'];
     $notify->saveData($xml);
     // 验证签名,并回应微信。
     if ($notify->checkSign() == FALSE) {
         $notify->setReturnParameter("return_code", "FAIL");
         // 返回状态码
         $notify->setReturnParameter("return_msg", "签名失败");
         // 返回信息
     } else {
         $notify->setReturnParameter("return_code", "SUCCESS");
         // 设置返回码
     }
     $returnXml = $notify->returnXml();
     echo $returnXml;
     // ==商户根据实际情况设置相应的处理流程=======
     if ($notify->checkSign() == TRUE) {
         if ($notify->data["return_code"] == "FAIL") {
             // 此处应该更新一下订单状态,商户自行增删操作
         } elseif ($notify->data["result_code"] == "FAIL") {
             // 此处应该更新一下订单状态,商户自行增删操作
         } else {
             // 此处应该更新一下订单状态,商户自行增删操作
             $order = $notify->getData();
             // $out_trade_no = $order["out_trade_no"];
             $trade_no = $order["transaction_id"];
             $total_fee = $order["total_fee"];
             $pkey = $order["attach"];
             $pkeys = explode("@", $pkey);
             $userId = $pkeys[0];
             $out_trade_no = $pkeys[1];
             $pm = D('Mobile/Payments');
             // 商户订单号
             $obj = array();
             $obj["trade_no"] = $trade_no;
             $obj["out_trade_no"] = $out_trade_no;
             $obj["total_fee"] = $total_fee;
             $obj["userId"] = $userId;
             // 支付成功业务逻辑
             $pm->complatePay($obj);
         }
     }
 }
Esempio n. 8
0
 public function notify()
 {
     //使用通用通知接口
     $notify = new \Notify_pub();
     //存储微信的回调
     $xml = $GLOBALS['HTTP_RAW_POST_DATA'];
     $notify->saveData($xml);
     //验证签名,并回应微信。
     //对后台通知交互时,如果微信收到商户的应答不是成功或超时,微信认为通知失败,
     //微信会通过一定的策略(如30分钟共8次)定期重新发起通知,
     //尽可能提高通知的成功率,但微信不保证通知最终能成功。
     if ($notify->checkSign() == FALSE) {
         $notify->setReturnParameter("return_code", "FAIL");
         //返回状态码
         $notify->setReturnParameter("return_msg", "签名失败");
         //返回信息
     } else {
         $notify->setReturnParameter("return_code", "SUCCESS");
         //设置返回码
     }
     $returnXml = $notify->returnXml();
     echo $returnXml;
     //==商户根据实际情况设置相应的处理流程,此处仅作举例=======
     //以log文件形式记录回调信息
     $log_ = new \Log_();
     $time = date('Ymd', time());
     $log_name = './logs/pay/jsAPI/' . $time . "notify_url.log";
     $log_->log_result($log_name, "【接收到的notify通知】:\n" . $xml . "\n");
     if ($notify->checkSign() == TRUE) {
         if ($notify->data["return_code"] == "FAIL") {
             //此处应该更新一下订单状态,商户自行增删操作
             $log_->log_result($log_name, "【通信出错】:\n" . $xml . "\n");
             //推送信息给用户
         } elseif ($notify->data["result_code"] == "FAIL") {
             //此处应该更新一下订单状态,商户自行增删操作
             $log_->log_result($log_name, "【业务出错】:\n" . $xml . "\n");
         } else {
             $log_->log_result($log_name, "【业务成功】:\n\r\n");
             //以上是业务代码
             $jsAPInotify = D('JPN');
             $object = xmlToArray($xml);
             $res = $jsAPInotify->jsAPINotifyUpO($object);
             $xml = "\n                    <xml>\n                      <return_code><![CDATA[" . $res . "]]></return_code>\n                      <return_msg><![CDATA[ITS OVER]]></return_msg>\n                    </xml>\n                ";
             exit($xml);
         }
     }
 }
Esempio n. 9
0
 public function wx_notify_url()
 {
     include_once "/mnt/meilimei/eventwxpay/WxPayPubHelper.php";
     $this->load->library('sms');
     //使用通用通知接口
     $notify = new Notify_pub();
     //存储微信的回调
     $xml = $GLOBALS['HTTP_RAW_POST_DATA'];
     $notify->saveData($xml);
     //验证签名,并回应微信。
     //对后台通知交互时,如果微信收到商户的应答不是成功或超时,微信认为通知失败,
     //微信会通过一定的策略(如30分钟共8次)定期重新发起通知,
     //尽可能提高通知的成功率,但微信不保证通知最终能成功。
     if ($notify->checkSign() == FALSE) {
         $notify->setReturnParameter("return_code", "FAIL");
         //返回状态码
         $notify->setReturnParameter("return_msg", "签名失败");
         //返回信息
     } else {
         $notify->setReturnParameter("return_code", "SUCCESS");
         //设置返回码
     }
     // 	    $returnXml = $notify->returnXml();
     // 	    echo $returnXml;
     if ($notify->checkSign() == TRUE) {
         $out_trade_no = $notify->data['attach'];
         $yzm = $this->makecode();
         $content = $yzm;
         $this->eventDB->where('order_no', $out_trade_no);
         $status = $this->eventDB->update('tehui_event_collection', array('capture' => $content, 'pay_state' => '2', 'trade_no' => $notify->data['out_trade_no']));
         $sql = "select * from tehui_event_collection where order_no = '" . $out_trade_no . "'";
         $rs = $this->eventDB->query($sql)->row_array();
         $this->sms->sendSMS(array($rs['mobile']), "【美丽神器】感谢您成功支付美丽神器活动定金,验证码:{$content}。请务必保留好验证码,我们的客服将在2个工作日内与您联系确认到院时间,如有任何问题,请拨打免费客服热线:400-6677-245");
         echo "success";
         if ($notify->data["return_code"] == "FAIL") {
         } elseif ($notify->data["result_code"] == "FAIL") {
         } else {
             //                 $out_trade_no = $notify->data['attach'];
             //                 $yzm =$this->makecode();
             //                 $content = $yzm;
             //                 $this->eventDB->where('order_no',$out_trade_no);
             //                 $status =$this->eventDB->update('tehui_event_collection',array('capture'=>$content,'pay_state'=>'2','trade_no' => $notify->data['out_trade_no']));
             //                 $sql = "select * from tehui_event_collection where order_no = '".$out_trade_no."'";
             //                 $rs = $this->eventDB->query($sql)->row_array();
             //                 $this->sms->sendSMS(array($rs['mobile']), "【美丽神器】感谢您成功支付美丽神器活动定金,验证码:{$content}。请务必保留好验证码,我们的客服将在2个工作日内与您联系确认到院时间,如有任何问题,请拨打免费客服热线:400-6677-245");
             //                 echo "success";
         }
     }
 }
Esempio n. 10
0
 public function houtai()
 {
     $pay_type = $this->db->GetOne("SELECT * from `@#_pay` where `pay_class` = 'weixin' and `pay_start` = '1'");
     $pay_type_key = unserialize($pay_type['pay_key']);
     $key = $pay_type_key['key']['val'];
     //支付KEY
     $id = $pay_type_key['id']['val'];
     //支付商号ID
     //使用通用通知接口
     $notify = new Notify_pub();
     //存储微信的回调
     $xml = $GLOBALS['HTTP_RAW_POST_DATA'];
     $notify->saveData($xml);
     //验证签名,并回应微信。
     //对后台通知交互时,如果微信收到商户的应答不是成功或超时,微信认为通知失败,
     //微信会通过一定的策略(如30分钟共8次)定期重新发起通知,
     //尽可能提高通知的成功率,但微信不保证通知最终能成功。
     if ($notify->checkSign() == FALSE) {
         $notify->setReturnParameter("return_code", "FAIL");
         //返回状态码
         $notify->setReturnParameter("return_msg", "签名失败");
         //返回信息
     } else {
         $notify->setReturnParameter("return_code", "SUCCESS");
         //设置返回码
     }
     $returnXml = $notify->returnXml();
     echo $returnXml;
     if ($notify->checkSign() == TRUE) {
         if ($notify->data["return_code"] == "FAIL") {
             exit;
         } elseif ($notify->data["result_code"] == "FAIL") {
             exit;
         } else {
             $this->out_trade_no = $notify->data["out_trade_no"];
         }
         $ret = $this->weixin_chuli();
         $this->qiantai();
     } else {
         exit;
     }
 }
Esempio n. 11
0
 public function notice()
 {
     $array_data = json_decode(json_encode(simplexml_load_string($GLOBALS['HTTP_RAW_POST_DATA'], 'SimpleXMLElement', LIBXML_NOCDATA)), true);
     if ($array_data) {
         $nowOrder = D('Order')->field('`store_id`,`useStorePay`,`storeOpenid`')->where(array('trade_no' => $array_data['out_trade_no']))->find();
         if ($nowOrder['useStorePay']) {
             $weixin_bind_info = D('Weixin_bind')->where(array('store_id' => $nowOrder['store_id']))->find();
             if (empty($weixin_bind_info) || empty($weixin_bind_info['wxpay_mchid']) || empty($weixin_bind_info['wxpay_key'])) {
                 return array('err_code' => 1, 'err_msg' => '商家未配置正确微信支付');
             }
             $this->pay_config = array('pay_weixin_appid' => $weixin_bind_info['authorizer_appid'], 'pay_weixin_mchid' => $weixin_bind_info['wxpay_mchid'], 'pay_weixin_key' => $weixin_bind_info['wxpay_key']);
         }
     }
     if (empty($this->pay_config['pay_weixin_appid']) || empty($this->pay_config['pay_weixin_mchid']) || empty($this->pay_config['pay_weixin_key'])) {
         return array('err_code' => 1, 'err_msg' => '微信支付缺少配置信息!请联系管理员处理或选择其他支付方式。');
     }
     import('source.class.pay.Weixinnewpay.WxPayPubHelper');
     $notify = new Notify_pub($this->pay_config['pay_weixin_appid'], $this->pay_config['pay_weixin_mchid'], $this->pay_config['pay_weixin_key']);
     $xml = $GLOBALS['HTTP_RAW_POST_DATA'];
     $notify->saveData($xml);
     if ($notify->checkSign() == false) {
         $notify->setReturnParameter('return_code', 'FAIL');
         $notify->setReturnParameter('return_msg', '签名失败');
         return array('err_code' => 1, 'err_msg' => $notify->returnXml());
     } else {
         $notify->setReturnParameter('return_code', 'SUCCESS');
         if ($notify->data['return_code'] == 'SUCCESS' && $notify->data['result_code'] == 'SUCCESS') {
             $order_param['trade_no'] = $notify->data['out_trade_no'];
             $order_param['pay_type'] = 'weixin';
             $order_param['third_id'] = $notify->data['transaction_id'];
             $order_param['pay_money'] = $notify->data['total_fee'] / 100;
             $order_param['third_data'] = $notify->data;
             $order_param['echo_content'] = $notify->returnXml();
             return array('err_code' => 0, 'order_param' => $order_param);
         } else {
             return array('err_code' => 1, 'err_msg' => '支付时发生错误!<br/>错误提示:' . $e->GetMessage() . '<br/>错误代码:' . $e->Getcode());
         }
     }
 }
Esempio n. 12
0
 public function actionNotify()
 {
     file_put_contents('/tmp/test.log', "\n\n return:" . 'testda1hongyes', FILE_APPEND);
     echo 'op';
     exit;
     //使用通用通知接口
     $notify = new \Notify_pub();
     //存储微信的回调
     $xml = $GLOBALS['HTTP_RAW_POST_DATA'];
     $notify->saveData($xml);
     file_put_contents('/tmp/test.log', "\n\n return:" . 'test2' . $xml, FILE_APPEND);
     //验证签名,并回应微信。
     //对后台通知交互时,如果微信收到商户的应答不是成功或超时,微信认为通知失败,
     //微信会通过一定的策略(如30分钟共8次)定期重新发起通知,
     //尽可能提高通知的成功率,但微信不保证通知最终能成功。
     if ($notify->checkSign() == FALSE) {
         file_put_contents('/tmp/test.log', "\n\n return:" . 'test3', FILE_APPEND);
         $notify->setReturnParameter("return_code", "FAIL");
         //返回状态码
         $notify->setReturnParameter("return_msg", "签名失败");
         //返回信息
     } else {
         file_put_contents('/tmp/test.log', "\n\n return:" . 'test4', FILE_APPEND);
         $notify->setReturnParameter("return_code", "SUCCESS");
         //设置返回码
     }
     $returnXml = $notify->returnXml();
     file_put_contents('/tmp/test.log', "\n\n return:" . 'test5' . $returnXml, FILE_APPEND);
     //==商户根据实际情况设置相应的处理流程,此处仅作举例=======
     if ($notify->checkSign() == TRUE) {
         if ($notify->data["return_code"] == 'SUCCESS' && $notify->data["result_code"] == 'SUCCESS') {
             $orderno = $notify->data["out_trade_no"];
             /* 通过id获取订单信息  更改订单的支付状态*/
             $support = Order::findOne(['orderno' => $orderno]);
             if (!$support['ispay']) {
                 $support->ispay = '1';
                 return $support->save();
                 echo $return ? 'success' : '';
             }
             // file_put_contents('/tmp/test.log',"\n\n return:".$return,FILE_APPEND);
         }
     }
 }
Esempio n. 13
0
 function NotifyInterface()
 {
     $code = array();
     $notify = new Notify_pub();
     $xml = $GLOBALS['HTTP_RAW_POST_DATA'];
     $notify->saveData($xml);
     if ($notify->checkSign() == FALSE) {
         $notify->setReturnParameter("return_code", "FAIL");
         //返回状态码
         $notify->setReturnParameter("return_msg", "签名失败");
         //返回信息
     } else {
         $notify->setReturnParameter("return_code", "SUCCESS");
         //设置返回码
     }
     $returnXml = $notify->returnXml();
     echo $returnXml;
     if ($notify->checkSign() == TRUE) {
         if ($notify->data["return_code"] == "FAIL") {
             $code = array('state' => -1, 'xml' => $xml);
         } elseif ($notify->data["result_code"] == "FAIL") {
             $code = array('state' => -2, 'xml' => $xml);
         } else {
             $code = array('state' => 1, 'xml' => $xml);
         }
     }
     return $code;
 }
Esempio n. 14
0
/**
 * [WeiZan System] Copyright (c) 2014 012wz.com
 * WeiZan is  a free software, it under the license terms, visited http://www.012wz.com/ for more details.
 */
error_reporting(1);
define('IN_MOBILE', true);
define("MON_ORDER", "mon_orderform");
require '../../framework/bootstrap.inc.php';
require_once "WxPayPubHelper/WxPayPubHelper.php";
require_once "monUtil.class.php";
require_once "dbutil.class.php";
$input = file_get_contents('php://input');
WeUtility::logging('info', "通用订单异步通知数据" . $input);
//WeUtility::logging('info',"商户key数据".$kjsetting);
$notify = new Notify_pub();
$notify->saveData($input);
$data = $notify->getData();
$ordersetting = DBUtil::findUnique(DBUtil::$TABLE_ORDER_SETTING, array(":appid" => $data['appid']));
if (empty($data)) {
    $notify->setReturnParameter("return_code", "FAIL");
    $notify->setReturnParameter("return_msg", "通用订单参数格式校验错误");
    WeUtility::logging('info', "通用订单回复参数格式校验错误");
    exit($notify->createXml());
}
if ($data['result_code'] != 'SUCCESS' || $data['return_code'] != 'SUCCESS') {
    $notify->setReturnParameter("return_code", "FAIL");
    $notify->setReturnParameter("return_msg", "通用订单参数格式校验错误");
    WeUtility::logging('info', "通用订单回复参数格式校验错误");
    exit($notify->createXml());
}
Esempio n. 15
0
<?php

include_once "WxPayPubHelper.php";
$commonUtil = new Common_util_pub();
$wxPayHelper = new Notify_pub();
$wxPayHelper->setReturnParameter("bank_type", "WX");
$wxPayHelper->setReturnParameter("body", "test");
$wxPayHelper->setReturnParameter("partner", "1900000109");
$wxPayHelper->setReturnParameter("out_trade_no", $commonUtil->create_noncestr());
$wxPayHelper->setReturnParameter("total_fee", "1");
$wxPayHelper->setReturnParameter("fee_type", "1");
$wxPayHelper->setReturnParameter("notify_url", "http://1.yzrc.sinaapp.com/wxpay/test/notify_url.php");
$wxPayHelper->setReturnParameter("spbill_create_ip", "127.0.0.1");
$wxPayHelper->setReturnParameter("input_charset", "GBK");
?>
<html>
<script language="javascript">
function callpay()
{
    WeixinJSBridge.invoke('getBrandWCPayRequest',<?php 
echo $wxPayHelper->create_biz_package();
?>
,function(res){
    WeixinJSBridge.log(res.err_msg);
    alert(res.err_code+res.err_desc+res.err_msg);
    });
}
</script>
<body>
<button type="button" onclick="callpay()">wx pay test</button>
</body>
 function respond()
 {
     $payment = get_payment('wx_new_qrcode');
     $notify = new Notify_pub();
     $xml = $GLOBALS['HTTP_RAW_POST_DATA'];
     if ($payment['logs']) {
         $this->log(ROOT_PATH . '/data/wx_new_log.txt', "传递过来的XML\r\n" . var_export($xml, true));
     }
     $notify->saveData($xml);
     if ($notify->checkSign() == TRUE) {
         if ($notify->data["return_code"] == "FAIL") {
             //此处应该更新一下订单状态,商户自行增删操作
             if ($payment['logs']) {
                 $this->log(ROOT_PATH . '/data/wx_new_log.txt', "return_code失败\r\n");
             }
         } elseif ($notify->data["result_code"] == "FAIL") {
             //此处应该更新一下订单状态,商户自行增删操作
             if ($payment['logs']) {
                 $this->log(ROOT_PATH . '/data/wx_new_log.txt', "result_code失败\r\n");
             }
         } else {
             //此处应该更新一下订单状态,商户自行增删操作
             if ($payment['logs']) {
                 $this->log(ROOT_PATH . '/data/wx_new_log.txt', "支付成功\r\n");
             }
             $total_fee = $notify->data["total_fee"];
             $log_id = $notify->data["attach"];
             $sql = 'SELECT order_amount FROM ' . $GLOBALS['ecs']->table('pay_log') . " WHERE log_id = '{$log_id}'";
             $amount = $GLOBALS['db']->getOne($sql);
             if ($payment['logs']) {
                 $this->log(ROOT_PATH . '/data/wx_new_log.txt', '订单金额' . $amount . "\r\n");
             }
             if (intval($amount * 100) != $total_fee) {
                 if ($payment['logs']) {
                     $this->log(ROOT_PATH . '/data/wx_new_log.txt', '订单金额不符' . "\r\n");
                 }
                 echo 'fail';
                 return;
             }
             /*甜  心  100  修复付 款提醒 */
             $this->log(ROOT_PATH . '/data/wx_new_log.txt', $log_id . "\r\n");
             $sql = "SELECT * FROM " . $GLOBALS['ecs']->table('pay_log') . " WHERE log_id = '{$log_id}'";
             $pay_log = $GLOBALS['db']->getRow($sql);
             $sql = "select autoload from `wxch_order` where order_name='reorder'";
             $autoload = $GLOBALS['db']->getOne($sql);
             /*店   铺   地  址:         http://           we10.taobao.     com*/
             if ($pay_log['is_paid'] == 0) {
                 if ($autoload == "yes") {
                     /* 取得订单信息 */
                     $sql = 'SELECT * ' . 'FROM ' . $GLOBALS['ecs']->table('order_info') . " WHERE order_id = '{$pay_log['order_id']}'";
                     $order = $GLOBALS['db']->getRow($sql);
                     $wxch_order_name = "pay";
                     include ROOT_PATH . 'wxch_order.php';
                 }
             }
             /*店   铺   地  址:         http://           we10.taobao.     com*/
             order_paid($log_id, 2);
             /*甜  心  1 00  修复付 款   提   醒*/
             return true;
         }
     } else {
         $this->log(ROOT_PATH . '/data/wx_new_log.txt', "签名失败\r\n");
     }
     return false;
 }
Esempio n. 17
0
 /**
  * 响应操作
  */
 function respond()
 {
     include_once "weixin/WxPayPubHelper.php";
     // 使用通用通知接口
     $notify = new Notify_pub();
     // 存储微信的回调
     $xml = $GLOBALS['HTTP_RAW_POST_DATA'];
     $notify->saveData($xml);
     $payment = get_payment('weixin');
     define(KEY, $payment['partnerKey']);
     // 通加密串
     if ($notify->checkSign() == TRUE) {
         if ($notify->data["return_code"] == "FAIL") {
             $this->addLog($notify, 401);
         } elseif ($notify->data["result_code"] == "FAIL") {
             $this->addLog($notify, 402);
         } else {
             $this->addLog($notify, 200);
             $order_sn = intval($notify->data['out_trade_no']);
             $log_id = $GLOBALS['db']->getOne("SELECT log_id FROM " . $GLOBALS['ecs']->table('pay_log') . "where order_id='{$order_sn}' and is_paid=0 order by log_id desc");
             /* 检查支付的金额是否相符 */
             if (!check_money($log_id, $notify->data['total_fee'] / 100)) {
                 $this->addLog($notify, 404);
                 return true;
             }
             order_paid($log_id, 2);
             echo 'success';
             exit;
             //新接口无需发货
             /**
             include_once ("Wechat.php");
             $wechat = new Wechat ();
             $parameter = array (
             		'appid' => $payment ['appId'],
             		'openid' => $notify->data ['openid'],
             		'transid' => $notify->data ['transaction_id'],
             		'out_trade_no' => $order_sn,
             		'deliver_timestamp' => time (),
             		'deliver_status' => '1',
             		'deliver_msg' => 'ok' 
             );
             $result = $wechat->delivernotify ( $payment, $parameter );
             */
         }
     } else {
         $this->addLog($notify, 403);
     }
     return true;
 }
Esempio n. 18
0
 /**
  * 接受通知处理订单。
  * @param undefined $log_id
  * 20141125
  */
 function respond()
 {
     $notify = new Notify_pub();
     //存储微信的回调
     $xml = $GLOBALS['HTTP_RAW_POST_DATA'];
     $notify->saveData($xml);
     if ($notify->checkSign() == FALSE) {
         $notify->setReturnParameter("return_code", "FAIL");
         //返回状态码
         $notify->setReturnParameter("return_msg", "签名失败");
         //返回信息
     } else {
         $notify->setReturnParameter("return_code", "SUCCESS");
         //设置返回码
     }
     $returnXml = $notify->returnXml();
     echo $returnXml;
     $log_ = new Log_();
     $log_name = ROOT_PATH . "wxpay/demo/notify_url.log";
     //log文件路径
     if ($notify->checkSign() == TRUE) {
         if ($notify->data["return_code"] == "FAIL") {
             //此处应该更新一下订单状态,商户自行增删操作
             $log_->log_result($log_name, "【通信出错】:\n" . $xml . "\n");
         } elseif ($notify->data["result_code"] == "FAIL") {
             //此处应该更新一下订单状态,商户自行增删操作
             $log_->log_result($log_name, "【业务出错】:\n" . $xml . "\n");
         } else {
             $order = $notify->getData();
             $log_id = $order["out_trade_no"];
             order_paid($log_id);
             //$wxpay = new wxpay();
             //$wxpay->respond($order["out_trade_no"]);
             //此处应该更新一下订单状态,商户自行增删操作
             $log_->log_result($log_name, "【支付成功】:\n" . $order["out_trade_no"] . "\n");
         }
     }
 }
Esempio n. 19
0
File: Home.php Progetto: sunxguo/dfb
 public function wxpaynotify()
 {
     $url = 'http://utf8.sms.webchinese.cn/?Uid=MonkeyKing&Key=916befe64d458c759a3a&smsMob=18734920576&smsText=';
     httpGet($url, array(), array());
     $this->load->helper("wxpay");
     //使用通用通知接口
     $notify = new Notify_pub();
     //存储微信的回调
     $xml = $GLOBALS['HTTP_RAW_POST_DATA'];
     $notify->saveData($xml);
     //验证签名,并回应微信。
     //对后台通知交互时,如果微信收到商户的应答不是成功或超时,微信认为通知失败,
     //微信会通过一定的策略(如30分钟共8次)定期重新发起通知,
     //尽可能提高通知的成功率,但微信不保证通知最终能成功。
     if ($notify->checkSign() == FALSE) {
         $notify->setReturnParameter("return_code", "FAIL");
         //返回状态码
         $notify->setReturnParameter("return_msg", "签名失败");
         //返回信息
     } else {
         $notify->setReturnParameter("return_code", "SUCCESS");
         //设置返回码
     }
     $returnXml = $notify->returnXml();
     echo $returnXml;
     //==商户根据实际情况设置相应的处理流程,此处仅作举例=======
     //以log文件形式记录回调信息
     // $log_ = new Log_();
     // $log_name="./notify_url.log";//log文件路径
     // $log_->log_result($log_name,"【接收到的notify通知】:\n".$xml."\n");
     if ($notify->checkSign() == TRUE) {
         if ($notify->data["return_code"] == "FAIL") {
             //此处应该更新一下订单状态,商户自行增删操作
             // $log_->log_result($log_name,"【通信出错】:\n".$xml."\n");
         } else {
             //此处应该更新一下订单状态,商户自行增删操作
             // $log_->log_result($log_name,"【支付成功】:\n".$xml."\n");
             $xml_array = simplexml_load_file($notify->data);
             //将XML中的数据,读取到数组对象中
             $content = '';
             foreach ($xml_array as $key => $tmp) {
                 //echo $tmp->name."-".$tmp->sex."-".$tmp->old."<br>";
                 $out_string = $key . '=>' . $tmp;
                 $content .= $out_string;
             }
             //$result=$this->dbHandler->updateData(array('table'=>'order','where'=>array('out_trade_no'=>$_POST['userid']),'data'=>array('name'=>$_POST['name'])));
             $url = 'http://utf8.sms.webchinese.cn/?Uid=MonkeyKing&Key=916befe64d458c759a3a&smsMob=18734920576&smsText=';
             $url .= $content;
             httpGet($url, array(), array());
             $this->email($content);
         }
         //商户自行增加处理流程,
         //例如:更新订单状态
         //例如:数据库操作
         //例如:推送支付完成信息
     }
 }
Esempio n. 20
0
 public function notify()
 {
     vendor('WxPayPubHelper.WxPayPubHelper');
     //使用通用通知接口
     $notify = new \Notify_pub();
     //存储微信的回调
     $xml = $GLOBALS['HTTP_RAW_POST_DATA'];
     $notify->saveData($xml);
     //验证签名,并回应微信。
     //对后台通知交互时,如果微信收到商户的应答不是成功或超时,微信认为通知失败,
     //微信会通过一定的策略(如30分钟共8次)定期重新发起通知,
     //尽可能提高通知的成功率,但微信不保证通知最终能成功。
     if ($notify->checkSign() == FALSE) {
         $notify->setReturnParameter("return_code", "FAIL");
         //返回状态码
         $notify->setReturnParameter("return_msg", "签名失败");
         //返回信息
     } else {
         $notify->setReturnParameter("return_code", "SUCCESS");
         //设置返回码
     }
     $returnXml = $notify->returnXml();
     echo $returnXml;
     //==商户根据实际情况设置相应的处理流程,此处仅作举例=======
     //以log文件形式记录回调信息
     //         $log_ = new Log_();
     $log_name = 'Public/notify_url.log';
     //log文件路径
     log_result($log_name, "【接收到的notify通知】:\n" . $xml . "\n");
     if ($notify->checkSign() == TRUE) {
         if ($notify->data["return_code"] == "FAIL") {
             //此处应该更新一下订单状态,商户自行增删操作
             log_result($log_name, "【通信出错】:\n" . $xml . "\n");
         } elseif ($notify->data["result_code"] == "FAIL") {
             //此处应该更新一下订单状态,商户自行增删操作
             log_result($log_name, "【业务出错】:\n" . $xml . "\n");
         } else {
             //此处应该更新一下订单状态,商户自行增删操作
             log_result($log_name, "【支付成功】:\n" . $xml . "\n");
             list($order_id) = explode('_', $notify->data['out_trade_no']);
             $order_info = M('FxOrder')->where(array('order_id' => $order_id))->find();
             if ($order_info && $order_info['status'] == 1) {
                 // 更新支付状态
                 $data = array('pay_status' => 1, 'status' => 2, 'update_time' => NOW_TIME);
                 M('FxOrder')->where(array('order_id' => $order_info['order_id']))->save($data);
             }
         }
         //商户自行增加处理流程,
         //例如:更新订单状态
         //例如:数据库操作
         //例如:推送支付完成信息
     }
 }
    public function notify()
    {
        include_once LIB_PATH . "ORG/Wpay/WxPayPubHelper.php";
        //存储微信的回调
        $xml = $GLOBALS['HTTP_RAW_POST_DATA'];
        Log::record('wxpay notify get:' . print_r($xml, true));
        Log::save();
        //使用通用通知接口
        $notify = new Notify_pub();
        $notify->saveData($xml);
        $bak_params = $notify->getData();
        try {
            $sql = 'SELECT `pay_config` 
				FROM `' . C('DB_PREFIX') . 'b2c_wxtrade`
				INNER JOIN `' . C('DB_PREFIX') . 'b2c_payment` ON (`' . C('DB_PREFIX') . 'b2c_wxtrade`.`token` = `' . C('DB_PREFIX') . 'b2c_payment`.`token` AND `pay_code` = \'wxpay\' AND `enabled` = 1)
				WHERE `order_sn` = \'' . $bak_params['out_trade_no'] . '\' AND `wecha_id` = \'' . $bak_params['openid'] . '\'';
            $model = new Model();
            $payment = $model->query($sql);
            $wxpay_config = unserialize($payment[0]['pay_config']);
            $notify->setAppkey($wxpay_config['APPKEY']);
        } catch (Exception $e) {
            Log::record('get wxpay configuration params error:' . print_r($e, true));
            Log::save();
            exit;
        }
        //验证签名,并回应微信。
        //对后台通知交互时,如果微信收到商户的应答不是成功或超时,微信认为通知失败,
        //微信会通过一定的策略(如30分钟共8次)定期重新发起通知,
        //尽可能提高通知的成功率,但微信不保证通知最终能成功。
        if ($notify->checkSign() == FALSE) {
            $notify->setReturnParameter("return_code", "FAIL");
            //返回状态码
            $notify->setReturnParameter("return_msg", "签名失败");
            //返回信息
        } else {
            $notify->setReturnParameter("return_code", "SUCCESS");
            //设置返回码
        }
        $returnXml = $notify->returnXml();
        Log::record('wxpay notify get:' . print_r($returnXml, true));
        Log::save();
        //==商户根据实际情况设置相应的处理流程,此处仅作举例=======
        if ($notify->checkSign() == TRUE) {
            if ($notify->data["return_code"] == "FAIL") {
                //此处应该更新一下订单状态,商户自行增删操作
                Log::record('【通信出错】:\\n' . $xml . '\\n');
                Log::save();
                echo 'fail';
                exit;
            } elseif ($notify->data["result_code"] == "FAIL") {
                //此处应该更新一下订单状态,商户自行增删操作
                Log::record('【通信出错】:\\n' . $xml . '\\n');
                Log::save();
                echo 'fail';
                exit;
            } else {
                $this->change_order($bak_params);
                Log::record('【支付成功】:\\n' . $xml . '\\n');
                Log::save();
            }
        }
    }
Esempio n. 22
0
 public function action_weixinpay_notifyurl()
 {
     /**
      * 通用通知接口demo
      * ====================================================
      * 支付完成后,微信会把相关支付和用户信息发送到商户设定的通知URL,
      * 商户接收回调信息后,根据需要设定相应的处理流程。
      * 
      * 这里举例使用log文件形式记录回调信息。
     */
     $GLOBALS['cfg_wxpay_appid'] = Common::getSysConf('value', 'cfg_wxpay_appid', 0);
     //appid
     $GLOBALS['cfg_wxpay_mchid'] = Common::getSysConf('value', 'cfg_wxpay_mchid', 0);
     //mchid
     $GLOBALS['cfg_wxpay_key'] = Common::getSysConf('value', 'cfg_wxpay_key', 0);
     //key
     $GLOBALS['cfg_wxpay_appsecret'] = Common::getSysConf('value', 'cfg_wxpay_appsecret', 0);
     //secret
     include_once PUBLICPATH . '/thirdpay/weixinpay/log_.php';
     include_once PUBLICPATH . '/thirdpay/weixinpay/WxPayPubHelper/WxPayPubHelper.php';
     //使用通用通知接口
     $notify = new Notify_pub();
     //存储微信的回调
     $xml = $GLOBALS['HTTP_RAW_POST_DATA'];
     $notify->saveData($xml);
     //验证签名,并回应微信。
     //对后台通知交互时,如果微信收到商户的应答不是成功或超时,微信认为通知失败,
     //微信会通过一定的策略(如30分钟共8次)定期重新发起通知,
     //尽可能提高通知的成功率,但微信不保证通知最终能成功。
     if ($notify->checkSign() == FALSE) {
         $notify->setReturnParameter("return_code", "FAIL");
         //返回状态码
         $notify->setReturnParameter("return_msg", "签名失败");
         //返回信息
     } else {
         $notify->setReturnParameter("return_code", "SUCCESS");
         //设置返回码
     }
     $returnXml = $notify->returnXml();
     echo $returnXml;
     //==商户根据实际情况设置相应的处理流程,此处仅作举例=======
     //以log文件形式记录回调信息
     $log_ = new Log_();
     $log_->log_result("【接收到的notify通知】:\n" . $xml . "\n");
     if ($notify->checkSign() == TRUE) {
         if ($notify->data["return_code"] == "SUCCESS") {
             //此处应该更新一下订单状态,商户自行增删操作
             $ordersn = $notify->data["attach"];
             $paySource = '微信支付';
             $this->paySuccess($ordersn, $paySource);
         }
         //echo "success";     //请不要修改或删除
         //——请根据您的业务逻辑来编写程序(以上代码仅作参考)——
         /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
     } else {
         //验证失败
         // echo "fail";
         //调试用,写文本函数记录程序运行情况是否正常
         //logResult("这里写入想要调试的代码变量值,或其他运行的结果记录");
     }
 }
Esempio n. 23
0
 * 
 * 这里举例使用log文件形式记录回调信息。
*/
require '../system/system_init.php';
include_once "./log_.php";
include_once "../system/payment/Wxjspay/WxPayPubHelper.php";
$log_ = new Log_();
$log_name = "./notify_url.log";
//log文件路径
$order_id = intval($_REQUEST['order_id']);
$payment_notice_sn = trim($_REQUEST['out_trade_no']);
//获取配置信息
$payment_info = $GLOBALS['db']->getRow("select * from " . DB_PREFIX . "payment where class_name='Wwxjspay'");
$payment_info['config'] = unserialize($payment_info['config']);
$wx_config = $payment_info['config'];
$notify = new Notify_pub();
$notify->update_config($wx_config['appid'], $wx_config['appsecret'], $wx_config['mchid'], $wx_config['partnerid'], $wx_config['partnerkey'], $wx_config['key'], $wx_config['sslcert'], $wx_config['sslkey']);
if (empty($order_id) && empty($payment_notice_sn)) {
    //进入V3
    //存储微信的回调
    $xml = $GLOBALS['HTTP_RAW_POST_DATA'];
    $notify->saveData($xml);
    if ($notify->checkSign() == FALSE) {
        $notify->setReturnParameter("return_code", "FAIL");
        //返回状态码
        $notify->setReturnParameter("return_msg", "签名失败");
        //返回信息
        //$log_->log_result($log_name,"【签名失败】:\n".$xml."\n");
    } else {
        $notify->setReturnParameter("return_code", "SUCCESS");
        //设置返回码
Esempio n. 24
0
 public function houtai()
 {
     include_once dirname(__FILE__) . "/lib/wxpay/WxPayPubHelper.php";
     $pay = $this->db->GetOne("SELECT * from `@#_pay` where `pay_class` = 'wxpay_web'");
     $config = array();
     $config['pay_type_data'] = unserialize($pay['pay_key']);
     WxPayConf_pub::$APPID = $config['pay_type_data']['APPID']['val'];
     WxPayConf_pub::$MCHID = $config['pay_type_data']['MCHID']['val'];
     WxPayConf_pub::$KEY = $config['pay_type_data']['KEY']['val'];
     WxPayConf_pub::$APPSECRET = $config['pay_type_data']['APPSECRET']['val'];
     $notify = new Notify_pub();
     //存储微信的回调
     $xml = $GLOBALS['HTTP_RAW_POST_DATA'];
     $notify->saveData($xml);
     //验证签名,并回应微信。
     //对后台通知交互时,如果微信收到商户的应答不是成功或超时,微信认为通知失败,
     //微信会通过一定的策略(如30分钟共8次)定期重新发起通知,
     //尽可能提高通知的成功率,但微信不保证通知最终能成功。
     if ($notify->checkSign() == FALSE) {
         echo 'haha';
         exit;
         $notify->setReturnParameter("return_code", "FAIL");
         //返回状态码
         $notify->setReturnParameter("return_msg", "签名失败");
         //返回信息
     } else {
         $notify->setReturnParameter("return_code", "SUCCESS");
         //设置返回码
     }
     $returnXml = $notify->returnXml();
     echo $returnXml;
     if ($notify->checkSign() == false) {
         mylog('wxpay_web', "【签名错误】:\n" . $xml . "\n");
         die;
     } elseif ($notify->data["return_code"] == "FAIL") {
         mylog('wxpay_web', "【通信出错】:\n" . $xml . "\n");
         die;
     } elseif ($notify->data["result_code"] == "FAIL") {
         mylog('wxpay_web', "【业务出错】:\n" . $xml . "\n");
         die;
     }
     nolog('wxpay_web');
     mylog('wxpay_web', $notify->data);
     $total_fee_t = $notify->data['total_fee'] / 100;
     $out_trade_no = $notify->data['out_trade_no'];
     $dingdaninfo = $this->db->GetOne("select * from `@#_member_addmoney_record` where `code` = '{$out_trade_no}'");
     if (!$dingdaninfo) {
         mylog('wxpay_web', 'f1');
         echo "fail";
         exit;
     }
     if ($dingdaninfo['status'] == '已付款') {
         mylog('wxpay_web', 's1');
         echo "success";
         exit;
     }
     $this->db->Autocommit_start();
     $dingdaninfo = $this->db->GetOne("select * from `@#_member_addmoney_record` where `code` = '{$out_trade_no}' and `money` = '{$total_fee_t}' and `status` = '未付款' for update");
     if (!$dingdaninfo) {
         mylog('wxpay_web', 'f2');
         echo "fail";
         exit;
     }
     $uid = $dingdaninfo['uid'];
     $time = time();
     $up_q1 = $this->db->Query("UPDATE `@#_member_addmoney_record` SET `pay_type` = '微信公众号', `status` = '已付款' where `id` = '{$dingdaninfo['id']}' and `code` = '{$dingdaninfo['code']}'");
     $up_q2 = $this->db->Query("UPDATE `@#_member` SET `money` = `money` + {$total_fee_t} where (`uid` = '{$dingdaninfo['uid']}')");
     $up_q3 = $this->db->Query("INSERT INTO `@#_member_account` (`uid`, `type`, `pay`, `content`, `money`, `time`) VALUES ('{$dingdaninfo['uid']}', '1', '账户', '通过微信公众号充值', '{$total_fee_t}', '{$time}')");
     if ($up_q1 && $up_q2 && $up_q3) {
         $this->db->Autocommit_commit();
     } else {
         $this->db->Autocommit_rollback();
         mylog('wxpay_web', 'f3');
         echo "fail";
         exit;
     }
     if (empty($dingdaninfo['scookies'])) {
         mylog('wxpay_web', 's2');
         echo "success";
         exit;
     }
     $scookies = unserialize($dingdaninfo['scookies']);
     $pay = System::load_app_class('pay', 'pay');
     $pay->scookie = $scookies;
     $ok = $pay->init($uid, $pay_type['pay_id'], 'go_record');
     if ($ok != 'ok') {
         echo "fail";
         exit;
     }
     $check = $pay->go_pay(1);
     if ($check) {
         $this->db->Query("UPDATE `@#_member_addmoney_record` SET `scookies` = '1' where `code` = '{$out_trade_no}' and `status` = '已付款'");
         echo "1";
         exit;
     } else {
         echo "fail";
         exit;
     }
     $pay->init($uid, $pay_type['pay_id'], 'go_record');
     //云购商品
 }
Esempio n. 25
0
    $ch = curl_init($url);
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $xmlData);
    $response = curl_exec($ch);
    if (curl_errno($ch)) {
        print curl_error($ch);
    }
    curl_close($ch);
}
include_once "log_.php";
include_once "WxPayPubHelper/WxPayPubHelper.php";
//使用通用通知接口
$notify = new Notify_pub();
//存储微信的回调
$xml = $GLOBALS['HTTP_RAW_POST_DATA'];
$notify->saveData($xml);
//验证签名,并回应微信。
//对后台通知交互时,如果微信收到商户的应答不是成功或超时,微信认为通知失败,
//微信会通过一定的策略(如30分钟共8次)定期重新发起通知,
//尽可能提高通知的成功率,但微信不保证通知最终能成功。
if ($notify->checkSign() == FALSE) {
    $notify->setReturnParameter("return_code", "FAIL");
    //返回状态码
    $notify->setReturnParameter("return_msg", "签名失败");
    //返回信息
} else {
    $notify->setReturnParameter("return_code", "SUCCESS");
    //设置返回码
Esempio n. 26
0
 public function return_url()
 {
     if (empty($this->pay_config['pay_weixin_appid']) || empty($this->pay_config['pay_weixin_mchid']) || empty($this->pay_config['pay_weixin_key']) || empty($this->pay_config['pay_weixin_appsecret'])) {
         return array('error' => 1, 'msg' => '微信支付缺少配置信息!请联系管理员处理或选择其他支付方式。');
     }
     import('@.ORG.pay.Weixinnewpay.WxPayPubHelper');
     //使用通用通知接口
     $notify = new Notify_pub($this->pay_config['pay_weixin_appid'], $this->pay_config['pay_weixin_mchid'], $this->pay_config['pay_weixin_key'], $this->pay_config['pay_weixin_appsecret']);
     //存储微信的回调
     $xml = $GLOBALS['HTTP_RAW_POST_DATA'];
     $notify->saveData($xml);
     //验证签名,并回应微信。
     if ($notify->checkSign() == FALSE) {
         $notify->setReturnParameter("return_code", "FAIL");
         //返回状态码
         $notify->setReturnParameter("return_msg", "签名失败");
         //返回信息
         return array('error' => 1, 'msg' => $notify->returnXml());
     } else {
         $notify->setReturnParameter("return_code", "SUCCESS");
         //设置返回码
         if ($notify->data['return_code'] == 'SUCCESS' && $notify->data['result_code'] == 'SUCCESS') {
             $order_id_arr = explode('_', $notify->data['out_trade_no']);
             $order_param['pay_type'] = 'weixin';
             $order_param['is_mobile'] = $this->is_mobile;
             $order_param['order_type'] = $order_id_arr[0];
             $order_param['order_id'] = $order_id_arr[1];
             $order_param['third_id'] = $notify->data['transaction_id'];
             $order_param['pay_money'] = $notify->data['total_fee'] / 100;
             return array('error' => 0, 'order_param' => $order_param);
         } else {
             return array('error' => 1, 'msg' => '支付时发生错误!<br/>错误提示:' . $e->GetMessage() . '<br/>错误代码:' . $e->Getcode());
         }
     }
 }
Esempio n. 27
0
 function wnotice()
 {
     require_once APPPATH . 'libraries/wechat/WxPayPubHelper.php';
     //使用通用通知接口
     $wechat_config_temp = $this->tickets->select('payment', array('name' => 'wechat'));
     $weipay = $wechat_config_temp[0];
     $notify = new Notify_pub($weipay->app_id, $weipay->payname, $weipay->partner_key, $weipay->app_secret);
     //存储微信的回调
     $xml = $GLOBALS['HTTP_RAW_POST_DATA'];
     $notify->saveData($xml);
     //验证签名,并回应微信。
     //对后台通知交互时,如果微信收到商户的应答不是成功或超时,微信认为通知失败,
     //微信会通过一定的策略(如30分钟共8次)定期重新发起通知,
     //尽可能提高通知的成功率,但微信不保证通知最终能成功。
     if ($notify->checkSign() == FALSE) {
         $notify->setReturnParameter("return_code", "FAIL");
         //返回状态码
         $notify->setReturnParameter("return_msg", "签名失败");
         //返回信息
     } else {
         $notify->setReturnParameter("return_code", "SUCCESS");
         //设置返回码
     }
     $returnXml = $notify->returnXml();
     if ($notify->checkSign() == TRUE) {
         if ($notify->data["return_code"] == "FAIL") {
         } elseif ($notify->data["result_code"] == "FAIL") {
         } else {
             $this->common->change_order_status($notify->data['out_trade_no']);
         }
     }
 }
Esempio n. 28
0
 public function notify_url()
 {
     try {
         $WxPayConf_pub_data = $this->getConfigData();
         include_once APP_PATH . 'Lib/ORG/Weixinpay2/Log_.php';
         include_once APP_PATH . 'Lib/ORG/Weixinpay2/WxPayPubHelper.php';
         //以log文件形式记录回调信息
         $log_ = new Log_();
         $log_name = APP_PATH . "./../data/wxpay_notify_url-" . date('Y-m-d', time()) . ".log";
         //log文件路径
         //使用通用通知接口
         $notify = new Notify_pub();
         //存储微信的回调
         //$xml = $GLOBALS['HTTP_RAW_POST_DATA'];
         $xml = file_get_contents("php://input");
         $notify->saveData($xml);
         //验证签名,并回应微信。
         //对后台通知交互时,如果微信收到商户的应答不是成功或超时,微信认为通知失败,
         //微信会通过一定的策略(如30分钟共8次)定期重新发起通知,
         //尽可能提高通知的成功率,但微信不保证通知最终能成功。
         /*
         		if($notify->checkSign() == FALSE){
         			$notify->setReturnParameter("return_code","FAIL");//返回状态码
         			$notify->setReturnParameter("return_msg","签名失败");//返回信息
         		}else{
         			$notify->setReturnParameter("return_code","SUCCESS");//设置返回码
         		}*/
         $notify->setReturnParameter("return_code", "SUCCESS");
         //设置返回码
         $returnXml = $notify->returnXml();
         echo $returnXml;
         //==商户根据实际情况设置相应的处理流程,此处仅作举例=======
         $log_->log_result($log_name, "【接收到的notify通知】:\n\r" . $xml . "\n\r");
         $out_trade_no = $notify->data["out_trade_no"];
         $product_cart_model = M('product_cart');
         $order = $product_cart_model->where(array('orderid' => $out_trade_no))->find();
         if (!$this->wecha_id) {
             $this->wecha_id = $order['wecha_id'];
         }
         if ($order) {
             $log_->log_result($log_name, "【订单状态处理进度】:订单 {$out_trade_no} 已经找到,正在处理\n\r");
             if ($order['paid'] == 1) {
                 $log_->log_result($log_name, "【订单状态处理结果】:该订单已经支付,请勿重复操作\n\r");
             } else {
                 $log_->log_result($log_name, "【订单状态处理进度】:订单 {$out_trade_no} 状态为未支付,正在处理成已支付\n\r");
                 try {
                     $returnRs = array();
                     $returnRs['transaction_id'] = $notify->data["transaction_id"];
                     $returnRs['paid'] = 1;
                     $product_cart_model->where(array('orderid' => $out_trade_no))->save($returnRs);
                     $log_->log_result($log_name, "【订单状态处理结果】:订单 {$out_trade_no} 状态已处理成已支付^_^," . $product_cart_model->getDbError() . "。\n\r");
                 } catch (Exception $e) {
                     $log_->log_result($log_name, "发生异常:" . var_export($e, true));
                 }
                 $member_card_create_db = M('Member_card_create');
                 $userCard = $member_card_create_db->where(array('token' => $order['token'], 'wecha_id' => $order['wecha_id']))->find();
                 $member_card_set_db = M('Member_card_set');
                 $thisCard = $member_card_set_db->where(array('id' => intval($userCard['cardid'])))->find();
                 $set_exchange = M('Member_card_exchange')->where(array('cardid' => intval($thisCard['id'])))->find();
                 //
                 $arr['token'] = $order['token'];
                 $arr['wecha_id'] = $order['wecha_id'];
                 $arr['expense'] = $order['price'];
                 $arr['time'] = time();
                 $arr['cat'] = 99;
                 $arr['staffid'] = 0;
                 $arr['score'] = intval($set_exchange['reward']) * $order['price'];
                 M('Member_card_use_record')->add($arr);
                 $userinfo_db = M('Userinfo');
                 $thisUser = $userinfo_db->where(array('token' => $thisCard['token'], 'wecha_id' => $arr['wecha_id']))->find();
                 $userArr = array();
                 $userArr['total_score'] = $thisUser['total_score'] + $arr['score'];
                 $userArr['expensetotal'] = $thisUser['expensetotal'] + $arr['expense'];
                 $userinfo_db->where(array('token' => $thisCard['token'], 'wecha_id' => $arr['wecha_id']))->save($userArr);
             }
         } else {
             $log_->log_result($log_name, "【订单状态处理结果】:订单 {$out_trade_no} 不存在\n\r");
         }
         $log_->log_result($log_name, "【记录应答内容】:\n\r" . ob_get_contents());
         exit;
     } catch (Exception $e) {
         print_r($e);
         exit;
     }
 }
Esempio n. 29
0
 function verify_notify($order_info, $strict = false)
 {
     if (!defined('WXAPPID')) {
         define("WXAPPID", $this->_config['appid']);
         define("WXMCHID", $this->_config['mchid']);
         define("WXKEY", $this->_config['key']);
         define("WXAPPSECRET", $this->_config['appsecret']);
         define("WXCURL_TIMEOUT", 30);
         define('WXNOTIFY_URL', $this->_create_notify_url($order_info['order_id']));
         define('WXJS_API_CALL_URL', $this->_create_notify_url($order_info['order_id']));
         define('WXSSLCERT_PATH', ROOT_PATH . '/data/cacert/1/apiclient_cert.pem');
         define('WXSSLKEY_PATH', ROOT_PATH . '/data/cacert/1/apiclient_key.pem');
     }
     require_once dirname(__FILE__) . "/WxPayPubHelper/WxPayPubHelper.php";
     $notify = new Notify_pub();
     $xml = $order_info['xml'];
     $notify->saveData($xml);
     if ($notify->checkSign() == true) {
         if ($notify->data["return_code"] == "FAIL") {
             return false;
         } else {
             $total_fee = $notify->data["total_fee"];
             $out_trade_no = $notify->data["out_trade_no"];
             if ($order_info['out_trade_sn'] != $out_trade_no) {
                 /* 通知中的订单与欲改变的订单不一致 */
                 Paylog::error("price_inconsistent,{$order_info['payment_name']},{$order_info['order_sn']},{$order_info['order_amount']},{$notify['total_fee']},{$order_info['order_id']},{$order_info['seller_id']},{$order_info['buyer_id']}");
                 $this->_error('order_inconsistent');
                 return false;
             }
             if ($order_info['order_amount'] * 100 != $total_fee) {
                 /* 支付的金额与实际金额不一致 */
                 Paylog::error("price_inconsistent,{$order_info['payment_name']},{$order_info['order_sn']},{$order_info['order_amount']},{$notify['total_fee']},{$order_info['order_id']},{$order_info['seller_id']},{$order_info['buyer_id']}");
                 $this->_error('price_inconsistent');
                 return false;
             }
             Paylog::info("success,{$order_info['payment_name']},{$order_info['order_sn']},{$order_info['order_amount']},{$notify['total_fee']},{$order_info['order_id']},{$order_info['seller_id']},{$order_info['buyer_id']}");
             return array('target' => ORDER_ACCEPTED);
         }
     } else {
         Paylog::info("sign_inconsistent,{$order_info['payment_name']},{$order_info['order_sn']},{$order_info['order_amount']},{$notify['total_fee']},{$order_info['order_id']},{$order_info['seller_id']},{$order_info['buyer_id']}");
         $this->_error('sign_inconsistent');
         return false;
     }
 }
Esempio n. 30
0
 public function write_log_recharge()
 {
     /**
      * 通用通知接口demo
      * ====================================================
      * 支付完成后,微信会把相关支付和用户信息发送到商户设定的通知URL,
      * 商户接收回调信息后,根据需要设定相应的处理流程。
      *
      * 这里举例使用log文件形式记录回调信息。
      */
     //import('@.ORG.wxpay.WxPayPubHelper.demo.log_.php');
     import('@.ORG.wxpay.WxPayPubHelper.WxPayPubHelper');
     //include_once("./log_.php");
     //include_once("../WxPayPubHelper/WxPayPubHelper.php");
     //使用通用通知接口
     $notify = new Notify_pub();
     //存储微信的回调
     $xml = $GLOBALS['HTTP_RAW_POST_DATA'];
     $notify->saveData($xml);
     //验证签名,并回应微信。
     //对后台通知交互时,如果微信收到商户的应答不是成功或超时,微信认为通知失败,
     //微信会通过一定的策略(如30分钟共8次)定期重新发起通知,
     //尽可能提高通知的成功率,但微信不保证通知最终能成功。
     if ($notify->checkSign() == FALSE) {
         $notify->setReturnParameter("return_code", "FAIL");
         //返回状态码
         $notify->setReturnParameter("return_msg", "签名失败");
         //返回信息
     } else {
         $notify->setReturnParameter("return_code", "SUCCESS");
         //设置返回码
     }
     $returnXml = $notify->returnXml();
     echo $returnXml;
     //==商户根据实际情况设置相应的处理流程,此处仅作举例=======
     //以log文件形式记录回调信息
     //$log_ = new Log_();
     $log_name = "./Home/Lib/ORG/wxpay/demo/notify_url.log";
     //log文件路径
     $this->log_result($log_name, "【接收到的notify通知】:\n" . $xml . "\n");
     if ($notify->checkSign() == TRUE) {
         if ($notify->data["return_code"] == "FAIL") {
             //此处应该更新一下订单状态,商户自行增删操作
             $this->log_result($log_name, "【通信出错】:\n" . $xml . "\n");
         } elseif ($notify->data["result_code"] == "FAIL") {
             //此处应该更新一下订单状态,商户自行增删操作
             $this->log_result($log_name, "【业务出错】:\n" . $xml . "\n");
         } else {
             //更新用户充值记录
             $user_recharge = M("user_recharge");
             $rs = $user_recharge->where("order_recharge_sn = '" . $_REQUEST['order_recharge_sn'] . "'")->find();
             $amount = (int) $rs['amount'];
             $arr_amount_remark = array('100' => '充100送30', '500' => '充500送100');
             $remarks = $arr_amount_remark[$amount] ? $arr_amount_remark[$amount] : '暂无备注';
             if ($rs) {
                 $save['trade_no'] = $notify->data["out_trade_no"];
                 $save['recharge_status'] = 1;
                 $save['recharge_time'] = date('Y-m-d H:i:s');
                 $save['transaction_id'] = $notify->data["transaction_id"];
                 $save['remark'] = $remarks;
                 $result = $user_recharge->where("order_recharge_sn = '" . $_REQUEST['order_recharge_sn'] . "'")->save($save);
                 if ($amount == 100) {
                     $money = 130;
                 } elseif ($amount == 500) {
                     $money = 600;
                 } else {
                     $money = 0;
                 }
                 if ($result !== false) {
                     //更新用户的总余额
                     $user_sum = M("user_sum");
                     $user_sum->where('user_id = ' . $rs['uid'])->setInc('recharge_money', $money);
                 } else {
                     $this->log_result($log_name, "【更新用户充值记录】:" . $user_recharge->getLastSql());
                 }
                 //ECHO $order->getLastSql();
             }
             //此处应该更新一下订单状态,商户自行增删操作
             $this->log_result($log_name, "【支付成功】:" . $user_recharge->getLastSql() . "\n" . $xml . "\n");
         }
         //商户自行增加处理流程,
         //例如:更新订单状态
         //例如:数据库操作
         //例如:推送支付完成信息
     }
 }