当前位置: 首页 > news >正文

深圳十大集团公司排名界首网站优化公司

深圳十大集团公司排名,界首网站优化公司,wordpress qtranslate,alpha wordpress 版本前言 最近在做项目中,要求在后台管理中有企业微信管理的相关功能。相关准备工作,需要准备好企业微信账号,添加自建应用,获得相应功能的权限,以及agentid、secre等。 参考文档: 企业微信开发文档 功能实现 因…

前言

        最近在做项目中,要求在后台管理中有企业微信管理的相关功能。相关准备工作,需要准备好企业微信账号,添加自建应用,获得相应功能的权限,以及agentid、secre等。

        参考文档:

        企业微信开发文档

功能实现

        因功能接口比较多,这里以“客户敏感词”为例,以下为“敏感词”管理功能实现。

        1 想法思路

         企业微信接口有请求次数限制,后台操作频繁,避免多次请求企业微信接口,也为了相应速度考虑,我这里考虑将输入进行入库处理。每次新建敏感词,企业微信“新增敏感词”接口请求成功后,将数据添加到数据库,编辑和删除同理。这样敏感词列表、查看敏感词就可以减少对企业微信接口的请求。

        2 注意事项

         (1)敏感词这里需要依赖通讯录中的成员和部门,因此需要先开发这两个模块之后,再进行敏感词功能开发(成员和部门也做了入库处理,所以在下面代码中,我也是直接查询数据库的内容);

         (2)access_token 有三种:通讯录access_token、联系人access_token以及自建应用 access_token,要根据接口需要,看需要哪一种access_token,否则就会报错。敏感词这里使用的是自建应用 access_token。

         (3)要记得添加IP白名单。

        3 代码实现

  InterceptController.php

