🔥码云GVP开源项目 12k star Uniapp+ElementUI 功能强大 支持多语言、二开方便! 广告
# 微信支付异步回调监听类 Notify **目录 (Table of Contents)** [TOC] ## 类基本信息 **类简要描述:** >[info] 该类主要用于微信支付的回调监听 **类名字空间:** - endor/wechat/pay **类继承关系:** Notify -> ResponsePay -> PayApi -> WechatCommon ## 类成员函数/方法 >[danger] 注意:异步通知回调,该方法回调函数内无法使用$_SESSION,$GLOBAL,$COOKIE等 超全局数组,同时该接口调用的地方不能有权限认证 ### __construct($configure) + 参数列表: |参数名|类型|必填项|说明 |:---- |:---|:----- |----- | |$configure| object (WechatConfig) | 是 | 微信配置参数对象 | + 返回值: `无` + 函数说明: `构造函数` ### waitPaymentNotifyResults($complate_results_call_func) + 参数列表: |参数名|类型|必填项|说明 |:---- |:---|:----- |----- | |$complate_results_call_func| closure| 是 | 当微信回调本地服务器后,处理本地业务逻辑的回调函数 | + 返回值: `无` + 函数说明: `微信异步完成通知,回调参数$complete_result_call_func 接受一个闭包或函数` `该闭包接受2个参数,2个参数为:` |参数名|类型|必填项|说明 |:---- |:---|:----- |----- | |$results| array| 是 |微信服务器返回本地服务器的数据,NotifyData的关联数组模式 | |$status| string| 是 | 该值为 FAIL或者 SUCCESS,当且仅当$status 为SUCCESS时,$results数据才可信| + 函数示例 ``` PHP $wxConfigure = new WechatConfig(); $wxConfigure->setParameter("appid",YOUR_APPID); $wxConfigure->setParameter("appsecret",YOUR_SECRET); $wxConfigure->setParameter("mchid",YOUR_MCHID]); $wxConfigure->setParameter("key",YOUR_KEY); $notify = new Notify($wxConfigure); $notify->waitPaymentNotifyResults(function($orderRes, $status) use($notify){ if($status === "SUCCESS") { $out_trade_no = $results['out_trade_no']; echo "success"; } else { // log error echo "failed"; } }); ```