zoukankan      html  css  js  c++  java
  • 检测微信小程序输入内容是否合法~

          
        // 获取access_token
        public function _get_access_token() {
            $key = C('DB_NAME') . "_access_token_".C('APP_ID');
            $red = Red::create();
    
            if ($red->get($key)) {
                return $red->get($key);
            }
    
            $request_url = "https://api.weixin.qq.com/cgi-bin/token?";
            $request_url .= "grant_type=client_credential&appid=".C('APP_ID')."&secret=".C('APP_SECRET');
            $data = json_decode(Http::doGet($request_url,30),true);
    
            if ($data['access_token']){
                $red->set($key,$data['access_token'],(int)$data['expires_in']);      
                return $data['access_token'];
            }
    
            return '';
        }
    
    
        /**
         * 检测输入文字内容,是否合法~
         * 
         */
        public function check_input($checkContent){
            $access_token = $this->_get_access_token();
            if(!$access_token){
                $this->json->err('获取access_token失败');
            }
    
            //$checkContent = '今日犹存免费成人网站,题壁有诗皆抱恨';
    
            $url = 'https://api.weixin.qq.com/wxa/msg_sec_check?access_token='. $access_token;
            $data = json_encode(array('content' => $checkContent),JSON_UNESCAPED_UNICODE);
            $ch = curl_init();
            curl_setopt($ch, CURLOPT_HEADER, FALSE);
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
            curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
            curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
            curl_setopt($ch, CURLOPT_URL,$url); // url
            curl_setopt($ch, CURLOPT_POST, TRUE);
            curl_setopt($ch, CURLOPT_POSTFIELDS, $data); // json数据
            $res = curl_exec($ch); // 返回值
            curl_close($ch);
            $result = json_decode($res,true);
            
            if($result['errcode'] !== 0){
                $this->json->err('内容非法-' . $result['errmsg']);
            }
        }
    
    
    
  • 相关阅读:
    Ural 1966 Cycling Roads
    SQL Server 2008 安装(lpt亲测)
    cf Round#273 Div.2
    poj 2318 TOYS
    计算几何好模板
    ❤Friends
    限制pyqt5应用程序 只允许打开一次
    pyqt5 菜单栏+信息提示框
    Android Linux deploy
    system分区解锁
  • 原文地址:https://www.cnblogs.com/pansidong/p/13260863.html
Copyright © 2011-2022 走看看