<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>

                # 附件十三 微信推送消息接口類庫源碼 基類 謝謝關注 ~~~ <?php /** * Created by PhpStorm. * Power By Mikkle * Email:776329498@qq.com * Date: 2017/9/15 * Time: 17:54 */ namespace mikkle\tp_wechat\base; use mikkle\tp_wechat\support\Exception; use mikkle\tp_wechat\Wechat; use think\Hook; use mikkle\tp_wechat\support\Log; use mikkle\tp_wechat\support\Request; /** * 微信消息接口基類 * Power: Mikkle * Email:776329498@qq.com * Class BaseWeApi * @package app\center\controller */ abstract class BaseWechatApi { protected $app_id; //微信參數 建議繼承覆蓋此參數 protected $options; protected $weObj; protected $openid; protected $type; protected $data; protected $fans; //是否開啟對接 建議繼承覆蓋此參數 protected $valid = true; // protected $isHook = false; //是否開啟鉤子 public function __construct($options = []) { $this->request = Request::instance(); $this->options = !empty($options) ? $options : $this->options; $this->app_id = $this->options['appid']; $this->weObj = Wechat::receive($this->options); } /** * 微信接收主方法 * Power: Mikkle * Email:776329498@qq.com */ public function index() { try { //是否是對接模式 if ($this->valid == true) { $this->weObj->valid(); } //分解數據獲得常用字段 $get_rev = $this->weObj->getRev(); if (empty($get_rev)) { $this->we_dump('false'); } $this->openid = $get_rev->getRevFrom(); $this->type = $get_rev->getRevType(); $this->data = $get_rev->getRevData(); if (empty($this->data)) { $this->we_dump('false'); } //用戶檢測,如果有就存入data,沒有則存入數據庫 $fans = $this->hasSaveFans(); if (!$fans) { throw new Exception("獲取粉絲信息錯誤"); } Hook::listen("wechat_receive", $this->weObj); //補充常用相關數據到DATA $this->data['appid'] = $this->app_id; $this->data['openid'] = $fans['openid']; $this->data['nickname'] = $fans['nickname']; $this->fans = $fans; //判斷消息是否存在 if ($this->saveWeMessage() === false) { $this->weObj->text('處理中,請稍后!')->reply(); die; }; $reply = []; //根據消息類型 獲取不同回復內容 $message = $this->messageTypeHandleCenter(); if (!empty($message)) { //處理兼容 if (!is_array($message)) { $reply['message'] = $message; } else { $reply = $message; } if (!isset($reply['type'])) $reply['type'] = 'text'; $reply['message'] = isset($reply['message']) ? $reply['message'] : '知道嗎!我愛你!請原諒我不知道如何回答你的問題!'; $this->weObj->$reply['type']($reply['message'])->reply(); } die; } catch (Exception $e) { Log::error($e); $this->weObj->text("本寶寶生病了,請原諒我不知道如何回答你的問題!")->reply(); die(); } } /** * 默認文本消息回復內容 * * Power: Mikkle * Email:776329498@qq.com * @return string */ protected function returnMessageText() { return '發送的是' . $this->weObj->getRevContent(); } /** * 默認圖片信息回復內容 * * Power: Mikkle * Email:776329498@qq.com * @return array */ protected function returnMessageImage() { $newsarray = [ [ 'Title' => '你的圖片發送成功', 'Description' => '這是你發的圖片吧', 'PicUrl' => $this->data['PicUrl'], 'Url' => $this->request->domain(), ], ]; $reply = ['type' => 'news', 'message' => $newsarray]; return $reply; } /** * 默認語音信息回復內容處理方法 * * Power: Mikkle * Email:776329498@qq.com * @return string */ protected function returnMessageVoice() { if (!empty($this->data['Content'])) { $keyword = $this->data['Content']; //TODO::語音識別 語義分析 } else { $keyword = $this->data->type; } $reply = '發送的語音翻譯是:' . $keyword; return $reply; } /** * 默認音樂信息回復列表處理方法 * Power: Mikkle * Email:776329498@qq.com * @return string */ protected function returnMessageMusic() { return '發送的是音樂'; } /** * 默認視頻信息回復處理方法 * Power: Mikkle * Email:776329498@qq.com * @return string */ protected function returnMessageVideo() { return '發送的是視頻'; } /** * 默認發送地理位置回復信息處理方法 * Power: Mikkle * Email:776329498@qq.com * @return string */ protected function returnMessageLocation() { return '發送的是地理位置'; } /** * 默認鏈接回復內容處理方法 * Power: Mikkle * Email:776329498@qq.com * @return string */ protected function returnMessageLink() { return '發送的是鏈接'; } /** * 默認關注回復處理方法 * Power: Mikkle * Email:776329498@qq.com * @return array */ protected function returnEventSubscribe() { return ['type' => 'text', 'message' => '感謝你的關注']; } /** * 默認取消關注回復處理方法 * Power: Mikkle * Email:776329498@qq.com * @return array */ protected function returnEventUnsubscribe() { return ['type' => 'text', 'message' => '期待你的再次關注']; } /** * 默認掃碼事件處理方法 * Power: Mikkle * Email:776329498@qq.com * @return array */ protected function returnEventScan() { $message = $this->weObj->getRevEvent(); if (isset($message["key"])) { return ['type' => 'text', 'message' => "你的掃碼成功,掃碼內容:{$message['key']}"]; } return ['type' => 'text', 'message' => '你的掃碼成功']; } /** * 默認上報地理事件處理方法 * Power: Mikkle * Email:776329498@qq.com * @return array */ protected function returnEventLocation() { return ['type' => 'text', 'message' => '地理位置上報成功']; } /** * 默認點擊菜單關鍵字處理方法 * Power: Mikkle * Email:776329498@qq.com * @return array */ protected function returnEventClick() { $message = $this->weObj->getRevEvent(); if (isset($message["key"])) { return ['type' => 'text', 'message' => "你的點擊成功,點擊關鍵字內容:{$message['key']}"]; } return ['type' => 'text', 'message' => '你的點擊成功']; } /** * 菜單調用掃碼事件處理方法 * Power: Mikkle * Email:776329498@qq.com * @param $type * @return array */ protected function returnEventMenuScan($type) { $message = $this->weObj->getRevEvent(); switch ($type) { case "push": //推送 if (isset($message["key"])) { return ['type' => 'text', 'message' => "你的點擊菜單掃碼,關鍵字內容:{$message['key']}"]; } return ['type' => 'text', 'message' => '你的點擊菜單掃碼成功']; break; case "waitmsg": //等候 if (isset($message["key"])) { return ['type' => 'text', 'message' => "你的點擊菜單掃碼等待中,關鍵字內容:{$message['key']}"]; } return ['type' => 'text', 'message' => '你的點擊菜單掃碼等待中']; break; default: ; } } /** * 通過菜單上傳圖片處理方法 * Power: Mikkle * Email:776329498@qq.com * @param $type // sys 系統 | photo 相冊 | weixin 微信相冊 * @return array */ protected function returnEventMenuPic($type) { $message = $this->weObj->getRevEvent(); if (isset($message["key"])) { return ['type' => 'text', 'message' => "你的通過菜單上傳圖片成功,圖片方式{$type},關鍵字內容:{$message['key']}"]; } return ['type' => 'text', 'message' => "你的通過菜單上傳圖片成功,圖片方式{$type}"]; } /** * 菜單上報地理事件 * Power: Mikkle * Email:776329498@qq.com * @return string */ protected function returnEventMenuLocation() { return $reply['message'] = 'success'; } /** * 群發成功推送結果處理方法 * Power: Mikkle * Email:776329498@qq.com * @return string */ protected function returnEventSendMass() { return $reply['message'] = 'success'; } /** * 模版消息接收結果處理方法 * Power: Mikkle * Email:776329498@qq.com * @return string */ protected function returnEventSendTemplate() { return $reply['message'] = 'success'; } /** * 客服事件處理方法 * Power: Mikkle * Email:776329498@qq.com * @param $type //create | close | switch * @return string */ protected function returnEvenKfSession($type) { return $reply['message'] = 'success'; } /** * 卡類時間 處理方法 * Power: Mikkle * Email:776329498@qq.com * @param $type //pass | notpass | user_get |user_dell * @return string */ protected function returnEventCard($type) { return $reply['message'] = 'success'; } /** * wifi連一連處理方法 * Power: Mikkle * Email:776329498@qq.com * @return string */ protected function returnEventWifiConnected() { return $reply['message'] = 'success'; } /** * 其他未知事件處理方法 * Power: Mikkle * Email:776329498@qq.com * @return string */ protected function returnEventOthers() { return $reply['message'] = 'success'; } /** * 周圍搖一搖事件處理方法 * Power: Mikkle * Email:776329498@qq.com * @return string */ protected function returnEventAroundUserSnake() { return $reply['message'] = 'success'; } /** * 處理微信消息總處理入口 * Power: Mikkle * Email:776329498@qq.com * @return array|string */ private function messageTypeHandleCenter() { switch ($this->type) { case WeChatCode::MSGTYPE_TEXT: if ($this->isHook) { Hook::listen("wechat_message_text", $this->weObj); } return $this->returnMessageText(); break; case WeChatCode::MSGTYPE_IMAGE: if ($this->isHook) { Hook::listen("wechat_message_image", $this->weObj); } return $this->returnMessageImage(); break; case WeChatCode::MSGTYPE_VOICE: if ($this->isHook) { Hook::listen("wechat_message_voice", $this->weObj); } return $this->returnMessageVoice(); break; case WeChatCode::MSGTYPE_MUSIC: if ($this->isHook) { Hook::listen("wechat_message_music", $this->weObj); } return $this->returnMessageMusic(); break; case WeChatCode::MSGTYPE_VIDEO: if ($this->isHook) { Hook::listen("wechat_message_video", $this->weObj); } return $this->returnMessageVideo(); break; case WeChatCode::MSGTYPE_LOCATION: if ($this->isHook) { Hook::listen("wechat_message_location", $this->weObj); } return $this->returnMessageLocation(); break; case WeChatCode::MSGTYPE_LINK: if ($this->isHook) { Hook::listen("wechat_message_link", $this->weObj); } return $this->returnMessageLink(); break; case WeChatCode::MSGTYPE_EVENT: //事件處理中心 $reply = $this->messageEventHandleCenter(); break; default: $reply = ['type' => 'text', 'message' => 'success']; break; } return $reply; } /** * 處理微信事件消息處理中心 * Power: Mikkle * Email:776329498@qq.com * @return array|string */ private function messageEventHandleCenter() { try { $reply = ""; switch ($this->data['Event']) { case WeChatCode::EVENT_SUBSCRIBE: if ($this->isHook) { Hook::listen("wechat_event_subscribe", $this->weObj); } $reply = $this->returnEventSubscribe(); break; case WeChatCode::EVENT_UNSUBSCRIBE: if ($this->isHook) { Hook::listen("wechat_event_unsubscribe", $this->weObj); } $reply = $this->returnEventUnsubscribe(); break; case WeChatCode::EVENT_SCAN: if ($this->isHook) { Hook::listen("wechat_event_scan", $this->weObj); } $reply = $this->returnEventScan(); break; case WeChatCode::EVENT_LOCATION: if ($this->isHook) { Hook::listen("wechat_event_location", $this->weObj); } $reply = $this->returnEventLocation(); break; case WeChatCode::EVENT_MENU_CLICK: if ($this->isHook) { Hook::listen("wechat_event_click", $this->weObj); } $reply = $this->returnEventClick(); break; case WeChatCode::EVENT_MENU_SCAN_PUSH: if ($this->isHook) { Hook::listen("wechat_event_menu_scan_push", $this->weObj); } $reply = $this->returnEventMenuScan("push"); break; case WeChatCode::EVENT_MENU_SCAN_WAITMSG: if ($this->isHook) { Hook::listen("wechat_event_menu_scan_waitmsg", $this->weObj); } $reply = $this->returnEventMenuScan("waitmsg"); break; case WeChatCode::EVENT_MENU_PIC_SYS: if ($this->isHook) { Hook::listen("wechat_event_menu_pic_sys", $this->weObj); } $reply = $this->returnEventMenuPic("sys"); break; case WeChatCode::EVENT_MENU_PIC_PHOTO: if ($this->isHook) { Hook::listen("wechat_event_menu_pic_photo", $this->weObj); } $reply = $this->returnEventMenuPic("photo"); break; case WeChatCode::EVENT_MENU_PIC_WEIXIN: if ($this->isHook) { Hook::listen("wechat_event_menu_pic_weixin", $this->weObj); } $reply = $this->returnEventMenuPic("weixin"); break; case WeChatCode::EVENT_MENU_LOCATION: if ($this->isHook) { Hook::listen("wechat_event_menu_location", $this->weObj); } $reply = $this->returnEventMenuLocation(); break; case WeChatCode::EVENT_SEND_MASS: if ($this->isHook) { Hook::listen("wechat_event_send_mass", $this->weObj); } $reply = $this->returnEventSendMass(); break; case WeChatCode::EVENT_SEND_TEMPLATE: if ($this->isHook) { Hook::listen("wechat_event_send_template", $this->weObj); } $reply = $this->returnEventSendTemplate(); //模板消息發送成功 $reply['message'] = 'success'; break; case WeChatCode::EVENT_KF_SESSION_CREATE: if ($this->isHook) { Hook::listen("wechat_event_kf_create", $this->weObj); } $reply = $this->returnEvenKfSession("create"); break; case WeChatCode::EVENT_KF_SESSION_CLOSE: if ($this->isHook) { Hook::listen("wechat_event_kf_close", $this->weObj); } $reply = $this->returnEvenKfSession("close"); break; case WeChatCode::EVENT_KF_SESSION_SWITCH: if ($this->isHook) { Hook::listen("wechat_event_kf_switch", $this->weObj); } $reply = $this->returnEvenKfSession("switch"); break; case WeChatCode::EVENT_CARD_PASS: if ($this->isHook) { Hook::listen("wechat_event_card_pass", $this->weObj); } $reply = $this->returnEventCard("notpass"); break; case WeChatCode::EVENT_CARD_NOTPASS: if ($this->isHook) { Hook::listen("wechat_event_card_notpass", $this->weObj); } $reply = $this->returnEventCard("notpass"); break; case WeChatCode::EVENT_CARD_USER_GET: if ($this->isHook) { Hook::listen("wechat_event_card_user_get", $this->weObj); } $reply = $this->returnEventCard("user_get"); break; case WeChatCode::EVENT_CARD_USER_DEL: if ($this->isHook) { Hook::listen("wechat_event_menu_user_del", $this->weObj); } $reply = $this->returnEventCard("user_dell"); break; case WeChatCode::EVENT_WIFI_CONNECTED : if ($this->isHook) { Hook::listen("wechat_event_wifi_connected", $this->weObj); } $reply = $this->returnEventWifiConnected(); break; case WeChatCode::EVENT_SHAKEAROUND_USER_SHAKE : if ($this->isHook) { Hook::listen("wechat_event_around_user_shake", $this->weObj); } $reply = $this->returnEventAroundUserSnake(); break; default: if ($this->isHook) { Hook::listen("wechat_event_others", $this->weObj); } $reply = $this->returnEventOthers(); break; break; } return $reply; } catch (Exception $e) { return "回復事件信息出錯了 {$e->getMessage()}"; } } /** * 保存信息方法 * 建議根據你的需求重寫此方法 * Power: Mikkle * Email:776329498@qq.com * @return bool */ protected function saveWeMessage() { return true; } /** * 獲取用戶信息 * 建議根據你的需求重寫此方法 * 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); return false; } } /** * 調試內容給客戶端 * Power: Mikkle * Email:776329498@qq.com * @param $value */ protected function we_dump($value) { ob_start(); var_dump($value); $back = ob_get_clean(); $this->weObj->text($back)->reply(); ob_end_flush(); die; return; } } ~~~
                  <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>

                              哎呀哎呀视频在线观看