buy_notify.php 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. <?php
  2. include("../../../../config/conn.php");
  3. include("../../../../config/function.php");
  4. ini_set('date.timezone','Asia/Shanghai');
  5. error_reporting(E_ERROR);
  6. require_once "../lib/WxPay.Api.php";
  7. require_once '../lib/WxPay.Notify.php';
  8. require_once 'log.php';
  9. //初始化日志
  10. $logHandler= new CLogFileHandler("../logs/".date('Y-m-d').'.log');
  11. $log = Log::Init($logHandler, 15);
  12. class PayNotifyCallBack extends WxPayNotify
  13. {
  14. //查询订单
  15. public function Queryorder($transaction_id)
  16. {
  17. $input = new WxPayOrderQuery();
  18. $input->SetTransaction_id($transaction_id);
  19. $result = WxPayApi::orderQuery($input);
  20. Log::DEBUG("query:" . json_encode($result));
  21. if(array_key_exists("return_code", $result)
  22. && array_key_exists("result_code", $result)
  23. && $result["return_code"] == "SUCCESS"
  24. && $result["result_code"] == "SUCCESS")
  25. {
  26. $sj=date("Y-m-d H:i:s");
  27. $uip=$_SERVER["REMOTE_ADDR"];
  28. $sql="select * from yjcode_dingdang where wxddbh='".$result[out_trade_no]."' and ifok=0";mysql_query("SET NAMES 'GBK'");$res=mysql_query($sql);
  29. if($row=mysql_fetch_array($res)){
  30. updatetable("yjcode_dingdang","sj='".$sj."',uip='".$uip."',alipayzt='TRADE_SUCCESS',ddzt='交易成功',ifok=1 where wxddbh='".$result[out_trade_no]."'");
  31. $money1=$row["money1"];
  32. PointIntoM($row[userid],"微信手机付款".$money1."元",$money1);
  33. PointUpdateM($row[userid],$money1);
  34. $buyuserid=$row[userid];
  35. $bharr=$row[probh];
  36. $numarr=$row[pronum];
  37. $tcidarr=$row[tcid];
  38. $buyformarr=$row[buyform];
  39. include("../../../../user/buy.php");
  40. }
  41. return true;
  42. }
  43. return false;
  44. }
  45. //重写回调处理函数
  46. public function NotifyProcess($data, &$msg)
  47. {
  48. Log::DEBUG("call back:" . json_encode($data));
  49. $notfiyOutput = array();
  50. if(!array_key_exists("transaction_id", $data)){
  51. $msg = "输入参数不正确";
  52. return false;
  53. }
  54. //查询订单,判断订单真实性
  55. if(!$this->Queryorder($data["transaction_id"])){
  56. $msg = "订单查询失败";
  57. return false;
  58. }
  59. return true;
  60. }
  61. }
  62. Log::DEBUG("begin notify");
  63. $notify = new PayNotifyCallBack();
  64. $notify->Handle(false);