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; }
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()); } } }
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); } } }
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); } } }
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; } }
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; } }
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); } } //商户自行增加处理流程, //例如:更新订单状态 //例如:数据库操作 //例如:推送支付完成信息 } }
/** * 微信支付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); } } } }
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("这里写入想要调试的代码变量值,或其他运行的结果记录"); } }
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; } }
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('Order')->where(array('order_id' => $order_id))->find(); $order_info['product_name'] = get_product_info($order_info['product_id']); if ($order_info && $order_info['status'] == 1) { $options = array('appid' => \WxPayConf_pub::APPID, 'appsecret' => \WxPayConf_pub::APPSECRET); $WX = new \Vendor\TPWechat($options); // 给客户发 $end_time = strtotime('+3 day'); $temp = array('touser' => get_shop_info($order_info['user_id'], 'openid'), 'template_id' => 'hIPbD2pnKDr-oUt5LdR3tFlAn2WaFdLi8KTRzSrvgH0', 'url' => \WxPayConf_pub::JS_API_CALL_URL . U('Order/index', array('order_id' => $order_id)), 'topcolor' => '#FF0000', 'data' => array('first' => array('value' => '你好,【' . $order_info['product_name'] . '】订单已经完成支付'), 'keyword1' => array('value' => $order_info['order_id']), 'keyword2' => array('value' => '支付成功(等待卖家发货)', 'color' => '#FF0000'), 'keyword3' => array('value' => $order_info['product_name']), 'remark' => array('value' => '违约有效期:' . date('Y-m-d H:i:s', $end_time)))); $WX->sendTemplateMessage($temp); // 给商家发 $temp['touser'] = get_shop_info($order_info['shop_id'], 'openid'); $temp['data']['first']['value'] = '你好,【' . $order_info['product_name'] . '】订单已经完成支付,请尽快发货'; $WX->sendTemplateMessage($temp); // 更新支付状态 $data = array('status' => 2, 'update_time' => NOW_TIME, 'end_time' => $end_time); M('Order')->where(array('order_id' => $order_info['order_id']))->save($data); $data = array('action' => 1, 'order_id' => $notify->data['out_trade_no'], 'fee' => $notify->data['total_fee'], 'time' => NOW_TIME); M('Pay_log')->add($data); } } //商户自行增加处理流程, //例如:更新订单状态 //例如:数据库操作 //例如:推送支付完成信息 } }
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']); } } }
public function notify($channel) { $xml = file_get_contents("php://input"); //$xml = '<xml><appid><![CDATA[wx62ad814ba9bf0b68]]></appid> // <bank_type><![CDATA[CFT]]></bank_type> // <cash_fee><![CDATA[1]]></cash_fee> // <fee_type><![CDATA[CNY]]></fee_type> // <is_subscribe><![CDATA[Y]]></is_subscribe> // <mch_id><![CDATA[1227304102]]></mch_id> // <nonce_str><![CDATA[yj1vuhafyyuvmcpz2p9992a91ul06edd]]></nonce_str> // <openid><![CDATA[oFA64s5NHmfwEaEl5jIfjTgsy1Pw]]></openid> // <out_trade_no><![CDATA[test0702152451350439000000000095]]></out_trade_no> // <result_code><![CDATA[SUCCESS]]></result_code> // <return_code><![CDATA[SUCCESS]]></return_code> // <sign><![CDATA[4E0910D81068E34969D263BE21A7BF99]]></sign> // <time_end><![CDATA[20150702152605]]></time_end> // <total_fee>1</total_fee> // <trade_type><![CDATA[JSAPI]]></trade_type> // <transaction_id><![CDATA[1008410170201507020336471776]]></transaction_id> // </xml>' ; $params = CommonUtil::xmlToArray($xml); $partner = $params['mch_id']; $config = $this->getConfigByPartner($channel, $partner); $notify = new \Notify_pub($config); $notify->saveData($xml); $notice = []; if ($notify->checkSign() == TRUE) { /// 通信出错 if ($notify->data["return_code"] == "FAIL") { $notify->setReturnParameter("return_code", "FAIL"); //返回状态码 $notify->setReturnParameter("return_msg", "通信出错"); //返回信息 /// 业务出错 } elseif ($notify->data["result_code"] == "FAIL") { $notify->setReturnParameter("return_code", "FAIL"); //返回状态码 $notify->setReturnParameter("return_msg", "业务出错"); //返回信息 /// 支付成功 } else { $notify->setReturnParameter("return_code", "SUCCESS"); //设置返回码 $notice['type'] = 'direct'; $notice['mer_recharge_no'] = $params['out_trade_no']; //商户订单号 $notice['ser_recharge_no'] = $params['transaction_id']; //第三方支付单号 $notice['gateway_account'] = $params['openid']; //用户在商户appid下的唯一标识 $notice['seller_partner'] = $params['mch_id']; //商户号 $notice['notify_status'] = 2; $notice['notify_log'] = '支付成功'; $notice['pay_time'] = strtotime($params['time_end']); $notice['notify_time'] = strtotime($params['time_end']); $notice['amount'] = $params['total_fee']; //订单金额 $notice['bank_id'] = $params['bank_type']; //银行类型 //$notice['attach'] = $params['attach'] ; //商家数据包 } } else { $notify->setReturnParameter("return_code", "FAIL"); //返回状态码 $notify->setReturnParameter("return_msg", "签名错误"); //返回信息 } $notice['output'] = $notify->returnXml(); //给第三方显示 return $notice; }
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; }
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()); } } }
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_(); $log_name = __ROOT__ . "/Public/Weixin/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"); } //商户自行增加处理流程, //例如:更新订单状态 //例如:数据库操作 //例如:推送支付完成信息 } }
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; // ==商户根据实际情况设置相应的处理流程,此处仅作举例======= 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('Home/Payments'); // 商户订单号 $obj = array(); $obj["trade_no"] = $trade_no; $obj["out_trade_no"] = $out_trade_no; $obj["total_fee"] = $total_fee; $obj["userId"] = $userId; // 支付成功业务逻辑 $payments = $pm->complatePay($obj); S("{$out_trade_no}", $total_fee); } } }
function notify() { include_once "wxpay/WxPayPubHelper/WxPayPubHelper.php"; //使用通用通知接口 $notify = new Notify_pub(); //存储微信的回调 $xml = $GLOBALS['HTTP_RAW_POST_DATA']; $this->test("1xml", $xml); $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; $this->test("1returnXml", $returnXml); //==商户根据实际情况设置相应的处理流程,此处仅作举例======= if ($notify->checkSign() == TRUE) { if ($notify->data["return_code"] == "FAIL") { } elseif ($notify->data["result_code"] == "FAIL") { } else { //此处应该更新一下订单状态,商户自行增删操作 $objxml = simplexml_load_string($xml, 'SimpleXMLElement', LIBXML_NOCDATA); $html .= "&transaction_id=" . $objxml->transaction_id . "&out_trade_no=" . $objxml->out_trade_no; $url = "http://www.gzsrex.com/index.php?g=Api&m=Pay&a=wxpayok" . $html; $this->test("1url", $url); Header("Location: {$url}"); } //商户自行增加处理流程, //例如:更新订单状态 //例如:数据库操作 //例如:推送支付完成信息 } }
public function notify_wechat() { //使用通用通知接口 $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"); //设置返回码 } $returnXml = $notify->returnXml(); echo $returnXml; //==商户根据实际情况设置相应的处理流程,此处仅作举例======= //以log文件形式记录回调信息 $log_ = new Log_(); $log_name = $this->config->item('log_path') . "wechat_notify.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"); } elseif ($notify->data["result_code"] == "FAIL") { //此处应该更新一下订单状态,商户自行增删操作 $log_->log_result($log_name, "【业务出错】:\n" . $xml . "\n"); } else { //此处应该更新一下订单状态,商户自行增删操作 } //商户自行增加处理流程, //例如:更新订单状态 //例如:数据库操作 //例如:推送支付完成信息 if (!isset($notify->data["out_trade_no"])) { $log_->log_result($log_name, "【serial number required】:\n"); exit('order id required'); } $this->load->model('order_model', 'order'); if (!isset($notify->data["attach"])) { $log_->log_result($log_name, "【attach required】:\n"); exit('attach required'); } $attach = explode('-', $notify->data['attach']); $order_id = $attach[0]; $cur_stage = $attach[1] + 1; $log_->log_result($log_name, "order_id:" . $order_id); $ret = $this->order->update_order_stage($order_id, $cur_stage); if (!$ret) { $log_->log_result($log_name, "update order status fail:ret:" . $ret . "\n"); } else { $log_->log_result($log_name, "update order status succ\n"); } } else { $log_->log_result($log_name, "checkSign fail\n"); } }
/** * 处理成功返回 */ public function notifySuccess() { $notify = new Notify_pub(); $notify->setReturnParameter("return_code", "SUCCESS"); //设置返回码 $notify->setReturnParameter("return_msg", "处理成功"); //返回信息 return $notify->returnXml(); }
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"); } //商户自行增加处理流程, //例如:更新订单状态 //例如:数据库操作 //例如:推送支付完成信息 } }
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_(); $log_name = "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"); $info = $notify->xmlToarray($xml); $notice_sn = $info['out_trade_no']; $order_info['out_notice_sn'] = $info['transaction_id']; $order_info['is_paid'] = 1; $order_info['pay_time'] = get_gmtime(); $order = M("order"); $order_info1 = $order->where("notice_sn={$notice_sn}")->select(); if ($order_info1['is_paid'] == 1) { exit; } else { $pay_time1 = $order->where("notice_sn={$notice_sn}")->getField('pay_time'); if ($pay_time1 == 0) { $result = $order->where("notice_sn={$notice_sn}")->save($order_info); // 根据条件更新记录 } if (false !== $result && isset($result)) { $number = $order->where("notice_sn={$notice_sn} AND is_paid =1")->getField('number'); $goods_id = $order->where("notice_sn={$notice_sn} AND is_paid =1")->getField('goods_id'); M("goods")->where("id={$goods_id}")->setInc('pay_number', $number); $pay_number = M("goods")->where("id={$goods_id}")->getField('pay_number'); $total_number = M("goods")->where("id={$goods_id}")->getField('number'); if ($pay_number >= $total_number) { $goods['type'] = 2; $goods['end_time'] = get_gmtime(); M("goods")->where("id={$goods_id}")->save($goods); // 根据条件更新记录 } $unique = M("unique"); $total_lucky_number = $unique->where("goods_id={$goods_id}")->getField('lucky_number'); $total_lucky_number = unserialize($total_lucky_number); $lucky_number = array_slice($total_lucky_number, 0, $number); $rem_lucky_number = array_slice($total_lucky_number, $number); $lucky_number1['lucky_number'] = serialize($lucky_number); $rem_lucky_number1['lucky_number'] = serialize($rem_lucky_number); M("unique")->where("goods_id={$goods_id}")->save($rem_lucky_number1); $order->where("notice_sn={$notice_sn}")->save($lucky_number1); } } } } }
/** * 支付完成回调通知 */ public function notice() { require_once W_LIBRARY_PATH . '/wx/pay/WxPayPubHelper/WxPayPubHelper.php'; //使用通用通知接口 $notify = new \Notify_pub(); //存储微信的回调 $xml = $GLOBALS['HTTP_RAW_POST_DATA']; // 记录日志 log_message($xml); $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文件形式记录回调信息 if ($notify->checkSign() == TRUE) { if ($notify->data["return_code"] == "FAIL") { //此处应该更新一下订单状态,商户自行增删操作 log_message("【通信出错】:\n" . $xml . "\n"); } elseif ($notify->data["result_code"] == "FAIL") { //此处应该更新一下订单状态,商户自行增删操作 log_message("【业务出错】:\n" . $xml . "\n"); } else { //此处应该更新一下订单状态,商户自行增删操作 log_message("【支付成功】:\n" . $xml . "\n"); $row = \Db\Trade\Order::row(array('order_id' => $notify->data['out_trade_no'], 'pay_status' => 0)); if (!empty($row)) { $row->mch_id = $notify->data['mch_id']; $row->trade_type = $notify->data['trade_type']; $row->transaction_id = $notify->data['transaction_id']; $row->bank_type = $notify->data['bank_type']; $row->mch_id = $notify->data['mch_id']; $row->pay_status = 1; $row->order_status = 1; $row->fee_type = $notify->data['fee_type']; $row->pay_time = W_START_TIME; $row->update(); } } } }
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'); //云购商品 }
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); } } }
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); } //商户自行增加处理流程, //例如:更新订单状态 //例如:数据库操作 //例如:推送支付完成信息 } }
$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) { /* $notify = new Notify_pub(); $xml = '<xml><appid><![CDATA[wx6b841dfdf70941ae]]></appid> <bank_type><![CDATA[ICBC_DEBIT]]></bank_type> <fee_type><![CDATA[CNY]]></fee_type> <is_subscribe><![CDATA[Y]]></is_subscribe> <mch_id><![CDATA[10018540]]></mch_id>
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(); } } }
/** * 接受通知处理订单。 * @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"); } } }
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); //【支付成功】 } //商户自行增加处理流程, //例如:更新订单状态 //例如:数据库操作 //例如:推送支付完成信息 } else { $code = array('state' => -3, 'xml' => $notify->data); } return $code; }