You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

61 lines
1.6 KiB

  1. <?php
  2. ini_set('date.timezone','Asia/Shanghai');
  3. error_reporting(E_ERROR);
  4. require_once "../lib/WxPay.Api.php";
  5. require_once '../lib/WxPay.Notify.php';
  6. require_once 'log.php';
  7. require_once '../../Common/Config.php';
  8. //初始化日志
  9. $logHandler= new CLogFileHandler("../logs/".date('Y-m-d').'.log');
  10. $log = Log::Init($logHandler, 15);
  11. class PayNotifyCallBack extends WxPayNotify
  12. {
  13. //查询订单
  14. public function Queryorder($transaction_id)
  15. {
  16. $input = new WxPayOrderQuery();
  17. $input->SetTransaction_id($transaction_id);
  18. $result = WxPayApi::orderQuery($input);
  19. Log::DEBUG("query:" . json_encode($result));
  20. if(array_key_exists("return_code", $result)
  21. && array_key_exists("result_code", $result)
  22. && $result["return_code"] == "SUCCESS"
  23. && $result["result_code"] == "SUCCESS")
  24. {
  25. return true;
  26. }
  27. return false;
  28. }
  29. //重写回调处理函数
  30. public function NotifyProcess($data, &$msg)
  31. {
  32. Log::DEBUG("call back:" . json_encode($data));
  33. $notfiyOutput = array();
  34. if(!array_key_exists("transaction_id", $data)){
  35. $msg = "输入参数不正确";
  36. return false;
  37. }
  38. //查询订单,判断订单真实性
  39. if(!$this->Queryorder($data["transaction_id"])){
  40. $msg = "订单查询失败";
  41. return false;
  42. }
  43. return true;
  44. }
  45. }
  46. $postStr = file_get_contents("php://input");
  47. success_notify(json_encode($postStr));
  48. $result=json_encode($_POST).json_encode($_GET);
  49. success_notify($result);
  50. Log::DEBUG("begin notify");
  51. $notify = new PayNotifyCallBack();
  52. $notify->Handle(false);
  53. function success_notify($result){
  54. file_put_contents('./success_notify.txt', date("Y-m-d H:i:s")." ".$result.PHP_EOL,FILE_APPEND);//订单成功后通知后台日志
  55. }