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

                # 高階篇二 使用Redis隊列發送微信模版消息 > 此命令行執行任務的方法類比較復雜 他需要命令行運行才會有效 > 命令行源碼以及創建方法 參見上節 http://www.hmoore.net/mikkle/thinkphp5_study/396283 > 總體的邏輯是通過Redis作為隊列媒介 命令行 根據分析reids數據并執行指定方法 > 本類的靜態方法add 是往redis隊列中追加數據 > 本類的靜態方法run方法 是命令行程序執行的處理隊列信息的方法 > Redis類庫 參見 附件十 http://www.hmoore.net/mikkle/thinkphp5_study/374537 ~~~ <?php /** * Created by PhpStorm. * Power By Mikkle * Email:776329498@qq.com * Date: 2017/7/4 * Time: 13:56 */ namespace app\worker\controller; use mikkle\tp_wechat\Wechat; use think\Config; use think\Exception; use think\Log; class WechatMessage extends Base { protected $options=[]; protected $wechat; protected $listName; public function __construct($options=[]) { $this->options = empty($options) ? Config::get("wechat.erp_options") : $options; parent::__construct($options); $this->message=Wechat::message($this->options); $this->listName = md5($this->workerName); } /** * 檢測命令行是否執行中 * Power: Mikkle * Email:776329498@qq.com * @return bool */ static public function checkCommandRun(){ return self::redis()->get("command") ? true :false; } /** * 快速添加模版消息任務 * * 當命令行未運行 直接執行 * Power: Mikkle * Email:776329498@qq.com * @param $data * @param array $options */ static public function add($data,$options=[]){ $instance = self::instance($options); switch (true){ case (self::checkCommandRun()): $instance->redis->lpush($instance->listName,$data); $instance->runWorker(); break; default: $instance->message->sendTemplateMessage($data); } } /** * 命令行執行的方法 * Power: Mikkle * Email:776329498@qq.com */ static public function run(){ $instance = self::instance(); try{ $i = 0; while(true){ $data = $instance->redis->rpop($instance->listName); if ($data){ $re=$instance->sendMessage($data); Log::notice($re); }else{ break; } $i++; sleep(1); } $instance->clearWorker(); echo "執行了{$i}次任務".PHP_EOL; }catch (Exception $e){ Log::error($e); $instance->clearWorker(); die($e->getMessage()); } } /** * 發送模版消息的方法 * Power: Mikkle * Email:776329498@qq.com * @param $data * @return bool */ protected function sendMessage($data){ $no = $this->message->sendTemplateMessage($data); if ($no){ Log::notice("發送成功[{$no}]"); return true ; }else{ Log::notice("發送失敗[{$no}]"); $this->failed($data); }; } /** * 出錯執行的回調方法 * Power: Mikkle * Email:776329498@qq.com * @param $data */ protected function failed($data){ } } ~~~ ![](https://box.kancloud.cn/3d03b7f1d9950795c8b1f45d16dfef3a_862x335.png) * 調用Work類的方法 你可以循環插入 ~~~ $assign_data= [ "ToUserName"=>$value, "url"=> Url::build($type["url"],[],"",true), "first"=> "溫馨提示,你有一個[{$type["title"]}]需要審核". (empty($uuid_name)?"":",提交人:$uuid_name"), "keyword1"=>"{$type["title"]}審核", "keyword2"=>date("Y-m-d H:i:s",time()), "remark"=>"點擊查看具體內容" ]; $template = $this->assignTemplate("mission",$assign_data); //添加異步命令行發送模版消息 $re = WechatMessage::add($template,"erp_options"); //dump($re); Log::notice("發送{$uuid_name}提交的{$type["title"]}審核模版消息成功!$re"); } ~~~ * 本類用到的部分方法 ~~~ static public function assignTemplate($name, $data = '') { $template = self::getTemplate($name); if (empty($data)){ return $template; }else{ try{ return View::instance()->display($template,$data); }catch (Exception $e){ Log::error($e->getMessage()); ob_get_clean(); throw $e; return false; } } } static public function getTemplate($name) { if (is_null(self::$instance)) { self::$instance = new static(); } if(isset(self::$instance->$name)){ return self::$instance->$name; }else{ return false; } } ~~~ 感謝大家關注 交流請加QQ群 321449759 ![](https://box.kancloud.cn/3499008a08e64306c68873288092a057_286x340.png)
                  <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>

                              哎呀哎呀视频在线观看