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

                ??一站式輕松地調用各大LLM模型接口,支持GPT4、智譜、豆包、星火、月之暗面及文生圖、文生視頻 廣告
                ``` <?php /** * Created by PhpStorm. * User: 項羽 * Date: 2019/1/16 * Time: 16:08 * QQ群:310325131 */ namespace app\api\controller; use think\cache\driver\Redis; class Sendmsg { /*獲取全局的token*/ public function ccs(){ $dd=$this->getAccessToken(); echo $dd; } /*存accesstoken*/ public function getAccessToken() { $isExpires = $this->isExpires(); if($isExpires === false){ //到期,獲取新的 $url = 'https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=' .config('appid') . '&secret=' . config('secret'); $res = $this->curl($url); // dump($res); $arr = json_decode($res,true); // return json($arr); if($arr && !isset($arr['errcode'])){ $arr['time'] = time(); file_put_contents(APP_PATH . '../access_token.json', json_encode($arr)); // var_dump($arr); return $arr['access_token']; }else{ echo 'error on get access_token';die; } }else{ return $isExpires; } } /*檢測是否過期*/ public function isExpires(){ if(!file_exists(APP_PATH . '../access_token.json')){ return false; } $res = file_get_contents(APP_PATH . '../access_token.json'); $arr = json_decode($res,true); if($arr && time()<(intval($arr['time'])+intval($arr['expires_in']))){ //未過期 return $arr['access_token']; }else{ return false; } } /*curl請求*/ public function curl($url) { //初始化 $ch = curl_init(); curl_setopt($ch, CURLOPT_URL,$url); // 執行后不直接打印出來 curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_HEADER, false); // 跳過證書檢查 curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); // 不從證書中檢查SSL加密算法是否存在 curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); //執行并獲取HTML文檔內容 $output = curl_exec($ch); //釋放curl句柄 curl_close($ch); return $output; } // 發送模板消息↙↙↙↙↙↙↙↙↙↙↙↙↙↙↙↙↙↙↙↙↙↙↙↙↙↙↙↙↙↙↙↙↙↙↙↙↙↙↙↙↙↙↙↙↙↙↙↙↙↙↙↙↙↙↙↙↙↙↙↙ /*獲取所有openid*/ public function sendall(){ //獲取access_token $access_token = $this->getAccessToken(); $url = "https://api.weixin.qq.com/cgi-bin/user/get?access_token={$access_token}&next_openid="; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL,$url); curl_setopt($ch, CURLOPT_RETURNTRANSFER,1); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER,0); $data = curl_exec($ch); $data = json_decode($data,true); return $data['data']['openid']; } /** * 發送模板消息 */ public function send_notice($openid){ //獲取access_token $access_token2=$this->getAccessToken(); //模板消息 $json_template = $this->json_tempalte($openid); $url="https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=".$access_token2; $res=$this->curl_post($url,urldecode($json_template)); return $res; } /** * 將模板消息json格式化 */ public function json_tempalte($openid){ //模板消息 $template=array( 'touser'=>$openid, //用戶openid 'template_id'=>"zTi9Y8omU9JovEI8yrX4LSMo8Yrm2EBpXD-rDU1T_tc", //在公眾號下配置的模板id 'url'=>"https://www.iqiyi.com/v_19rrmucyoc.html?vfm=2008_aldbd", //點擊模板消息會跳轉的鏈接 'topcolor'=>"#7B68EE", 'data'=>array( 'first'=>array('value'=>urlencode("通知通知:小區發起全民選舉投票了"),'color'=>"#4B0082"), 'keyword1'=>array('value'=>urlencode('2019年人人家智慧小區投票提醒'),'color'=>'#00BFFF'), //keyword需要與配置的模板消息對應 'keyword2'=>array('value'=>urlencode(date("Y-m-d H:i:s")),'color'=>'#00BFFF'), 'keyword3'=>array('value'=>urlencode('點擊詳情進入投票展示頁面'),'color'=>'#00BFFF'), 'remark' =>array('value'=>urlencode('備注:這是測試'),'color'=>'#B23AEE'), ) ); $json_template=json_encode($template); return $json_template; } /** * @param $url * @param array $data * @return mixed * curl請求 */ public function curl_post($url , $data=array()){ $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE); // POST數據 curl_setopt($ch, CURLOPT_POST, 1); // 把post的變量加上 curl_setopt($ch, CURLOPT_POSTFIELDS, $data); $output = curl_exec($ch); curl_close($ch); return $output; } /*獲取所有openid并存入redis*/ public function sendall_redis(){ $redis = new Redis(); //獲取access_token $access_token = $this->getAccessToken(); $url = "https://api.weixin.qq.com/cgi-bin/user/get?access_token={$access_token}&next_openid="; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL,$url); curl_setopt($ch, CURLOPT_RETURNTRANSFER,1); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER,0); $data = curl_exec($ch); $data = json_decode($data,true); foreach($data['data']['openid'] as $k=>$v){ $redis->rpush("openidlist1",$v); } } /*每次取出一個redis隊列中的值來進行操作*/ public function sendmsg_redis(){ $redis = new Redis(); $all_openid=array(); for ($i=1;$i<=300;$i++){ $val = $redis->lpop('openidlist1'); if ($val){ array_push($all_openid,$val); } } // echo json_encode($all_openid); /*查看所有的查出的opendi*/ foreach ($all_openid as $value) { $data= $this->send_notice(trim($value)); $data= json_decode($data,true); if ($data['errcode']==0){ return '發送成功'; }else{ return '發送失敗'; } } } /*TODO 這個地方需要加一個定時任務 另外配置好 appid secret 還需要在 think\cache\driver\Redis; 中添加以下幾個函數*/ /*↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓*/ /** * 將一個或多個值插入到列表頭部 * @param $key * @param $value * @return int */ /* public function lpush($key, $step){ return $this->handler->lPush($key, $step); }*/ /** * 將一個或多個值插入到列表尾部 * @param $key * @param $value * @return int */ /*public function rpush($key, $step){ return $this->handler->rPush($key, $step); }*/ /** * 移出并獲取列表的第一個元素 * @param string $key * @return string */ /*public function lpop($name){ $key = $this->getCacheKey($name); return $this->handler->lPop($key); }*/ } ```
                  <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>

                              哎呀哎呀视频在线观看