多应用+插件架构,代码干净,二开方便,首家独创一键云编译技术,文档视频完善,免费商用码云13.8K 广告
​ 1.获取AccessToken 封装类 ~~~php <?php namespace app\api\controller; use app\common\controller\Api; use think\Db; class Accesstoken extends Api{ protected $noNeedLogin = ['*']; protected $noNeedRight = ['*']; protected $appid; protected $secret; protected $accessUrl; public function __construct() { $this->appid=config('wxinfo.appId'); $this->secret=config('wxinfo.secretId'); $this->accessUrl = Config('wxinfo.accessUrl'); } public function get_access_token() { $res=Db::name('access_token')->find(); if($res){ if(time()>$res['create_time']+7000){ $access_token=self::create_access_token(); }else{ $access_token=$res['access_token']; } }else{ $access_token=$this->create_access_token(); } return $access_token; } public function create_access_token() { $url = sprintf($this->accessUrl,$this->appid,$this->secret); $result = $this->https_request($url); $wxResult = json_decode($result,true); if(empty($wxResult)){ return ['code'=>400,'msg'=>'获取AccessToken异常']; } $access_token=Db::name('access_token')->find(); if($access_token){ $res=Db::name('access_token')->where('id',$access_token['id'])->update(['access_token'=>$wxResult['access_token'],'create_time'=>time()]); }else{ $res=Db::name('access_token')->insert(['access_token'=>$wxResult['access_token'],'create_time'=>time()]); } if($res){ return $wxResult['access_token']; }else{ return false; } } #curl protected function https_request($url,$data = null){ if(function_exists('curl_init')){ $curl = curl_init(); curl_setopt($curl, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0); curl_setopt($curl, CURLOPT_URL, $url); curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE); curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE); curl_setopt($curl, CURLOPT_SSLVERSION, CURL_SSLVERSION_TLSv1); curl_setopt($curl, CURLOPT_FOLLOWLOCATION,1); if (!empty($data)){ curl_setopt($curl, CURLOPT_POST, 1); curl_setopt($curl, CURLOPT_POSTFIELDS, $data); } curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); $output = curl_exec($curl); curl_close($curl); return $output; }else{ return false; } } } ~~~ ![](data:image/gif;base64,R0lGODlhAQABAPABAP///wAAACH5BAEKAAAALAAAAAABAAEAAAICRAEAOw== "点击并拖拽以移动") 2.处理审核代码 ~~~php /*检测文本发布内容安全*/ $token=new Accesstoken(); $access_token=$token->get_access_token(); $url='https://api.weixin.qq.com/wxa/msg_sec_check?access_token='.$access_token; $res = $this->https_request($url,json_encode(['content'=>$data['title']],JSON_UNESCAPED_UNICODE)); $resArr = json_decode($res,true); if (isset($resArr['errcode']) && $resArr['errcode'] == 0){ }else{ return json(['code'=>400,'msg'=>'含有违法违规内容,不可发布']); } $res = $this->https_request($url,json_encode(['content'=>$data['content']],JSON_UNESCAPED_UNICODE)); $resArr = json_decode($res,true); if (isset($resArr['errcode']) && $resArr['errcode'] == 0){ }else{ return json(['code'=>400,'msg'=>'含有违法违规内容,不可发布']); } /*检测图片发布内容安全*/ if($img){ $newurl='https://api.weixin.qq.com/wxa/media_check_async?access_token='.$access_token; $list=explode(",",$img); foreach ($list as $k=>$v){ $res = $this->https_request($newurl,json_encode(['media_url'=>$v,'media_type'=>2],JSON_UNESCAPED_UNICODE)); $resimgArr = json_decode($res,true); trace('&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&'); trace($v); trace($resimgArr); trace('&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&'); if (isset($resimgArr['errcode']) && $resimgArr['errcode'] == 0){ }else{ return json(['code'=>400,'msg'=>'图片含有违法违规内容,不可发布']); } } } #curl protected function https_request($url,$data = null){ if(function_exists('curl_init')){ $curl = curl_init(); curl_setopt($curl, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0); curl_setopt($curl, CURLOPT_URL, $url); curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE); curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE); curl_setopt($curl, CURLOPT_SSLVERSION, CURL_SSLVERSION_TLSv1); curl_setopt($curl, CURLOPT_FOLLOWLOCATION,1); if (!empty($data)){ curl_setopt($curl, CURLOPT_POST, 1); curl_setopt($curl, CURLOPT_POSTFIELDS, $data); } curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); $output = curl_exec($curl); curl_close($curl); return $output; }else{ return false; } } ~~~ ![](data:image/gif;base64,R0lGODlhAQABAPABAP///wAAACH5BAEKAAAALAAAAAABAAEAAAICRAEAOw== "点击并拖拽以移动") 3.腾讯内容安全文档地址 [https://developers.weixin.qq.com/miniprogram/dev/api-backend/open-api/sec-check/security.imgSecCheck.html](https://developers.weixin.qq.com/miniprogram/dev/api-backend/open-api/sec-check/security.imgSecCheck.html "https://developers.weixin.qq.com/miniprogram/dev/api-backend/open-api/sec-check/security.imgSecCheck.html") [security.mediaCheckAsync | 微信开放文档](https://developers.weixin.qq.com/miniprogram/dev/api-backend/open-api/sec-check/security.mediaCheckAsync.html "security.mediaCheckAsync | 微信开放文档") [security.msgSecCheck | 微信开放文档](https://developers.weixin.qq.com/miniprogram/dev/api-backend/open-api/sec-check/security.msgSecCheck.html "security.msgSecCheck | 微信开放文档") ### 目前使用的是 security.mediaCheckAsync 跟 security.msgSecCheck,并且内容还要后台人工审核 ,security.mediaCheckAsync是异步的,不能及时反馈,所以弹框提示信息是这样的: 发布内容有图片,等待腾讯审核成功后可以显示 ​