wsq_pay_notify.inc.php 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. <?php
  2. if(function_exists('file_get_contents')){
  3. $postStr = file_get_contents("php://input");
  4. }else{
  5. $postStr = $GLOBALS["HTTP_RAW_POST_DATA"];
  6. }
  7. //调试记录开始
  8. $notifydatastr = print_r($notifydata,true)."----------2---------notifydata \r\n";
  9. $notifydatastr = $notifydatastr.print_r(xmlToArray($postStr),true)."---------poststr \r\n";
  10. $notifydatastr = $notifydatastr.print_r($_GET,true)."---------GET \r\n";
  11. $notifydatastr = $notifydatastr.print_r($_POST,true)."---------POST \r\n\r\n\r\n";
  12. $notifydatastr = $notifydatastr.DISCUZ_PARTNER.'|'.DISCUZ_SECURITYCODE."---------常量 \r\n\r\n\r\n";;
  13. $filename = "./wxpay.txt";
  14. $fp = fopen("$filename", "a"); //打开文件指针,创建文件
  15. fwrite($fp, $notifydatastr);
  16. fclose($fp); //关闭指针
  17. //调试记录结束
  18. $post = xmlToArray($postStr);
  19. if($post['result_code'] == 'SUCCESS'){
  20. $data = array();
  21. $data['paystate'] = 3;
  22. $data['orderid'] = $post['transaction_id'];
  23. $data['pay_time'] = $_G['timestamp'];
  24. $data['notify_time'] = $_G['timestamp'];
  25. DB::update("xj_eventpay_log",$data,"tradeno='".$post['out_trade_no']."'");
  26. $paylog = DB::fetch_first("SELECT applyid FROM ".DB::table('xj_eventpay_log')." WHERE tradeno='".$post['out_trade_no']."'");
  27. $data = array();
  28. $data['pay_state'] = 1;
  29. DB::update("xj_eventapply",$data,"applyid=".$paylog['applyid']);
  30. $return = array();
  31. $return['return_code'] = 'SUCCESS'; //SUCCESS/FAIL SUCCESS表示商户接收通知成功并校验成功
  32. $return['return_msg'] = 'ok'; //返回信息,如非空,为错误原因
  33. }else{
  34. $return = array();
  35. $return['return_code'] = 'FAIL'; //SUCCESS/FAIL SUCCESS表示商户接收通知成功并校验成功
  36. $return['return_msg'] = 'ERROR'; //返回信息,如非空,为错误原因
  37. }
  38. echo arrayToXml($return);
  39. /**
  40. * 作用:array转xml
  41. */
  42. function arrayToXml($arr)
  43. {
  44. $xml = "<xml>";
  45. foreach ($arr as $key=>$val)
  46. {
  47. if (is_numeric($val))
  48. {
  49. $xml.="<".$key.">".$val."</".$key.">";
  50. }
  51. else
  52. $xml.="<".$key."><![CDATA[".$val."]]></".$key.">";
  53. }
  54. $xml.="</xml>";
  55. return $xml;
  56. }
  57. /**
  58. * 作用:将xml转为array
  59. */
  60. function xmlToArray($xml)
  61. {
  62. //将XML转为array
  63. $array_data = json_decode(json_encode(simplexml_load_string($xml, 'SimpleXMLElement', LIBXML_NOCDATA)), true);
  64. return $array_data;
  65. }
  66. ?>