<?php /** * 标记客户的投诉处理状态 * @author www.linauror.com * @copyright 2014 */ include 'config.php'; include 'lib.php'; $wechat = new Wechat(); $data = $wechat->getXmlArray(); // 具体参数可以查看文档 // openid 与 feedback参数都可以从数据库中得到 $result = file_get_contents('http://api.weixin.qq.com/cgi-bin/pay/delivernotify?access_token=' . $wechat->getAccessToken() . '&openid=' . $openid . '&feedbackid=' . $feedbackid); $result = json_decode($result, true); if ($result['errcode'] == 0) { echo 'success'; } else { print_r($result); }
<?php define('IN_ECS', true); require '../includes/init.php'; require '../includes/lib_order.php'; include_once '../includes/lib_payment.php'; //获取post数据 include_once '../includes/modules/payment/Wechat.php'; $wechat = new Wechat(); $post = $wechat->getXmlArray(); addLog($post, 6); $oid = intval($post['productid']); $order = $db->getRow("SELECT * FROM " . $GLOBALS['ecs']->table('order_info') . " WHERE order_id = {$oid}"); //if($order['pay_status'] == 2) exit('is payed'); if ($order['order_amount'] > 0) { $payment = payment_info($order['pay_id']); include_once '../includes/modules/payment/' . $payment['pay_code'] . '.php'; $pay_obj = new $payment['pay_code'](); $payment = unserialize_config($payment['pay_config']); if ($post['appid'] == $payment['appId']) { define(APPID, $payment['appId']); define(APPKEY, $payment['paySignKey']); define(SIGNTYPE, "sha1"); define(PARTNERKEY, $payment['partnerKey']); define(APPSERCERT, $payment['appSecret']); include_once "../includes/modules/payment/weixin/WxPayHelper.php"; $wxPayHelper = new WxPayHelper(); $url = return_url('weixin'); $wxPayHelper->setParameter("bank_type", "WX"); $wxPayHelper->setParameter("body", $order['order_sn']); $wxPayHelper->setParameter("partner", $payment['partnerId']);
// 官方文档所说的post是接收不到参数的,实际上要用get才行 // 写入文件 $filename = 'notify_back_before.txt'; $fh = fopen($filename, "w"); fwrite($fh, "异步通知:\r\n"); foreach ($array as $key => $value) { fwrite($fh, $key . "=" . $value . "&"); } fwrite($fh, "\r\n\r\n"); //关闭文件 fclose($fh); //$verifyNotify = $wechat->verifyNotify($array, $config); // 验证通知 //if ($verifyNotify) { if ($array['trade_state'] == 0) { //成功支付 $array += $wechat->getXmlArray(); // 再获取xml数据 // 结果已经获取到了 下面可以更新数据库支付状态等操作了 也可以使用订单查询接口来查询是否支付成功 // 写入文件 $filename = 'notify_back_after.txt'; $fh = fopen($filename, "w"); fwrite($fh, "异步通知:\r\n"); foreach ($array as $key => $value) { fwrite($fh, $key . "=" . $value . "&"); } fwrite($fh, "\r\n\r\n"); //关闭文件 fclose($fh); $mysqli = new mysqli($arr["DB_HOST"], $arr["DB_USER"], $arr["DB_PWD"], $arr["DB_NAME"], $arr["DB_PORT"]); //记录支付日志 $query = "insert into " . $arr["DB_PREFIX"] . "wxpay_history(`sign_type`,`service_version`,`input_charset`," . "`sign`,`sign_key_index`,`trade_mode`,`trade_state`,`pay_info`,`partner`,`bank_type`,`bank_billno`," . "`total_fee`,`fee_type`,`notify_id`,`transaction_id`,`out_trade_no`,`attach`,`time_end`,`transport_fee`," . "`product_fee`,`discount`,`buyer_alias`,`openid`,`appid`,`issubscribe`,`timestamp`,`noncestr`,`appsignature`,`signmethod`)" . " values ( '" . $array['sign_type'] . "', '" . $array['service_version'] . "', '" . $array['input_charset'] . "', '" . $array['sign'] . "', '" . $array['sign_key_index'] . "', '" . $array['trade_mode'] . "', '" . $array['trade_state'] . "', '" . $array['pay_info'] . "', '" . $array['partner'] . "', '" . $array['bank_type'] . "', '" . $array['bank_billno'] . "', '" . $array['total_fee'] . "', '" . $array['fee_type'] . "', '" . $array['notify_id'] . "', '" . $array['transaction_id'] . "', '" . $array['out_trade_no'] . "', '" . $array['attach'] . "', '" . $array['time_end'] . "', '" . $array['transport_fee'] . "', '" . $array['product_fee'] . "', '" . $array['discount'] . "', '" . $array['buyer_alias'] . "', '" . $array['openid'] . "', '" . $array['appid'] . "', '" . $array['issubscribe'] . "', '" . $array['timestamp'] . "', '" . $array['noncestr'] . "', '" . $array['appsignature'] . "', '" . $array['signmethod'] . "')";
$partnerkey = strval($row['partnerkey']); $signkey = strval($row['signkey']); $partner = strval($row['partnerid']); $config = array('appId' => $appid, 'appSecret' => $secret, 'paySignKey' => $signkey, 'partnerId' => $partner, 'partnerKey' => $partnerkey); $wechat = new Wechat(); $array2 = $_GET; /*$strget="get:"; foreach ($array2 as $k2 => $v2) { $strget.= $k2."=".$v2."&"; } $wechat->log_result($strget); */ $verifyNotify = $array2['notify_id']; //验证通知 if ($verifyNotify) { $array2['xml'] = $wechat->getXmlArray(); //获取xml数据 //$array += $wechat->getXmlArray(); // 再获取xml数据 //$array2 += $wechat->getXmlArray(); // 再获取xml数据 $wxorder = serialize($array2); // 结果已经获取到了 下面可以更新数据库支付状态等操作了 也可以使用订单查询接口来查询是否支付成功 //$wechat->log_result($array); $out_trade_no = $array2['out_trade_no']; //商户订单号 // echo $out_trade_no;exit; // $notify_id= $array['notify_id'];//通知id $trade_state = $array2['trade_state']; //交易状态 if ($trade_state == 0) { $sql = "update " . $arr['DB_PREFIX'] . "item_order set status=2,support_time=" . time() . ",paytype='wxpay' where orderId='" . $out_trade_no . "'"; mysql_query($sql, $conn);