您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

native_notify.php 2.0 KiB

3 年前
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. <?php
  2. ini_set('date.timezone','Asia/Shanghai');
  3. error_reporting(E_ERROR);
  4. require_once "../lib/WxPay.Api.php";
  5. require_once '../lib/WxPay.Notify.php';
  6. require_once 'log.php';
  7. //初始化日志
  8. $logHandler= new CLogFileHandler("../logs/".date('Y-m-d').'.log');
  9. $log = Log::Init($logHandler, 15);
  10. class NativeNotifyCallBack extends WxPayNotify
  11. {
  12. public function unifiedorder($openId, $product_id)
  13. {
  14. //统一下单
  15. $input = new WxPayUnifiedOrder();
  16. $input->SetBody("test");
  17. $input->SetAttach("test");
  18. $input->SetOut_trade_no(WxPayConfig::MCHID.date("YmdHis"));
  19. $input->SetTotal_fee("1");
  20. $input->SetTime_start(date("YmdHis"));
  21. $input->SetTime_expire(date("YmdHis", time() + 600));
  22. $input->SetGoods_tag("test");
  23. $input->SetNotify_url("http://paysdk.weixin.qq.com/example/notify.php");
  24. $input->SetTrade_type("NATIVE");
  25. $input->SetOpenid($openId);
  26. $input->SetProduct_id($product_id);
  27. $result = WxPayApi::unifiedOrder($input);
  28. Log::DEBUG("unifiedorder:" . json_encode($result));
  29. return $result;
  30. }
  31. public function NotifyProcess($data, &$msg)
  32. {
  33. //echo "处理回调";
  34. Log::DEBUG("call back:" . json_encode($data));
  35. if(!array_key_exists("openid", $data) ||
  36. !array_key_exists("product_id", $data))
  37. {
  38. $msg = "回调数据异常";
  39. return false;
  40. }
  41. $openid = $data["openid"];
  42. $product_id = $data["product_id"];
  43. //统一下单
  44. $result = $this->unifiedorder($openid, $product_id);
  45. if(!array_key_exists("appid", $result) ||
  46. !array_key_exists("mch_id", $result) ||
  47. !array_key_exists("prepay_id", $result))
  48. {
  49. $msg = "统一下单失败";
  50. return false;
  51. }
  52. $this->SetData("appid", $result["appid"]);
  53. $this->SetData("mch_id", $result["mch_id"]);
  54. $this->SetData("nonce_str", WxPayApi::getNonceStr());
  55. $this->SetData("prepay_id", $result["prepay_id"]);
  56. $this->SetData("result_code", "SUCCESS");
  57. $this->SetData("err_code_des", "OK");
  58. return true;
  59. }
  60. }
  61. Log::DEBUG("begin notify!");
  62. $notify = new NativeNotifyCallBack();
  63. $notify->Handle(true);