|
- <?php
- ini_set('date.timezone', 'Asia/Shanghai');
- error_reporting(E_ERROR);
- require_once "/usr/share/nginx/XMWX/wechat/WxPay/lib/WxPay.Api.php";
- require_once 'log.php';
- require_once '/usr/share/nginx/XMWX/wechat/Common_fx/Mysql.php';
- //初始化日志
- $logHandler = new CLogFileHandler("../logs/" . date('Y-m-d') . '.log');
- $log = Log::Init($logHandler, 15);
-
- function printf_info($data)
- {
- foreach ($data as $key => $value) {
- echo "<font color='#f00;'>$key</font> : $value <br/>";
- }
- }
- //链接数据库查询需要退款的订单信息
- $pdo = conn();
- $sql = "select * from order_refund where yet = 0 and PAY_SERIAL_NUMBER<>''"; //PAY_SERIAL_NUMBER:支付串号(商户单号)
- $rs = $pdo->query($sql);
- $rowset = $rs->fetchAll(PDO::FETCH_ASSOC);
- foreach ($rowset as $v) {
- $list[] = $v;
- }
- //遍历全部订单并退款 此为全额退款 金额不同会退款失败
- foreach ($list as $v) {
- $out_trade_no = (string)$v['PAY_SERIAL_NUMBER'];
- $total_fee = (string)$v['price'] * 100;
- $refund_fee = (string)$v['price'] * 100;
-
- $input = new WxPayRefund();
- $input->SetOut_trade_no($out_trade_no);
- $input->SetTotal_fee($total_fee);
- $input->SetRefund_fee($refund_fee);
- $input->SetOut_refund_no(WxPayConfig::MCHID . date("YmdHis"));
- $input->SetOp_user_id(WxPayConfig::MCHID);
- $rs = WxPayApi::refund($input);
- //退款给成功后设置退款状态位
- if (!isset($rs['err_code'])) {
- $sql = "update order_refund set yet = 1 where order_id =" . $v['order_id'];
- $rs2 = $pdo->exec($sql);
- $info = serialize($rs);//$out_trade_no.'success\n';
- } else {
- $info = $out_trade_no . 'error:' . $rs['err_code'] . '\n';
- }
- success_notify($info);
- echo $info;
- }
-
-
- function success_notify($result)
- {
- file_put_contents('./refund_wechat.txt', date("Y-m-d H:i:s") . " " . $result . PHP_EOL, FILE_APPEND);//订单成功后通知后台日志
- }
|