<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                # 微信公眾號推送接口對接教程 [TOC] ## **第一步 創建一個控制器 繼承WchatApi** ~~~ <?php namespace app\api\controller\index; use mikkle\tp_wechat\WechatApi; /** * Created by PhpStorm. * Power By Mikkle * Email:776329498@qq.com * Date: 2017/11/1 * Time: 14:57 */ class Index extends WechatApi { } ~~~ ok 現在微信的接口已經搭建好了 剩余就是配置微信參數了 ## **第二步 配置微信參數** 配置參數詳見 http://www.hmoore.net/mikkle/thinkphp5_study/450540 當然 你也可以直接吧微信參數直接寫到接口文件中 ~~~ <?php namespace app\api\controller\index; use mikkle\tp_wechat\WechatApi; /** * Created by PhpStorm. * Power By Mikkle * Email:776329498@qq.com * Date: 2017/11/1 * Time: 14:57 */ class Index extends WechatApi { protected $options=[ 'token'=>'*****', 'appid'=>'******************', 'appsecret'=>'*********************************', 'encodingaeskey'=>'******************************', ]; protected $valid = false; //網站第一次匹配 true 1為匹配 protected $isHook = false; //是否開啟鉤子 } ~~~ ## **第三步 登錄微信網站對接接口即可** >[danger] 設置 protected $valid = true; //網站第一次匹配 true 1為匹配 > 登錄微信公眾平臺對接即可. ## **第四步 根據自己實際需求處理重建回調方法** 例如: ~~~ protected function returnEventUnsubscribe(){ Db::name('WeFans')->where('openid', $this->openid)->update(['subscribe' => 0, 'unsubscribe_time' => time()]); return ['type' => 'text', 'message' => '期待你的再次關注']; } ~~~ ## **推送接口 回調函數列表** 詳情你可以參照 WechatApi 文件 文件中已經添加了默認處理方法 | 回調方法名稱 | 回調方法作用 | | --- | --- | | returnMessageText | 默認文本消息回復內容 | | returnMessageImage | 默認圖片信息回復內容 | | returnMessageVoice | 默認語音信息回復內容處理方法 | | returnMessageMusic | 默認音樂信息回復內容處理方法 | | returnMessageVideo | 默認視頻信息回復處理方法 | | returnMessageLocation | 默認發送地理位置回復信息處理方法 | | returnMessageLink | 默認鏈接回復內容處理方法 | | returnEventSubscribe | 默認關注回復處理方法 | | returnEventUnsubscribe | 默認取消關注回復處理方法 | | returnEventScan | 默認掃碼事件處理方法 | | returnEventLocation | 默認上報地理事件處理方法 | | returnEventClick | 默認點擊菜單關鍵字處理方法 | | returnEventMenuScan | 菜單調用掃碼事件處理方法 | | returnEventMenuPic | 通過菜單上傳圖片處理方法 | | returnEventMenuLocation | 菜單上報地理事件處理方法 | | returnEventSendMass | 群發成功推送結果處理方法 | | returnEventSendTemplate | 模版消息接收結果處理方法 | | returnEvenKfSession | 客服事件處理方法 | | returnEventCard | 卡類事件 處理方法 | | returnEventWifiConnected | wifi連一連處理方法 | | returnEventAroundUserSnake | 周圍搖一搖事件處理方法 | | returnEventOthers | 其他未知事件處理方法 | >[danger] PS 不是所有的推送 都會返回給顧客信息的 如果你要通知顧客 就要主動發起推送 如模版消息 在回調方法中,我只做了回調結構處理 text news image voice video等媒體信息 message內容要寫MediaId * 文本類型 方法一 直接回復string ~~~ return '發送的是文本信息'; ~~~ 方法二 回復數組 ~~~ return ['type' => 'text', 'message' => '感謝你的關注']; ~~~ * 回復新聞 ~~~ $newsarray = [ [ 'Title' => '你的圖片發送成功', 'Description' => '這是你發的圖片吧', 'PicUrl' => $this->data['PicUrl'], 'Url' => $this->request->domain(), ], ]; $reply = ['type' => 'news', 'message' => $newsarray]; return $reply; ~~~ >[danger] 注意 回復結構 $newsarray是二維數組 支持多條文章 * 回復 image voice video ~~~ //回復 image return ['type' => 'image', 'message' => $MediaId]; //回復 voice return ['type' => 'voice', 'message' => $MediaId]; //回復 video return ['type' => 'video', 'message' => $MediaId]; ~~~ ## **重構微信推送保存方法的接口** 返回true 表示消息不存在 并且保存成功 返回 fasle 表示該消息已經存在 我是分表存儲的 如:下面代碼 ~~~ saveWeMessage(){ //根據message的獲取存儲的Model $model_message = $this->getWeMessageModel(); //查詢是否已經接受該消息 if (isset($this->data['MsgId'])) { if ($model_message->infoByMsgId($this->data['MsgId'])) { return false; } $model_message->editData($this->data); } } ~~~ 如果你不保存也不查詢是否存在 直接返回true ## **微信推送信息的獲取** | 屬性名稱 | 備注 | | --- | --- | | $this->app_id | 微信app_id | | $this->options | 微信參數信息 | | $this->openid | 用戶openid | | $this->fans | 微信fans信息 | | $this->type | 推送類型 | | $this->data | 微信推送信息 | 你可以根據需求直接在回調函數中調用查詢使用 ## **微信推送信息的調試** ~~~ $this->we_dump($reply); ~~~ >[info] 你只需要使用we_dump方法即可 會把你想要的信息轉化成文本信息 ## **重構獲取用戶信息接口** 默認的獲取用戶信息方法并未查庫處理 推薦重構 進行查庫處理 ~~~ /** * 獲取用戶信息 * 建議根據你的需求重寫此方法 * Power: Mikkle * Email:776329498@qq.com * @param string $openid * @return array|bool */ protected function hasSaveFans($openid = '') { try { $openid = $openid ?: $this->openid; if (empty($openid)) { return false; } $fans = $this->weObj->getUserInfo($openid); return $fans; } catch (Exception $e) { Log::error($e->getMessage()); return false; } } ~~~ ## **微信推送鉤子(HOOK)事件列表** >[info] 本推送接口埋藏大量的鉤子(HOOK),但并沒用自動開啟 >[danger] 如果要開啟鉤子 請將$this->isHook 設置為true 或者 1 > 另外 回調函數的參數為 $this->weObj 對象 并不是當前類 ~~~ Hook::listen("wechat_receive", $this->weObj); ~~~ >[info] 你可以根據下面的方法 在hook獲取想要的值 ~~~ //分解數據獲得常用字段 $get_rev = $this->weObj->getRev(); $this->openid = $get_rev->getRevFrom(); $this->type = $get_rev->getRevType(); $this->data = $get_rev->getRevData(); ~~~ | 鉤子名稱 | 鉤子說明 | | --- | --- | | wechat_receive | 主程序 | | wechat_message_text | | | wechat_message_image | | | wechat_message_voice | | | wechat_message_music | | | wechat_message_video | | | wechat_message_location | | | wechat_message_link | | | wechat_event_subscribe | | | wechat_event_unsubscribe | | | wechat_event_scan | | | wechat_event_location | | | wechat_event_click | | | wechat_event_menu_scan_push | | | wechat_event_menu_scan_waitmsg | | | wechat_event_menu_pic_sys | | | wechat_event_menu_pic_photo | | | wechat_event_menu_pic_weixin | | | wechat_event_menu_location | | | wechat_event_send_mass | | | wechat_event_send_template | | | wechat_event_kf_create | | | wechat_event_kf_close | | | wechat_event_kf_switch | | | wechat_event_card_pass | | | wechat_event_card_notpass | | | wechat_event_card_user_get | | | wechat_event_menu_user_del | | | wechat_event_wifi_connected | | | wechat_event_around_user_shake | | | wechat_event_others | | 注釋我不寫了 自己猜吧
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看