From 048fc8ecf260687fe89ecbdd1ade1f78ddc47f6d Mon Sep 17 00:00:00 2001 From: wuhui_zzw <1760308791@qq.com> Date: Mon, 1 Jul 2024 08:55:08 +0800 Subject: [PATCH] =?UTF-8?q?=E5=90=88=E5=90=8C=E7=AE=A1=E7=90=86=E6=9A=82?= =?UTF-8?q?=E5=81=9C=E5=BC=80=E5=8F=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/common/services/FaDaDaServices.php | 293 +++++++++++++++++++++++++ 1 file changed, 293 insertions(+) create mode 100644 app/common/services/FaDaDaServices.php diff --git a/app/common/services/FaDaDaServices.php b/app/common/services/FaDaDaServices.php new file mode 100644 index 0000000..a76884d --- /dev/null +++ b/app/common/services/FaDaDaServices.php @@ -0,0 +1,293 @@ + $this->appid, + 'X-FASC-Sign-Type' => 'HMAC-SHA256', + 'X-FASC-Timestamp' => $millisecond, + 'X-FASC-Nonce' => '1719570699896n667e910bdab4e',//uniqid($millisecond.'n'), + 'X-FASC-Api-SubVersion' => '5.1', + // 'bizContent' => $bizContent ? json_encode($bizContent) : '', + ]; + $header = [ + 'Content-Type:application/x-www-form-urlencoded', + 'Cache-Control:no-cache', + 'Pragma:no-cache', + // 文档要求信息 + 'X-FASC-App-Id:'.$signData['X-FASC-App-Id'], + 'X-FASC-Sign-Type:'.$signData['X-FASC-Sign-Type'], + 'X-FASC-Timestamp:'.$signData['X-FASC-Timestamp'], + 'X-FASC-Nonce:'.$signData['X-FASC-Nonce'], + 'X-FASC-Api-SubVersion:'.$signData['X-FASC-Api-SubVersion'] + ]; + // 根据请求类型 使用不同的header信息 + if($requestType == 'access_token') { + $header[] = 'X-FASC-Grant-Type:client_credential'; + $signData['X-FASC-Grant-Type'] = 'client_credential'; + } + else { + $accessToken = $this->getAccessToken(); + $header[] = 'X-FASC-AccessToken:'.$accessToken; + $signData['X-FASC-AccessToken'] = $accessToken; + } + // 获取签名 + $header[] = 'X-FASC-Sign:'.$this->getSign($signData, $millisecond); + // 发起请求 + $result = curlPost($this->apiLink.$apiName, [],30, $header); + + + + debug($result); + + return $result; + } catch (\Exception $e) { + // Log::info('法大大 - 错误: ' . $e->getMessage()); + throw new ValidateException('法大大请求失败:' . $e->getMessage()); + } + } + // 获取签名 + private function getSign($data, $millisecond){ + // 对排序后的参数字符串计算摘要,sha256Hex + krsort($data); + $signStr = ''; + foreach($data as $key => $value){ + if(!empty($value) && $value != '') $signStr .= $key . '=' . $value . '&'; + } + $signText = hash('sha256', $signStr); + + + + + debug([$signText,$data,$millisecond]); + + + $secretSigning = hash_hmac('sha256', $this->appSecret, $millisecond, true); + + + + // 用时间戳计算临时签名密钥 + // $secretSigning = hash_hmac('sha256', $millisecond, mb_convert_encoding($this->appSecret, 'UTF-8')); + // $signature = strtolower(bin2hex(hash_hmac('sha256', $signText, $secretSigning))); + + + return strtolower(bin2hex(hash_hmac('sha256', $secretSigning, $signText, TRUE))); + + +// // 对排序后的参数字符串计算摘要,sha256Hex +// String signText = sha256Hex(paramToSignStr); +// // 用时间戳计算临时签名密钥 +// byte[] secretSigning = hmac256((appSecret).getBytes(UTF8), timestamp); +// // 计算参数签名并统一转换成小写 +// String signature = DatatypeConverter.printHexBinary(hmac256(secretSigning, signText)).toLowerCase(); + + + + + + + + return $signature; + } + // 获取访问凭证 + private function getAccessToken(){ + $result = $this->requestApi([],'/service/get-access-token', 'access_token'); + + + debug(['access_token' => $result]); + + // debug("获取访问凭证"); + + return ''; + } + + + + + // 获取个人授权链接 + public function getAuthUrl(){ + $bizContent = [ + // 个人用户在应用中的唯一标识,由集成方自定义,长度最大64个字符。 + 'clientUserId' => '', + ]; + $result = $this->requestApi($bizContent); + + + + debug([ + '获取个人授权链接', + '请求信息'=>$bizContent, + '返回结果'=>$result, + ]); + + + } + // 创建签署任务(基于签署任务模板) + public function createWithTemplate(){ + $bizContent = [ + // 该签署任务的发起方(扣费主体),需检查授权 + 'initiator' => [ + // 主体类型:corp: 企业;person: 个人 + 'idType' => '', + // 主体标识,长度最大64个字符 + // 如果idType为corp:代表应用系统上的企业用户,主体方是openCorpId所指定的企业 + // 如果idType为person:代表应用系统上的个人用户,主体方是openUserId所指定的个人; + 'openId' => '', + ], + // 签署任务主题。长度最大100个字符 + 'signTaskSubject' => '', + // 指定签署任务模板ID + 'signTemplateId' => '', + // 是否自动提交签署任务 + 'autoStart' => true, + // 是否自动定稿填写内容(在有填写参与方时生效) + 'autoFillFinalize' => true, + // 参与方列表 参与方信息 + 'actors' => [ + [ + 'actor' => [ + // 参与方标识。在同一个签署任务中,参与方标识唯一,不允许重复;例如:甲方、乙方、丙方 + 'actorId' => '', + // 参与方主体类型: corp: 企业;person: 个人 + 'actorType' => '', + // 参与方具体名称。长度最大128个字符。 + 'actorName' => '', + // 参与方权限 fill:填写;sign:签署;cc:抄送 + 'permissions' => ['fill','sign'], + // 参与方主体在应用上的OpenId;openCorpId/openUserId + 'actorOpenId' => '', + ], + ] + ], + ]; + + + + + $result = $this->requestApi($bizContent); + + + + debug([ + '创建签署任务(基于签署任务模板)', + '请求信息'=>$bizContent, + '返回结果'=>$result, + ]); + } + // 获取参与方签署链接 + public function actorGetUrl(){ + $bizContent = [ + // 签署任务ID + 'signTaskId' => '', + // 参与方标识。在同一个签署任务中,参与方标识唯一,不允许重复;例如:甲方、乙方、丙方 + 'actorId' => '', + // 应用系统中唯一确定登录用户身份的标识 + 'clientUserId' => '', + // 重定向地址,系统判断在非小程序环境下会跳转至该地址。 + // 'redirectUrl' => '', + // 小程序的重定向地址(微信和支付宝) + 'redirectMiniAppUrl' => '', + ]; + + + $result = $this->requestApi($bizContent); + debug([ + '获取参与方签署链接', + '请求信息'=>$bizContent, + '返回结果'=>$result, + ]); + + } + // 查询签署任务列表 + public function ownerGetList(){ + $bizContent = [ + // 签署任务发起方或参与方主体 + 'ownerId' => [ + // 主体类型:corp: 企业;person: 个人 + 'idType' => '', + // 主体标识,长度最大64个字符 + // 如果idType为corp:代表应用系统上的企业用户,主体方是openCorpId所指定的企业 + // 如果idType为person:代表应用系统上的个人用户,主体方是openUserId所指定的个人; + 'openId' => '', + ], + // 指定第几页,如果不传默从第一页返回。页码从1开始,即首页为1。 + 'listPageNo' => '', + // 指定每页多少条数据,如果不传默认为100,单页最大100 + 'listPageSize' => '', + ]; + + + $result = $this->requestApi($bizContent); + debug([ + '查询签署任务列表', + '请求信息'=>$bizContent, + '返回结果'=>$result, + ]); + } + // 查询签署任务详情 + public function ownerGetDetail(){ + $bizContent = [ + // 个人用户在应用中的唯一标识,由集成方自定义,长度最大64个字符。 + 'signTaskId' => '', + ]; + + $result = $this->requestApi($bizContent); + debug([ + '查询签署任务详情', + '请求信息'=>$bizContent, + '返回结果'=>$result, + ]); + } + // 获取签署文档下载地址 + public function ownerGetDownloadUrl(){ + $bizContent = [ + // 个人用户在应用中的唯一标识,由集成方自定义,长度最大64个字符。 + 'ownerId' => [ + // 主体类型:corp: 企业;person: 个人 + 'idType' => '', + // 主体标识,长度最大64个字符 + // 如果idType为corp:代表应用系统上的企业用户,主体方是openCorpId所指定的企业 + // 如果idType为person:代表应用系统上的个人用户,主体方是openUserId所指定的个人; + 'openId' => '', + ], + // 签署任务ID。下载单个任务文档时传此参数,直接返回下载链接。 + 'signTaskId' => '', + ]; + + + + + $result = $this->requestApi($bizContent); + debug([ + '获取签署文档下载地址', + '请求信息'=>$bizContent, + '返回结果'=>$result, + ]); + } + + + + + + // 测试 + public function test(){ + + + $this->requestApi([]); + } + +}