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

多媒体展厅seo对网站优化

多媒体展厅,seo对网站优化,wordpress内容新窗口打开,织梦图片网站源码开发之前必须把这张图了解透了&#xff0c;不然会容易做着做着懵&#xff0c;没有思路。 官方地址&#xff1a;https://developer.work.weixin.qq.com/document/path/98151 一、前端页面 login登录页&#xff0c; <template><view class"login-container&quo…

开发之前必须把这张图了解透了,不然会容易做着做着懵,没有思路。

官方地址:https://developer.work.weixin.qq.com/document/path/98151

一、前端页面

login登录页,

<template><view class="login-container"><button class="form-button wecom" @click="handleWecomLogin">企业微信登录</button></view>
</template>function handleWecomLogin() {const CORPID = 'ww7981ebca139e75f9'const REDIRECT_URI='https://datalab.ffep.online:20093/web/pages/index/callback'	// 返回授权登录码const AGENTID='1000086'// 生成授权URL// const authUrl = `https://open.weixin.qq.com/connect/oauth2/authorize?appid=${CORPID}&redirect_uri=${REDIRECT_URI}&response_type=code&scope=snsapi_base&agentid=${AGENTID}&state=login`;const authUrl = `https://login.work.weixin.qq.com/wwlogin/sso/login?login_type=CorpApp&appid=${CORPID}&redirect_uri=${REDIRECT_URI}&state=STATE&agentid=${AGENTID}`// 跳转到企业微信授权页面window.location.href = authUrl;}</script><style lang="scss" scoped>/*省略*/
</style>

callback回调页

<template><view></view>
</template><script setup lang="ts">
import { onLoad } from '@dcloudio/uni-app';
import request from '../../utils/hrAPI';onLoad(async (options) => {if (options.code) {try {// 使用授权码换取用户信息并登录// const res = await loginWithWecomCode(options.code);const res = await request({url: '/ffep/Wecom/loginWithWecomCode',method: 'POST',data: {code:options.code},requiresAuth:false});if (res.code === 1) {uni.setStorageSync('staffinfo', res.data.staffinfo);uni.showToast({ title: '登录成功', icon: 'success' });uni.reLaunch({ url: '/pages/index/index' });} else {uni.showToast({ title: res.msg, icon: 'none' });// uni.navigateBack();}} catch (error) {console.error('企业微信登录失败:', error);uni.showToast({ title: '网络错误,请重试', icon: 'none' });// uni.navigateBack();}} else {// uni.navigateBack();}
});
</script>

二、后端准备

准备一个控制器

<?php
namespace app\api\controller\ffep;use app\common\controller\Api;
use think\Db;
use think\Request;
use addons\wecom\library\Wecom as wecomService;
use think\Exception;
use think\Cache;
use app\admin\model\wecom\Staff;class Wecom extends Api
{protected $noNeedLogin = ['*'];protected $noNeedRight = ['*'];// IT尊享服务protected $app_id = "1000086";protected $app_secret = "T3jVYGDudwKnz3k1u50EXT3LhcOnUm5Z3cN-mXRutlo";protected $corpid;protected $corpsecret;public function __construct(){parent::__construct();// 企微的公司id和密钥$this->corpid = $config['corpid'];  $this->corpsecret = $config['secret']; }// callback回调页面会访问这个方法,请求用户idpublic function loginWithWecomCode(){// 注意这里要拿应用的accesstoken,查看token的权限地址https://developer.work.weixin.qq.com/devtool/query$accessToken = $this->getAppAccessToken($this->app_id,$this->app_secret);$code = $this->request->param('code',false);if($code){$url = "https://qyapi.weixin.qq.com/cgi-bin/auth/getuserinfo?access_token=$accessToken&code=$code";//发送一个POST请求并获取返回结果$result = \fast\Http::get($url);$result = json_decode($result);// dump($result);exit;if(isset($result->userid)){// 拿到用户userid的业务逻辑$userid = $result->userid;$staffinfo = Staff::where('userid',$userid)->find();if(!$staffinfo){$this->error('企业微信信息获取失败。请联系管理员');}else{// 获取成功的流程$this->success('授权成功',['staffinfo'=>$staffinfo]);}}else{$this->error('企业微信授权登录失败。请重试');}}}/*** 获取JS-SDK配置*/public function jssdkConfig(){// dump(Request::instance());exit;$url = $this->request->post('url');if (!$url) {$this->error('缺少URL参数');}try {$config = $this->getJssdkConfig($url);$this->success('获取成功', $config);} catch (Exception $e) {$this->error('获取失败: ' . $e->getMessage());}}/*** 生成JS-SDK配置*/private function getJssdkConfig($url){$corpid = $this->corpid;$corpsecret = $this->corpsecret;// 获取access_token$accessToken = $this->getAccessToken();// 获取jsapi_ticket$jsapiTicket = $this->getJsapiTicket($accessToken);// 生成签名$nonceStr = $this->createNonceStr();$timestamp = time();$signature = $this->generateSignature($jsapiTicket, $nonceStr, $timestamp, $url);return ['appId' => $corpid,'nonceStr' => $nonceStr,'timestamp' => $timestamp,'signature' => $signature,'jsApiList' => ['checkJsApi', 'scanQRCode'] // 需要使用的接口列表];}// 获取应用的accesstokenpublic function getAppAccessToken($agentid,$appsecret){$token = Cache::get($agentid.'_wecom_access_token');if (!$token) {$config = get_addon_config('wecom');$corpid = $this->corpid;$corpsecret = $appsecret;$url = "https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid={$corpid}&corpsecret={$corpsecret}";$result = $this->httpGet($url);$result = json_decode($result, true);if (isset($result['access_token'])) {$accessToken = $result['access_token'];Cache::set($agentid.'_wecom_access_token', $accessToken, 7100); // 提前100秒过期} else {throw new Exception('获取access_token失败: ' . json_encode($result));}}return $token;}/*** 获取access_token*/private function getAccessToken(){// 从缓存获取或重新请求$accessToken = Cache::get('wecom_access_token');if (!$accessToken) {$corpid = $this->corpid;$corpsecret = $this->corpsecret;$url = "https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid={$corpid}&corpsecret={$corpsecret}";$result = $this->httpGet($url);$result = json_decode($result, true);if (isset($result['access_token'])) {$accessToken = $result['access_token'];Cache::set('wecom_access_token', $accessToken, 7100); // 提前100秒过期} else {throw new Exception('获取access_token失败: ' . json_encode($result));}}return $accessToken;}/*** 获取jsapi_ticket*/private function getJsapiTicket($accessToken){// 从缓存获取或重新请求$jsapiTicket = Cache::get('wecom_jsapi_ticket');if (!$jsapiTicket) {$url = "https://qyapi.weixin.qq.com/cgi-bin/get_jsapi_ticket?access_token={$accessToken}";$result = $this->httpGet($url);$result = json_decode($result, true);if (isset($result['ticket'])) {$jsapiTicket = $result['ticket'];Cache::set('wecom_jsapi_ticket', $jsapiTicket, 7100); // 提前100秒过期} else {throw new Exception('获取jsapi_ticket失败: ' . json_encode($result));}}return $jsapiTicket;}/*** 生成签名*/private function generateSignature($jsapiTicket, $nonceStr, $timestamp, $url){$string = "jsapi_ticket={$jsapiTicket}&noncestr={$nonceStr}&timestamp={$timestamp}&url={$url}";return sha1($string);}/*** 创建随机字符串*/private function createNonceStr($length = 16){$chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";$str = "";for ($i = 0; $i < $length; $i++) {$str .= substr($chars, mt_rand(0, strlen($chars) - 1), 1);}return $str;}/*** HTTP GET请求*/private function httpGet($url){$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);$output = curl_exec($ch);curl_close($ch);return $output;}
}

三、实践过程中遇到的问题&解决办法

解决:

 

not allow to access from your ip

 

http://www.dtcms.com/wzjs/389927.html

相关文章:

  • 石家庄java开发做网站深圳网站建设专业乐云seo
  • 昆明网站建设哪家比较好外贸推广平台排名
  • 做网站有哪几种语言优化网站关键词的技巧
  • 网站制作与网站建设pdf广告seo是什么意思
  • 邯郸做移动网站的地方合肥百度关键词推广
  • 用c 做动态网站关键词优化seo外包
  • shopex网站搬家创建网站教程
  • asp网站怎么做三语阐述网络推广的主要方法
  • 网站建设售后支持郑州seo优化培训
  • 广东省建设厅网站网站开发的基本流程
  • 网站源代码安装广州:推动优化防控措施落地
  • 长春个人网站制作百度云搜索引擎入口
  • 怎么做自己的一个网站北京网站优化快速排名
  • 教育网站 前置审批公司员工培训内容有哪些
  • 注册个人工作室流程及费用泉州seo培训
  • 定制网络教研系统seo服务 文库
  • 做平面设计的网站有哪些交易平台官网
  • 定制网站制作公司怎么样宁波seo外包公司
  • 珠珠宝宝网网站站建建设设公司运营策划方案
  • 做家装的网站什么是软文写作
  • vue可以做pc网站吗百度网盘电脑版登录入口
  • cms管理手机网站谷歌推广seo
  • 专业营销型网站定制网页开发
  • 我要建立个人网站seo企业优化方案
  • 网络工作室图移动网站优化排名
  • 找人做网站需要什么软件网页搜索排名提升
  • 做本地网站赚钱吗制作电商网站
  • 国外免费b2b网站大全黄页百度快速收录教程
  • wordpress站群代软文推广收费
  • 攻略类型网站如何做产品营销河南整站关键词排名优化软件