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 execute($md5Key, $desKey, $resp) { $log_ = new Log_(); // 获取通知原始信息 //$log_->log_result("异步通知原始数据:" . $resp); if (null == $resp) { return; } // 获取配置密钥 $log_->log_result("desKey:" . $desKey); $log_->log_result("md5Key:" . $md5Key); // 解析XML $params = $this->xml_to_array(base64_decode($resp)); $ownSign = $this->generateSign($params, $md5Key); $params_json = json_encode($params); $log_->log_result("解析XML得到对象:" . $params_json); $log_->log_result("根据传输数据生成的签名:" . $ownSign); if ($params['SIGN'][0] == $ownSign) { // 验签不对 $log_->log_result("签名验证正确!"); } else { $log_->log_result("签名验证错误!"); return; } // 验签成功,业务处理 // 对Data数据进行解密 $des = new DesUtils(); // (秘钥向量,混淆向量) $decryptArr = $des->decrypt($params['DATA'][0], $desKey); // 加密字符串 $log_->log_result("对<DATA>进行解密得到的数据:" . $decryptArr); $params['data'] = $decryptArr; $log_->log_result("最终数据:" . json_encode($params)); $log_->log_result("**********接收异步通知结束。**********\n\n"); return 200; }
//微信会通过一定的策略(如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> <nonce_str><![CDATA[4p5ama9d2jrjgwmutiw7qcm69ru5l3zx]]></nonce_str> <openid><![CDATA[oW7Z1tyBJECU23nL4RwBjJxdI0xE]]></openid> <out_trade_no><![CDATA[130]]></out_trade_no> <result_code><![CDATA[SUCCESS]]></result_code>
<?php /** * 通用通知接口demo * ==================================================== * 支付完成后,微信会把相关支付和用户信息发送到商户设定的通知URL, * 商户接收回调信息后,根据需要设定相应的处理流程。 * * 这里举例使用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");
public function zfalipay_notify_url() { include_once APP_PATH . 'Lib/ORG/Weixinpay2/Log_.php'; $log_ = new Log_(); $log_name = APP_PATH . "./../data/zfalipay_notify_url-" . date('Y-m-d', time()) . ".log"; //log文件路径 $log_->log_result($log_name, "【接收到的notify通知】:\r\n" . var_export($_POST, true) . "\r\n"); import("@.ORG.Alipay.AlipayNotify"); $alipay_config = $this->zfalipay_config; $alipayNotify = new AlipayNotify($alipay_config); $verify_result = $alipayNotify->verifyNotify(); if ($verify_result) { //验证成功 $trade_status = $_POST['trade_status']; //交易状态 $out_trade_no = $_POST['out_trade_no']; //商户订单号 $trade_no = $_POST['trade_no']; //支付宝交易号 $trade_status = $_POST['trade_status']; //交易状态 $total_fee = $_POST['total_fee']; //交易金额 $order = $this->order_db->where(array('orderid' => $out_trade_no))->find(); if ($trade_status == 'TRADE_FINISHED' || $trade_status == 'TRADE_SUCCESS') { if ($order['paid'] == 0) { $data['paid'] = 1; $data['payment'] = 'zfalipay'; $this->order_db->where(array('orderid' => $out_trade_no))->save($data); $this->order_db->where(array('orderid' => $out_trade_no))->setField('paid', 1); } echo "success"; } } }
//微信会通过一定的策略(如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"); } elseif ($notify->data["result_code"] == "FAIL") { //此处应该更新一下订单状态,商户自行增删操作 $log_->log_result($log_name, "【业务出错】:\n" . $xml . "\n"); } else { //此处应该更新一下订单状态,商户自行增删操作 $log_->log_result($log_name, "【支付成功】:\n" . $xml . "\n"); } //商户自行增加处理流程,
/** * JS_API支付demo * ==================================================== * 在微信浏览器里面打开H5网页中执行JS调起支付。接口输入输出数据格式为JSON。 * 成功调起支付需要三个步骤: * 步骤1:网页授权获取用户openid * 步骤2:使用统一支付接口,获取prepay_id * 步骤3:使用jsapi调起支付 */ include_once "lib/log_.php"; include_once "lib/WxPayPubHelper.php"; //使用jsapi接口 $jsApi = new JsApi_pub(); //以log文件形式记录回调信息 $log_ = new Log_(); $log_name = "./notify_url.log"; //log文件路径 @($pay_sn = $_GET['pay_sn']); @($pay_amount = $_GET['pay_amount']); /* $log_->log_result($log_name,"【get pay_sn】:\n".$pay_sn."\n"); $log_->log_result($log_name,"【get pay_amount】:\n".$pay_amount."\n"); if(!isset($_COOKIE['pay_sn'])||!isset($_COOKIE['pay_amount'])) { $expire = time() + 86400; // 设置24小时的有效期 setcookie ("pay_sn", $pay_sn, $expire); // 设置一个名字为var_name的cookie,并制定了有效期 setcookie ("pay_amount", $pay_amount, $expire); // 再将过期时间设置进cookie以便你能够知道var_name的过期时间 $pay_sn = $_COOKIE['pay_sn']; $pay_amount = $_COOKIE['pay_amount']; }
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"); } }
/** * Native(原生)支付模式一demo * ==================================================== * 模式一:商户按固定格式生成链接二维码,用户扫码后调微信 * 会将productid和用户openid发送到商户设置的链接上,商户收到 * 请求生成订单,调用统一支付接口下单提交到微信,微信会返回 * 给商户prepayid。 * 本例程对应的二维码由native_call_qrcode.php生成; * 本例程对应的响应服务为native_call.php; * 需要两者配合使用。 * */ include_once "./log_.php"; include_once "./WxPayHelper/WxPayHelper.php"; //以log文件形式记录回调信息,用于调试 $log_ = new Log_(); $log_name = "./logs/native_call.log"; //使用native通知接口 $nativeCall = new NativeCall(); //接收微信请求 $xml = $GLOBALS['HTTP_RAW_POST_DATA']; $log_->log_result($log_name, "【接收到的native通知】:\n" . $xml . "\n"); $nativeCall->saveData($xml); if ($nativeCall->checkSign() == FALSE) { $nativeCall->setReturnParameter("return_code", "FAIL"); //返回状态码 $nativeCall->setReturnParameter("return_msg", "签名失败"); //返回信息 } else { //提取product_id $product_id = $nativeCall->getProductId();
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; } }
//对后台通知交互时,如果微信收到商户的应答不是成功或超时,微信认为通知失败, //微信会通过一定的策略(如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文件形式记录回调信息 $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"); } elseif ($notify->data["result_code"] == "FAIL") { //此处应该更新一下订单状态,商户自行增删操作 $log_->log_result($log_name, "【业务出错】:\n" . $xml . "\n"); } else { //此处应该更新一下订单状态,商户自行增删操作 $log_->log_result($log_name, "【支付成功】:\n" . $xml . "\n"); } // ($notify->data["out_trade_no"], '17',$notify->data["transaction_id"]);
public function notify($payid) { //以log文件形式记录回调信息,用于调试 $log_ = new \Log_(); $time = date('Ymd', time()); $log_name = './logs/pay/' . $time . "native_call.log"; //使用native通知接口 $nativeCall = new \NativeCall_pub(); //接收微信请求 $xml = $GLOBALS['HTTP_RAW_POST_DATA']; $log_->log_result($log_name, "【接收到的native通知】:\n" . $xml . "\n"); $nativeCall->saveData($xml); if ($nativeCall->checkSign() == FALSE) { $nativeCall->setReturnParameter("return_code", "FAIL"); //返回状态码 $nativeCall->setReturnParameter("return_msg", "签名失败"); //返回信息 } else { //提取product_id $product_id = $nativeCall->getProductId(); //使用统一支付接口 $unifiedOrder = new \UnifiedOrder_pub(); //根据不同的$product_id设定对应的下单参数,此处只举例一种 switch ($product_id) { case WxPayConf_pub::APPID . "static": //与native_call_qrcode.php中的静态链接二维码对应 $unifiedOrder->setParameter("body", "贡献一分钱"); //商品描述 //自定义订单号,此处仅作举例 $timeStamp = time(); $out_trade_no = WxPayConf_pub::APPID . "{$timeStamp}"; $unifiedOrder->setParameter("out_trade_no", "{$out_trade_no}"); //商户订单号 $unifiedOrder->setParameter("product_id","$product_id");//商品ID $unifiedOrder->setParameter("total_fee", "1"); //总金额 $unifiedOrder->setParameter("notify_url", WxPayConf_pub::NOTIFY_URL); //通知地址 $unifiedOrder->setParameter("trade_type", "NATIVE"); //交易类型 $unifiedOrder->setParameter("product_id", "{$product_id}"); //用户标识 $unifiedOrder->setParameter("attach", "{$payid}"); //附加数据 订单ID //获取prepay_id $prepay_id = $unifiedOrder->getPrepayId(); $nativeCall->setReturnParameter("return_code", "SUCCESS"); //返回状态码 $nativeCall->setReturnParameter("result_code", "SUCCESS"); //业务结果 $nativeCall->setReturnParameter("prepay_id", "{$prepay_id}"); //预支付ID break; default: //设置返回码 //设置必填参数 //appid已填,商户无需重复填写 //mch_id已填,商户无需重复填写 //noncestr已填,商户无需重复填写 //sign已填,商户无需重复填写 $nativeCall->setReturnParameter("return_code", "SUCCESS"); //返回状态码 $nativeCall->setReturnParameter("result_code", "FAIL"); //业务结果 $nativeCall->setReturnParameter("err_code_des", "此商品无效"); //业务结果 break; } } //将结果返回微信 $returnXml = $nativeCall->returnXml(); $log_->log_result($log_name, "【返回微信的native响应】:\n" . $returnXml . "\n"); exit($returnXml); //交易完成 }
//微信会通过一定的策略(如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"); } elseif ($notify->data["result_code"] == "FAIL") { //此处应该更新一下订单状态,商户自行增删操作 //$log_->log_result($log_name,"【业务出错】:\n".$xml."\n"); } else { //此处应该更新一下订单状态,商户自行增删操作 //$log_->log_result($log_name,"【支付成功】:\n".$xml."\n"); } //商户自行增加处理流程,
/** * Native(原生)支付模式一demo * ==================================================== * 模式一:商户按固定格式生成链接二维码,用户扫码后调微信 * 会将productid和用户openid发送到商户设置的链接上,商户收到 * 请求生成订单,调用统一支付接口下单提交到微信,微信会返回 * 给商户prepayid。 * 本例程对应的二维码由native_call_qrcode.php生成; * 本例程对应的响应服务为native_call.php; * 需要两者配合使用。 * */ include_once "./log_.php"; include_once "../WxPayPubHelper/WxPayPubHelper.php"; //以log文件形式记录回调信息,用于调试 $log_ = new Log_(); $log_name = "./native_call.log"; //使用native通知接口 $nativeCall = new NativeCall_pub(); //接收微信请求 $xml = $GLOBALS['HTTP_RAW_POST_DATA']; $log_->log_result($log_name, "【接收到的native通知】:\n" . $xml . "\n"); $nativeCall->saveData($xml); if ($nativeCall->checkSign() == FALSE) { $nativeCall->setReturnParameter("return_code", "FAIL"); //返回状态码 $nativeCall->setReturnParameter("return_msg", "签名失败"); //返回信息 } else { //提取product_id $product_id = $nativeCall->getProductId();
/** * 接受通知处理订单。 * @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"); } } }
/** * 获取prepay_id */ function getPrepayId() { //以log文件形式记录回调信息 $log_ = new Log_(); $log_name = "./notify_url.log"; //log文件路径 $this->postXml(); $this->result = $this->xmlToArray($this->response); $log_->log_result($log_name, "【接收到的notify通知】:\n" . $this->response . "\n"); $prepay_id = $this->result["prepay_id"]; $log_->log_result($log_name, "【接收到的notify通知】:\n" . $prepay_id . "\n"); return $prepay_id; }