notify.php 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. <?php
  2. ini_set('date.timezone','Asia/Shanghai');
  3. error_reporting(E_ERROR);
  4. require_once dirname(__FILE__)."/../lib/WxPay.Api.php";
  5. require_once dirname(__FILE__).'/../lib/WxPay.Notify.php';
  6. require_once 'log.php';
  7. //初始化日志
  8. $logHandler= new CLogFileHandler("../logs/".date('Y-m-d').'.log');
  9. $log = Log::Init($logHandler, 15);
  10. class PayNotifyCallBack extends WxPayNotify
  11. {
  12. //查询订单
  13. public function Queryorder($transaction_id)
  14. {
  15. $input = new WxPayOrderQuery();
  16. //$input->SetTransaction_id($transaction_id);
  17. $input->SetOut_trade_no($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. return $result;
  27. }
  28. //return false;
  29. return $result;
  30. }
  31. //重写回调处理函数
  32. public function NotifyProcess($data, &$msg)
  33. {
  34. Log::DEBUG("call back:" . json_encode($data));
  35. $notfiyOutput = array();
  36. if(!array_key_exists("transaction_id", $data)){
  37. $msg = "输入参数不正确";
  38. return false;
  39. }
  40. //查询订单,判断订单真实性
  41. if(!$this->Queryorder($data["transaction_id"])){
  42. $msg = "订单查询失败";
  43. return false;
  44. }
  45. return true;
  46. }
  47. }
  48. Log::DEBUG("begin notify");
  49. $orderid = $_GET['orderid'];
  50. $notify = new PayNotifyCallBack();
  51. //echo json_encode($notify->Queryorder($orderid));
  52. $notify->Handle(false);