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

                # 微信推送接口對接示例含掃描登錄微信端部分源碼 >[info] 上源碼 不解釋了 ~~~ <?php /** * Created by PhpStorm. * Power by Mikkle * QQ:776329498 * Date: 2017/4/27 * Time: 13:33 */ namespace app\center\controller; use app\base\controller\Curl; use app\base\controller\Rsa; use app\base\model\we\WeFans; use app\base\model\we\WeLocation; use app\base\model\we\WeMessage; use app\base\model\we\WeTemplateMessage; use mikkle\tp_wechat\WechatApi; use think\Db; use think\Exception; use think\Cache; use think\Log; class ErpApi extends WechatApi { protected $valid = false; //網站第一次匹配 true 1為匹配 protected $isHook = false; //是否開啟鉤子 public function index() { try{ // Log::notice($this->request); parent::index(); }catch (Exception $e){ Log::error($e->getMessage()); } } protected function messageApplyEvent($EventKey, $subscribe = false){ $news_array = [ [ 'Title' => '申請云管家ERP系統', 'Description' => '現在去申請', 'PicUrl' => '', 'Url' => $this->request->domain() . '/center/apply/apply?event_key=' . $EventKey, ], ]; $reply = ['type' => 'news', 'message' => $news_array]; return $reply; } /** * 微信API接口 掃碼登錄 * Power by Mikkle * QQ:776329498 * @param $EventKey * @param bool|false $subscribe * @return array */ protected function messageLogEvent($EventKey, $subscribe = false) { $domain =Db::table("mk_we_fans_domain")->where(["status"=>1,"openid"=>$this->openid])->value("domain"); if ($domain) { //寫入登錄緩存 $log_data = [ 'code' => 1001, 'content' => '登錄成功', 'data' => $this->openid, ]; // Cache::set('log_' . $EventKey, $log_data, 120); $open_id = Rsa::instance()->encrypt($this->openid); try { $url = "http://{$domain}/api/system/loginWechat"; $push_data = [ "open_id" => $open_id, "event_key" => $EventKey ]; $result_code = json_decode(Curl::curlPost($url, $push_data)); if (!is_object($result_code)) { $result_code = json_decode(Curl::curlPost($url, $push_data)); } if (is_object($result_code)) { if (isset($result_code->code)) { if ($result_code->code == 1001) { if ($subscribe) { $reply = ['type' => 'text', 'message' => '感謝你的關注,你正在進行微信掃碼成功.登錄ID[' . $EventKey . ']']; } else { $reply = ['type' => 'text', 'message' => '你正在進行微信掃碼.登錄ID[' . $EventKey . ']']; } }else{ throw new Exception($result_code); } } }else{ throw new Exception($result_code); } }catch (Exception $e){ Log::error($e->getMessage()); $reply=['type' => 'text', 'message' => '感謝你的關注']; return $reply; } } else { $news_array = [ [ 'Title' => '你的微信暫時未綁定ERP系統', 'Description' => '現在去綁定', 'PicUrl' => '', 'Url' => $this->request->domain() . '/center/we_action/binding?sid=' . $EventKey, ], ]; $reply = ['type' => 'news', 'message' => $news_array]; } return $reply; } protected function returnEventLocation() { return ""; } protected function returnEventSubscribe(){ if (isset($this->data['EventKey'])&&is_string($this->data['EventKey'])) { $EventKeyArray = explode('_', $this->data['EventKey']); if(count($EventKeyArray)==2){ $EventKey=$EventKeyArray[1]; switch(true){ case (stristr($EventKey,"apply")): return $this->messageApplyEvent($EventKey,true); break; default: //判斷登錄緩存是否存在 if (Cache::has('log_' . $EventKey)) { $reply = $this->messageLogEvent($EventKey,true); } else { $reply = ['type' => 'text', 'message' => '感謝你的關注']; } } } $reply = ['type' => 'text', 'message' => '感謝你的關注']; } else { $reply = ['type' => 'text', 'message' => '感謝你的關注']; } return $reply; } protected function returnEventUnsubscribe(){ Db::name('WeFans')->where('openid', $this->openid)->update(['subscribe' => 0, 'unsubscribe_time' => time()]); return ['type' => 'text', 'message' => '期待你的再次關注']; } protected function returnEventScan(){ //記錄掃碼獲取機器人回答 $EventKey = $this->data['EventKey']; switch(true){ case (stristr($EventKey,"apply")): $reply = $this->messageApplyEvent($EventKey); break; default: //判斷登錄緩存是否存在 if (Cache::has('log_' . $EventKey)) { $reply = $this->messageLogEvent($EventKey);; } else { $reply = ['type' => 'text', 'message' =>"你的掃碼成功-$EventKey"]; } } return $reply; } protected function saveWeMessage() { //定義message的Model $model_message = $this->getWeMessageModel(); //查詢是否已經接受該消息 if (isset($this->data['MsgId'])) { if ($model_message->infoByMsgId($this->data['MsgId'])) { return false; } } //記錄消息 if (isset($this->data['Recognition'])) { if (is_string($this->data['Recognition'])) { $this->data['Content'] = $this->data['Recognition']; } else { $this->data['Content'] = 'Translation failure!'; unset($this->data['Recognition']); } } if (isset($this->data['Latitude'])) { $this->getWeLocationModel()->editData($this->data); } else if (isset($this->data['MsgID'])) { $this->getWeTemplateMessageModel()->updateTemplateMessage($this->data['MsgID']); } else { $model_message->editData($this->data); } } public function hasSaveFans($openid = '') { try { $openid = $openid ? $openid : $this->openid; if (empty($openid)) { // $this->we_dump($openid); return false; } $model_fans = $this->getWeFansModel(); $fans = $model_fans->infoToArray($openid); if (!$fans) { $fans = $this->weObj->getUserInfo($openid); if ($fans) { if (is_object($fans)) { $fans = $fans->toArray(); } $fans['appid'] = isset($this->options['appid'])?$this->options['appid']:""; // Log::notice($fans); $model_fans->editData($fans); } else { //todo 報警 throw new Exception("獲取用戶信息失敗"); } } else { //記錄心跳 $model_fans->where('openid', $this->openid)->setField('update_time', time()); } return $fans; } catch (Exception $e) { Log::error($e->getMessage()); return false; } } protected function getWeFansModel() { return new WeFans(); } protected function getWeMessageModel() { return new WeMessage(); } protected function getWeTemplateMessageModel() { return new WeTemplateMessage(); } protected function getWeLocationModel() { return new WeLocation(); } } ~~~
                  <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>

                              哎呀哎呀视频在线观看