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.
 
 
 
 
 

67 lines
1.9 KiB

  1. <?php
  2. ini_set('date.timezone','Asia/Shanghai');
  3. require_once "../lib/WxPay.Api.php";
  4. require_once '../lib/WxPay.Notify.php';
  5. require_once 'log.php';
  6. require_once '../../Common/Config.php';
  7. require_once '../../Common/Function.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. if (!empty($postStr)){
  48. libxml_disable_entity_loader(true);
  49. $dataArray= (array)simplexml_load_string($postStr, 'SimpleXMLElement', LIBXML_NOCDATA);
  50. foreach ($dataArray as $key=>$v){
  51. success_notify($key."--".$v);
  52. }
  53. $orderno=$dataArray['out_trade_no'];
  54. $url="http://xmwxc.zhizhuchuxing.cn/core/order_confirm2.asp?orderno=".$orderno;
  55. $result=http_request($url);
  56. success_notify($url."--".$result.'--'.json_encode($result));
  57. }
  58. success_notify(json_encode($postStr));
  59. function success_notify($result){
  60. file_put_contents('./success_notify.txt', date("Y-m-d H:i:s")." ".$result.PHP_EOL,FILE_APPEND);//订单成功后通知后台日志
  61. }