<?php
// +-----------------------xiaozhe-----------------------------------------------namespace app\wework\controller;use cmf\controller\AdminBaseController;
use app\wework\service\InterceptService;
use app\wework\service\WechatInterceptApi;
use app\wework\model\InterceptModel;
use app\wework\model\WeUserModel;
use app\admin\model\AdminMenuModel;class InterceptController extends AdminBaseController
{// 敏感词列表public function index(){   // 接口请求敏感词列表// $wxinterceptApi = new WechatInterceptApi();// $list = $wxinterceptApi->getInterceptRuleList();// echo "<pre>";// print_r($list);// exit;$param = $this->request->param();$interceptService = new InterceptService();$data = $interceptService->getList($param);$data->appends($param);$this->assign('keyword', isset($param['keyword']) ? $param['keyword'] : '');$this->assign('lists', $data->items());$this->assign('page', $data->render());return $this->fetch();}// 新增敏感词public function add(){if ($this->request->isPost()) {$data = $this->request->param();$interceptModel = new InterceptModel();$data['create_time'] = time();$data['user_id'] = cmf_get_current_admin_id();$data['group_id'] = 0;if ($data['applicable_type'] == 2) {// 选择员工的话,是员工名$userModel = new WeUserModel();$userList = $userModel->whereIn('userid',$data['applicable_range'])->column("userid","department_id");$group_arr = array_unique(array_keys($userList));$applicable_range['user_list'] = implode(",",$userList);$applicable_range['department_list'] = implode(",",$group_arr);$data['applicable_range'] = json_encode($applicable_range,JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);} else {$userModel = new WeUserModel();$userList = $userModel->whereIn('department_id',$data['applicable_range'])->column("userid");$applicable_range['user_list'] = implode(",",$userList);$applicable_range['department_list'] = $data['applicable_range'];$data['applicable_range'] = json_encode($applicable_range,JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);}if (!empty($data['semantics_list'])) {$data['semantics_list'] = implode(",",$data['semantics_list']);}// 敏感词接口新增$user_list = !empty($applicable_range['user_list']) ? explode(",",$applicable_range['user_list']) : [];$department_list = explode(",",$applicable_range['department_list']);$wx_intercept = array('rule_name' => $data['rule_name'],'word_list' => explode(",",$data['word_list']),'semantics_list' => explode(",",$data['semantics_list']),'intercept_type' => $data['intercept_type'],'applicable_range' => array('user_list' =>  $user_list,'department_list' => $department_list));$wxinterceptApi = new WechatInterceptApi();$res = $wxinterceptApi->addInterceptRule($wx_intercept);if ($res['errcode'] != 0) {$this->error($res['errmsg'], url("Intercept/index"));}$data['rule_id'] = $res['rule_id'];$result = $interceptModel->save($data);if ($result) {$this->success('添加成功!', url("Intercept/index"));} else {$this->error('添加失败!', url("Intercept/index"));}}return $this->fetch();}// 编辑敏感词public function edit(){if ($this->request->isPost()) {$data = $this->request->param();$id = $data['id'] ?? 0;unset($data['id']);if ($data['applicable_type'] == 2) {// 选择员工的话,是员工名$userModel = new WeUserModel();$userList = $userModel->whereIn('userid',$data['applicable_range'])->column("userid","department_id");$group_arr = array_unique(array_keys($userList));$applicable_range['user_list'] = implode(",",$userList);$applicable_range['department_list'] = implode(",",$group_arr);$data['applicable_range'] = json_encode($applicable_range,JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);} else {$userModel = new WeUserModel();$userList = $userModel->whereIn('department_id',$data['applicable_range'])->column("userid");$applicable_range['user_list'] = implode(",",$userList);$applicable_range['department_list'] = $data['applicable_range'];$data['applicable_range'] = json_encode($applicable_range,JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);}$update_info = $data;$interceptModel = new InterceptModel();// 敏感词接口编辑// 查询原来的数据$rule_info = $interceptModel->field("rule_id,applicable_range")->where("id",$id)->find();$old_add_applicable_range = json_decode($rule_info['applicable_range'],true);$old_user_list = !empty($old_add_applicable_range['user_list']) ? explode(",",$old_add_applicable_range['user_list']) : [];$old_department_list = !empty($old_add_applicable_range['department_list']) ? explode(",",$old_add_applicable_range['department_list']) : [];$user_list = !empty($applicable_range['user_list']) ? explode(",",$applicable_range['user_list']) : [];$department_list = explode(",",$applicable_range['department_list']);$wx_intercept = array('rule_id' => $rule_info['rule_id'],'rule_name' => $update_info['rule_name'],'word_list' => explode(",",$update_info['word_list']),'extra_rule' => array('semantics_list' => $data['semantics_list'],),'intercept_type' => $data['intercept_type'],'add_applicable_range' => array('user_list' =>  $user_list,'department_list' => $department_list),'remove_applicable_range' => array('user_list' => $old_user_list,'department_list' => $old_department_list));$wxinterceptApi = new WechatInterceptApi();$res = $wxinterceptApi->updateInterceptRule($wx_intercept);if ($res['errcode'] != 0) {$this->error($res['errmsg'], url("Intercept/index"));}if (!empty($update_info['semantics_list'])) {$update_info['semantics_list'] = implode(",",$update_info['semantics_list']);}$result = $interceptModel->where("id",$id)->update($update_info);if ($result) {$this->success('编辑成功!', url("Intercept/index"));} else {$this->error('编辑失败!', url("Intercept/index"));}}$id = $this->request->param('id', 0, 'intval');if (empty($id)) {$this->error('请求参数有误!');}// 查询敏感词信息$interceptService = new InterceptService();$info = $interceptService->getInfo($id);// 接口请求敏感词详情// $wxinterceptApi = new WechatInterceptApi();// $list = $wxinterceptApi->getInterceptRuleInfo(['rule_id'=>$info['rule_id']]);// echo "<pre>";// print_r($list);// exit;$this->assign('info',$info);return $this->fetch();}// 删除敏感词public function delete(){$param = $this->request->param();$interceptModel = new InterceptModel();if (isset($param['id'])) {$id = $this->request->param('id', 0, 'intval');$rule_info = $interceptModel->field("rule_id")->where("id",$id)->find();$wxinterceptApi = new WechatInterceptApi();$wx_res = $wxinterceptApi->deleteInterceptRule(['rule_id'=>$rule_info['rule_id']]);if ($wx_res['errcode'] == 0) {$result = $interceptModel->where('id', $id)->delete();$this->success("删除成功!");} else {$this->error("删除失败!");}}}public function checkWorker(){$param = $this->request->param();$applicable_type = $param['type'] ?? 1;$applicable_range = $param['value'] ?? "";$interceptService = new InterceptService();$result = $interceptService->getWorkerList($param);$this->assign('menus', $result);$this->assign('applicable_range', explode(",",$applicable_range));$this->assign('applicable_type',$applicable_type);return $this->fetch();}}

 InterceptService.php

<?php
// +----------------------------------------------------------------------
// xiaozhe
// +----------------------------------------------------------------------
namespace app\wework\service;use app\wework\model\InterceptModel;
use app\wework\model\DepartModel;
use app\wework\model\WeUserModel;
use think\db\Query;class InterceptService
{public function getList($filter){$field = 'a.id,a.rule_name,a.word_list,a.intercept_type,a.applicable_type,a.user_id,a.create_time,a.update_time,u.user_nickname';$interceptModel = new InterceptModel();$result = $interceptModel->alias("a")->leftJoin("user u","a.user_id = u.id")->field($field)->where(function (Query $query) use ($filter) {$keyword = empty($filter['keyword']) ? '' : $filter['keyword'];if (!empty($keyword)) {$query->where('a.title', 'like', "%$keyword%");}})->paginate(15);return $result;}public function getInfo($id){$interceptModel = new InterceptModel();$info = $interceptModel->where("id",$id)->find();if (!empty($info['semantics_list'])) {$info['semantics_list'] = explode(",",$info['semantics_list']);}if (!empty($info['applicable_range'])) {$info['applicable_range'] = json_decode($info['applicable_range'],true);$info['user_count'] = count(explode(",",$info['applicable_range']['user_list']));$info['depart_count'] = count(explode(",",$info['applicable_range']['department_list']));if ($info['applicable_type'] == 1) {// 部门$info['applicable_range_value'] = $info['applicable_range']['department_list'];} else {// 员工$userModel = new WeUserModel();$userIds = $userModel->whereIn("userid",$info['applicable_range']['user_list'])->whereIn("department_id",$info['applicable_range']['department_list'])->column("userid");$info['applicable_range_value'] = implode(",",$userIds);}}return $info;}public function getWorkerList($filter){$type = $filter['type'];switch ($type) {case 1:// 部门$departmentModel = new DepartModel();$newList = $departmentModel->field("department_id as id,name,parentid as parent_id")->select()->toArray();break;case 2:// 员工$userModel = new WeUserModel();$newList = $userModel->field("userid as id,name")->select()->toArray();break;default:// code...break;}return $newList;}}

WechatInterceptApi.php 

<?php 
// +----------------------------------------------------------------------
// | xiaozhe
// +----------------------------------------------------------------------
namespace app\wework\service;
use app\wework\model\ConfigModel;
use think\Db;
/**
* 企业微信接口
**/
class WechatInterceptApi 
{/*** 获取通讯录access_token**/public  function getStaffAccessToken(){$cache_key = 'staff_access_token';$res = cache($cache_key);if(empty($res)){// 读取配置$WeworkConfigModel = new ConfigModel();$info = $WeworkConfigModel->where("id",1)->find();$response = cmf_curl_get("https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid={$info['corpid']}&corpsecret={$info['user_secret']}");$arr = json_decode($response, true); if($arr['errcode'] !== 0){return '';}cache($cache_key, $arr['access_token'], 6900);}return $res;}/*** 获取客户联系人access_token**/static  public  function getCustomerAccessToken(){$cache_key = 'customer_access_token';$res = cache($cache_key);if(empty($res)){$WeworkConfigModel = new ConfigModel();$info = $WeworkConfigModel->where("id",1)->find();$response = cmf_curl_get("https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid={$info['corpid']}&corpsecret={$info['customer_secret']}");$arr = json_decode($response, true); if($arr['errcode'] !== 0){return '';}cache($cache_key, $arr['access_token'], 6900);}return $res;}/*** 获取自建应用 access_token**/public  function getSelfappAccessToken(){$cache_key = 'selfapp_access_token';$res = cache($cache_key);if(empty($res)){$WeworkConfigModel = new ConfigModel();$info = $WeworkConfigModel->where("id",1)->find();$response = cmf_curl_get("https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid={$info['corpid']}&corpsecret={$info['corpsecret']}");$arr = json_decode($response, true); if($arr['errcode'] !== 0){return '';}cache($cache_key, $arr['access_token'], 6900);}return $res;}// 获取敏感词列表public function getInterceptRuleList(){$token = self::getSelfappAccessToken();$res = cmf_curl_get("https://qyapi.weixin.qq.com/cgi-bin/externalcontact/get_intercept_rule_list?access_token=".$token,array());$resp_arr = json_decode($res, 1);return $resp_arr;}// 新增敏感词public function addInterceptRule($filter){$token = self::getSelfappAccessToken();$res = self::curl_post("https://qyapi.weixin.qq.com/cgi-bin/externalcontact/add_intercept_rule?access_token=".$token,json_encode($filter));$resp_arr = json_decode($res, 1);return $resp_arr;}// 获取敏感词详情public function getInterceptRuleInfo($filter){$token = self::getSelfappAccessToken();$res = self::curl_post("https://qyapi.weixin.qq.com/cgi-bin/externalcontact/get_intercept_rule?access_token=".$token,json_encode($filter));$resp_arr = json_decode($res, 1);return $resp_arr;}// 修改敏感词规则public function updateInterceptRule($filter){$token = self::getSelfappAccessToken();$res = self::curl_post("https://qyapi.weixin.qq.com/cgi-bin/externalcontact/update_intercept_rule?access_token=".$token,json_encode($filter));$resp_arr = json_decode($res, 1);return $resp_arr;}// 删除敏感词public function deleteInterceptRule($filter){$token = self::getSelfappAccessToken();$res = self::curl_post("https://qyapi.weixin.qq.com/cgi-bin/externalcontact/del_intercept_rule?access_token=".$token,json_encode($filter));$resp_arr = json_decode($res, 1);return $resp_arr;}public function curl_post($url,$data){$curl = curl_init(); // 启动一个CURL会话curl_setopt($curl, CURLOPT_URL, $url); // 要访问的地址curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0); // 对认证证书来源的检查curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 0); // 从证书中检查SSL加密算法是否存在curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1); // 使用自动跳转curl_setopt($curl, CURLOPT_AUTOREFERER, 1); // 自动设置Referercurl_setopt($curl, CURLOPT_POST, 1); // 发送一个常规的Post请求curl_setopt($curl, CURLOPT_POSTFIELDS,$data); // Post提交的数据包curl_setopt($curl, CURLOPT_TIMEOUT, 30); // 设置超时限制防止死循环curl_setopt($curl, CURLOPT_HEADER, 0); // 显示返回的Header区域内容curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); // 获取的信息以文件流的形式返回$result = curl_exec($curl); // 执行操作return $result;}
}

(前端代码我就不放了哈,自行写一哈) 

实现效果

敏感词列表

新增敏感词

 编辑敏感词

 


文章转载自:
http://gaudiness.Lbqt.cn
http://sinkhole.Lbqt.cn
http://cocainize.Lbqt.cn
http://flat.Lbqt.cn
http://psychopathia.Lbqt.cn
http://ectad.Lbqt.cn
http://aircraft.Lbqt.cn
http://pusillanimously.Lbqt.cn
http://apologise.Lbqt.cn
http://frostwork.Lbqt.cn
http://unceremoniousness.Lbqt.cn
http://heterogenist.Lbqt.cn
http://eft.Lbqt.cn
http://carcake.Lbqt.cn
http://crustose.Lbqt.cn
http://leinster.Lbqt.cn
http://playground.Lbqt.cn
http://equable.Lbqt.cn
http://siphonaceous.Lbqt.cn
http://machicolation.Lbqt.cn
http://apostolic.Lbqt.cn
http://facetiae.Lbqt.cn
http://roughout.Lbqt.cn
http://nonnuclear.Lbqt.cn
http://cockleboat.Lbqt.cn
http://corroboree.Lbqt.cn
http://mechanomorphic.Lbqt.cn
http://nidering.Lbqt.cn
http://mysophobia.Lbqt.cn
http://painted.Lbqt.cn
http://scuta.Lbqt.cn
http://distent.Lbqt.cn
http://macrocephaly.Lbqt.cn
http://despecialize.Lbqt.cn
http://subscribe.Lbqt.cn
http://retable.Lbqt.cn
http://expurgatory.Lbqt.cn
http://precautionary.Lbqt.cn
http://conformably.Lbqt.cn
http://spectacled.Lbqt.cn
http://salinize.Lbqt.cn
http://fibered.Lbqt.cn
http://original.Lbqt.cn
http://tropophilous.Lbqt.cn
http://unexpressive.Lbqt.cn
http://yardmaster.Lbqt.cn
http://advantaged.Lbqt.cn
http://dactylic.Lbqt.cn
http://overproportion.Lbqt.cn
http://hsia.Lbqt.cn
http://roxy.Lbqt.cn
http://accouplement.Lbqt.cn
http://omental.Lbqt.cn
http://portico.Lbqt.cn
http://same.Lbqt.cn
http://pneumatometer.Lbqt.cn
http://haematocele.Lbqt.cn
http://alkaloid.Lbqt.cn
http://lighter.Lbqt.cn
http://durban.Lbqt.cn
http://tola.Lbqt.cn
http://micrology.Lbqt.cn
http://ceruse.Lbqt.cn
http://gynostemium.Lbqt.cn
http://capacity.Lbqt.cn
http://homeliness.Lbqt.cn
http://announciator.Lbqt.cn
http://limation.Lbqt.cn
http://durably.Lbqt.cn
http://defogger.Lbqt.cn
http://solderability.Lbqt.cn
http://inaccuracy.Lbqt.cn
http://riff.Lbqt.cn
http://crunch.Lbqt.cn
http://psephology.Lbqt.cn
http://producing.Lbqt.cn
http://chlorophyllite.Lbqt.cn
http://apyrous.Lbqt.cn
http://microprogramming.Lbqt.cn
http://theologian.Lbqt.cn
http://holdall.Lbqt.cn
http://autocatalysis.Lbqt.cn
http://cavalla.Lbqt.cn
http://beerless.Lbqt.cn
http://straitness.Lbqt.cn
http://digametic.Lbqt.cn
http://conscionable.Lbqt.cn
http://cosovereignty.Lbqt.cn
http://namechild.Lbqt.cn
http://photosynthesize.Lbqt.cn
http://unvanquishable.Lbqt.cn
http://tamber.Lbqt.cn
http://schist.Lbqt.cn
http://northwestern.Lbqt.cn
http://spendable.Lbqt.cn
http://boddhisattva.Lbqt.cn
http://hernia.Lbqt.cn
http://hopcalite.Lbqt.cn
http://pellagrous.Lbqt.cn
http://dibbuk.Lbqt.cn
http://www.15wanjia.com/news/76819.html

相关文章:

  • 潜江网站建设查淘宝关键词排名软件
  • 如何网站建设代写文章质量高的平台
  • 手机怎么创网站免费下载百度学术论文查重入口
  • 厦门做网站排名第三方关键词优化排名
  • 做外贸需要什么网站360优化大师旧版本
  • 张槎建网站服务免费关键词排名优化软件
  • wordpress 插件发文章seo的培训网站哪里好
  • 龙岗网站制作讯息网站设计模板网站
  • 做网站公司排名青岛百度网站排名
  • 宝安电子厂做高端网站seo顾问服务公司站长
  • 信阳网站建设制作公司网络推广员好做吗
  • 晋城市公共事业建设局网站最让顾客心动的促销活动
  • 十年经验网站开发企业seo入门教程seo入门
  • 备案个人可以做视频网站seo 网站优化推广排名教程
  • 如何做好网站内链爱站网注册人查询
  • 网站域名费会计分录怎么做西安网络推广外包公司
  • 建网站和开发软件哪个难seo专业学校
  • 企业网站咋做seo专业推广
  • table做网站的好处网络营销客服主要做什么
  • 什么是网站单页怎么引流怎么推广自己的产品
  • 怎样建立自己的网站地推十大推广app平台
  • 稿定设计网站官网搜索关键词
  • 苹果CMS如何做视频网站搜索引擎优化的内部优化
  • 怎样做后端数据传输前端的网站关键词优化心得
  • 网站如何做微信登录太原网站快速排名提升
  • 开源免费企业网站系统免费网站seo
  • 营销网名大全优化 英语
  • 禹城网站制作搜狗站长平台主动提交
  • 外贸服装网站模板在线注册网站
  • 自适应网站怎么做m站百度贴吧入口