Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.
 
 
 
 
 

55 righe
1.9 KiB

  1. <?php
  2. ini_set('date.timezone', 'Asia/Shanghai');
  3. error_reporting(E_ERROR);
  4. require_once "/usr/share/nginx/XMWX/wechat/WxPay/lib/WxPay.Api.php";
  5. require_once 'log.php';
  6. require_once '/usr/share/nginx/XMWX/wechat/Common_fx/Mysql.php';
  7. //初始化日志
  8. $logHandler = new CLogFileHandler("../logs/" . date('Y-m-d') . '.log');
  9. $log = Log::Init($logHandler, 15);
  10. function printf_info($data)
  11. {
  12. foreach ($data as $key => $value) {
  13. echo "<font color='#f00;'>$key</font> : $value <br/>";
  14. }
  15. }
  16. //链接数据库查询需要退款的订单信息
  17. $pdo = conn();
  18. $sql = "select * from order_refund where yet = 0 and PAY_SERIAL_NUMBER<>''"; //PAY_SERIAL_NUMBER:支付串号(商户单号)
  19. $rs = $pdo->query($sql);
  20. $rowset = $rs->fetchAll(PDO::FETCH_ASSOC);
  21. foreach ($rowset as $v) {
  22. $list[] = $v;
  23. }
  24. //遍历全部订单并退款 此为全额退款 金额不同会退款失败
  25. foreach ($list as $v) {
  26. $out_trade_no = (string)$v['PAY_SERIAL_NUMBER'];
  27. $total_fee = (string)$v['price'] * 100;
  28. $refund_fee = (string)$v['price'] * 100;
  29. $input = new WxPayRefund();
  30. $input->SetOut_trade_no($out_trade_no);
  31. $input->SetTotal_fee($total_fee);
  32. $input->SetRefund_fee($refund_fee);
  33. $input->SetOut_refund_no(WxPayConfig::MCHID . date("YmdHis"));
  34. $input->SetOp_user_id(WxPayConfig::MCHID);
  35. $rs = WxPayApi::refund($input);
  36. //退款给成功后设置退款状态位
  37. if (!isset($rs['err_code'])) {
  38. $sql = "update order_refund set yet = 1 where order_id =" . $v['order_id'];
  39. $rs2 = $pdo->exec($sql);
  40. $info = serialize($rs);//$out_trade_no.'success\n';
  41. } else {
  42. $info = $out_trade_no . 'error:' . $rs['err_code'] . '\n';
  43. }
  44. success_notify($info);
  45. echo $info;
  46. }
  47. function success_notify($result)
  48. {
  49. file_put_contents('./refund_wechat.txt', date("Y-m-d H:i:s") . " " . $result . PHP_EOL, FILE_APPEND);//订单成功后通知后台日志
  50. }