notify.php 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. <?php
  2. /*
  3. * FecShop file.
  4. *
  5. * @link http://www.fecshop.com/
  6. * @copyright Copyright (c) 2016 FecShop Software LLC
  7. * @license http://www.fecshop.com/license/
  8. */
  9. ini_set('date.timezone', 'Asia/Shanghai');
  10. //error_reporting(E_ERROR);
  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. \Yii::info("query:" . json_encode($result), 'fecshop_debug');
  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. return true;
  25. }
  26. return false;
  27. }
  28. //重写回调处理函数
  29. public function NotifyProcess($data, &$msg)
  30. {
  31. \Yii::info("call back:" . json_encode($data), 'fecshop_debug');
  32. $notfiyOutput = [];
  33. if (!array_key_exists("transaction_id", $data)) {
  34. $msg = "输入参数不正确";
  35. return false;
  36. }
  37. //查询订单,判断订单真实性
  38. if (!$this->Queryorder($data["transaction_id"])) {
  39. $msg = "订单查询失败";
  40. return false;
  41. }
  42. $arr = $this->getDataArray($data);
  43. return \Yii::$service->payment->wxpay->ipnUpdateOrder($arr);
  44. }
  45. public function getDataArray($data)
  46. {
  47. $arr = [];
  48. foreach ($data as $k => $v) {
  49. $arr[$k] = $v;
  50. }
  51. return $arr;
  52. }
  53. }