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

网站复制详细的营销推广方案

网站复制,详细的营销推广方案,即墨做网站,深圳市政府信息公开网coze个人版token有效期最多30天,升级团队版或企业版后可设置token为长期。但是刷新token不是所有场景都适用,根据目前个人版权限,不支持工作流刷新token需要创建OAuth应用,创建时应用类型选择渠道,下载证书。在设置/发…

coze个人版token有效期最多30天,升级团队版或企业版后可设置token为长期。

但是刷新token不是所有场景都适用,根据目前个人版权限,不支持工作流

刷新token需要创建OAuth应用,创建时应用类型选择渠道,下载证书。

在设置/发布渠道中选择企业自定义渠道管理,添加平台时可选择发布的渠道。

token刷新代码:

JWTServer

<?php
namespace app\index\server;class jwtServer {private $key = "";private $algo = "HS256";private $kid = "";public function __construct($kid, $key, $type = "str") {$this->kid = $kid;$this->setkey($key, $type);}public function setkey($key, $type = "str") {$usekey = false;if ($type == "file") {$file = $key;if (!is_file($file)) {throw new \Exception("file:" . $file . "not exist");}$usekey = file_get_contents($file);}if ($type == "str") {if (!is_string($key) || empty($key)) {throw new \Exception("set key error");}$usekey = $key;}if (empty($usekey)) {throw new \Exception("set key fail");}$resource = openssl_pkey_get_private($usekey);if (!$resource) {throw new \Exception("key is not private key");}$this->key = $usekey;}public function setalgo($algo) {$this->algo = $algo;}/*** 生成字符串*/public function generate($payload) {if (empty($this->key)) {throw new \Exception("key not set");}$header = $this->getHeader();$payload = $this->getPayload($payload);$signature = $this->getSignature($header, $payload);$token = $header . "." . $payload . "." . $signature;return $token;}private function getHeader() {if (empty($this->kid)) {throw new \Exception("kid is empty");}$typ = "JWT";$data = ["alg" => $this->algo,"typ" => $typ,"kid" => $this->kid,];$headerJson = json_encode($data);$headerBase64 = $this->base64UrlEncode($headerJson);return $headerBase64;}private function getPayload($payload) {$payloadJson = json_encode($payload);$payloadBase64 = $this->base64UrlEncode($payloadJson);return $payloadBase64;}private function getSignature($headerBase64, $payloadBase64) {// $sign = $this->getSignEncryption($headerBase64, $payloadBase64);$sign = $this->getSignEncryption2($headerBase64, $payloadBase64);$signBase64 = $this->base64UrlEncode($sign);return $signBase64;}/*** 签名加密 废弃*/private function getSignEncryption($headerBase64, $payloadBase64) {if (empty($this->key)) {throw new \Exception("key not set");}$algo = $this->algo;$signStr = $headerBase64 . "." . $payloadBase64;$sign = hash_hmac($algo, $signStr, $this->key, true);return $sign;}public function getSignEncryption2($headerBase64, $payloadBase64) {if (empty($this->key)) {throw new \Exception("key not set");}$key = $this->key;$signStr = $headerBase64 . "." . $payloadBase64;openssl_sign($signStr, $encrypted, $key, OPENSSL_ALGO_SHA256);return $encrypted;}/*** Base64URL编码*/private function base64UrlEncode($data) {return rtrim(strtr(base64_encode($data), '+/', '-_'), '=');}/*** Base64URL解码*/private function base64UrlDecode($data) {return base64_decode(strtr($data, '-_', '+/'));}public function vertify($token) {$data = explode(".", $token);if (count($data) < 3) {throw new \Exception("token format error");}list($headerBase64, $payloadBase64, $signBase64) = $data;$header = json_decode($this->base64UrlDecode($headerBase64), true);$payload = json_decode($this->base64UrlDecode($payloadBase64), true);$sign = $this->base64UrlDecode($signBase64);// $signCheck = $this->getSignEncryption($headerBase64, $payloadBase64);$signCheck = $this->getSignEncryption2($headerBase64, $payloadBase64);if ($sign != $signCheck) {throw new \Exception("token error");}//验证时间if (isset($payload['exp'])) {if ($payload['exp'] > time()) {throw new \Exception("token Failure");}}return $payload;}
}

COZE获取token

amespace app\index\server;use app\index\model\businesstypemodel;
use think\Log;class cozeserver {private $oauth2token_url = "https://api.coze.cn/api/permission/oauth2/token";private function getoauthconfig() {$id = "id"; //id$key = "key"; //公钥指纹$pem_file = ROOT_PATH . "/private_key.pem";$config = ['id' => $id,'key' => $key,'pem_file' => $pem_file,];return $config;}public function gettoken($type, $username = "") {$config = $this->getoauthconfig();$s_jwt = new jwtServer($config['key'], $config['pem_file'], 'file');$s_jwt->setalgo("RS256");$max_day = 30;$time = time();$exp_time = strtotime("+$max_day days");$jti = getRandomStrings();$session_name = empty($username) ? "watercat" : $username;$payload = ["iss" => $config['id'], // OAuth 应用的 ID"aud" => "api.coze.cn", // 扣子 API 的 Endpoint"iat" => $time, // JWT 开始生效的时间,秒级时间戳"exp" => $exp_time, // JWT 过期时间,秒级时间戳"jti" => $jti, // 随机字符串,防止重放攻击"session_name" => $session_name, //用户在业务侧的 UID];$jwtstr = $s_jwt->generate($payload);$url = $this->oauth2token_url;$authorization = " Bearer " . $jwtstr;$header = ['Authorization:' . $authorization,'Content-Type: application/json',];$postdata = ["grant_type" => "urn:ietf:params:oauth:grant-type:jwt-bearer",// "duration_seconds" => 86399,//默认900秒// "scope" => "",];$data = json_encode($postdata, 320);$result = requestCurl($url, "post", $data, $header);Log::info($result);$jsondata = json_decode($result, true);if (isset($jsondata['error'])) {$msg = $jsondata['error_message'];throw new \Exception($msg);}//解析后数据return $jsondata;}
}

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

相关文章:

  • dede5.7微电影网站模板百度快速排名优化工具
  • 微信公众号怎么开通免费免费发布网站seo外链
  • 简单的企业网站phpb站推广入口2023
  • 网站排名seo培训公司官网怎么制作
  • 网站开发进度管理表外贸平台自建站
  • 哪几个做内贸的网站比较好一点百度seo分析工具
  • 理财 网站模板 html怎么在广告联盟接广告
  • 金华建设技工学校网站线上推广方案怎么写
  • 旅游网站建设的技术可行性百度网盘网址是多少
  • 首页百度杭州seo推广服务
  • 用帝国做的网站绍兴seo外包
  • 网站登录验证码显示不出来云巅seo
  • 医院做网站定位电商代运营十大公司排名
  • 伍佰亿网站建设深圳优化公司统高粱seo
  • 青州市网站建设电商平台怎么运营的
  • 帮人负责做网站叫什么工作品牌网络营销推广方案策划
  • 内衣网站建设详细方案小红书推广方案
  • 网页游戏网站链接怎么推广软件让别人下载
  • visual studio 开发网站开发外贸推广渠道有哪些
  • 义乌网八方资源家1688网商网郑州seo排名公司
  • 怎么设置网站栏目竞价外包托管费用
  • 广州网站建设 美词域名流量查询工具
  • 商城网站开发设计sem优化推广
  • 什么是网站实施哈尔滨关键词优化方式
  • 河北区做网站公司全网营销的公司
  • 网站建设一般怎么付款官网优化包括什么内容
  • 电子商务网站开发课程设计百度seo营销公司
  • 网站定制需求seo外链技巧
  • 免费营销网站制作搜索引擎国外
  • 涿鹿镇做网站企业站seo