notify_url.php 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. <?php
  2. /**
  3. * 通用通知接口demo
  4. * ====================================================
  5. * 支付完成后,微信会把相关支付和用户信息发送到商户设定的通知URL,
  6. * 商户接收回调信息后,根据需要设定相应的处理流程。
  7. *
  8. * 这里举例使用log文件形式记录回调信息。
  9. */
  10. include_once("lib/log_.php");
  11. include_once("lib/WxPayPubHelper.php");
  12. //使用通用通知接口
  13. $notify = new Notify_pub();
  14. //存储微信的回调
  15. $xml = $GLOBALS['HTTP_RAW_POST_DATA'];
  16. $notify->saveData($xml);
  17. //验证签名,并回应微信。
  18. //对后台通知交互时,如果微信收到商户的应答不是成功或超时,微信认为通知失败,
  19. //微信会通过一定的策略(如30分钟共8次)定期重新发起通知,
  20. //尽可能提高通知的成功率,但微信不保证通知最终能成功。
  21. if($notify->checkSign() == FALSE){
  22. $notify->setReturnParameter("return_code","FAIL");//返回状态码
  23. $notify->setReturnParameter("return_msg","签名失败");//返回信息
  24. }else{
  25. $notify->setReturnParameter("return_code","SUCCESS");//设置返回码
  26. }
  27. $returnXml = $notify->returnXml();
  28. echo $returnXml;
  29. //==商户根据实际情况设置相应的处理流程,此处仅作举例=======
  30. //以log文件形式记录回调信息
  31. $log_ = new Log_();
  32. $log_name="./notify_url.log";//log文件路径
  33. $log_->log_result($log_name,"【接收到的notify通知】:\n".$xml."\n");
  34. if($notify->checkSign() == TRUE)
  35. {
  36. if ($notify->data["return_code"] == "FAIL") {
  37. //此处应该更新一下订单状态,商户自行增删操作
  38. $log_->log_result($log_name,"【通信出错】:\n".$xml."\n");
  39. }
  40. elseif($notify->data["result_code"] == "FAIL"){
  41. //此处应该更新一下订单状态,商户自行增删操作
  42. $log_->log_result($log_name,"【业务出错】:\n".$xml."\n");
  43. }
  44. else{
  45. //此处应该更新一下订单状态,商户自行增删操作
  46. $log_->log_result($log_name,"【支付成功】:\n".$xml."\n");
  47. }
  48. //商户自行增加处理流程,
  49. //例如:更新订单状态
  50. //例如:数据库操作
  51. //例如:推送支付完成信息
  52. $_GET['act'] = 'payment';
  53. $_GET['op'] = 'wxpayreturn';
  54. $_GET['payment_code']='wxpay';
  55. $_GET['result_code'] = $notify->data["result_code"];
  56. $_GET['out_trade_no'] = $notify->data["out_trade_no"];
  57. $_GET['transaction_id'] = $notify->data["transaction_id"];
  58. require_once(dirname(__FILE__).'/../../../index.php');
  59. }
  60. ?>