post($url, ['userid' => $user_id], ['content-Type' => 'application/json']); } /** * 获取用户信息 * @param $mobile * @return mixed */ public static function get_user_info($mobile) { $token = self::getaccess_token(); $url = self::GETBYMOBILE_URL . '?access_token=' . $token; $data = ['mobile' => $mobile]; return (new GuzzleHttpRequester())->post($url, $data, ['content-Type' => 'application/json']); } //获取access_token public static function getaccess_token() { /** * 这里写死了,其他系统自行替换 */ // 发起请求获取 access_token $ding_config = getConfByType('ding_talk'); $dingappkey = $ding_config['dingappkey']; $dingappsecret = $ding_config['dingappsecret']; if (Cache::get('DingTalkToken')) { $access_token = Cache::get('DingTalkToken'); } else { $url = self::ACCESSTOKEN_URL . '?appkey=' . $dingappkey . '&appsecret=' . $dingappsecret; $res = (new GuzzleHttpRequester())->get($url, null, ['content-Type' => 'application/json']); if ($res['errcode'] == 0) { $access_token = $res['access_token']; Cache::set('DingTalkToken', $access_token, 71990); } } return $access_token; } /** * 删除钉钉推送 * @param $unionId * @param $tasks * @return mixed */ public static function delTask($unionId, $tasks) { $token = self::getaccess_token(); // 获取access_token $url = 'https://api.third.com/v1.0/todo/users/' . $unionId . '/tasks/' . $tasks . '?operatorId=' . $unionId; // 设置请求的url $header = ['x-acs-third-access-token' => $token, 'Content-Type' => 'application/json']; // 设置请求头 return (new GuzzleHttpRequester())->delete($url, $header); // 发送delete请求 } /** * 更新钉钉推送状态,如果该任务已经推送给用户,用户完成后可以调用该函数更新该任务状态 * @param $unionIds * @param $tasks * @return mixed */ public static function putTask($unionIds, $tasks) { $token = self::getaccess_token(); //获取access_token $url = self::TASK_URL . '/iSFXGc4dL7kPHpo97sJx8jAiEiE/tasks/' . $tasks . '?operatorId=iSFXGc4dL7kPHpo97sJx8jAiEiE'; //请求的url $header = ['x-acs-third-access-token' => $token, 'Content-Type' => 'application/json']; //设置请求头 $data['executorIds'] = $unionIds; //设置执行者id $data['done'] = true; //设置完成状态 return (new GuzzleHttpRequester())->put($url, $data, $header); //发起PUT请求 } /** * 获取用户信息 * @param $mobile * @return false|mixed */ public static function getUserInfo($mobile) { $get_user = self::get_user_info($mobile); if ($get_user['errcode'] != 0) { return false; } $get_unionId = self::get_unionid($get_user['result']['userid']); if ($get_unionId['errcode'] != 0) { return false; } return $get_unionId['result']['unionid']; } /** * 审批流创建钉钉代办,仅限审批流使用 * @param $unionIds * @param $title * @param $local_url * @param $approval_flow_line_id * @return mixed */ public static function createTaskDo($unionIds, $title, $local_url, $approval_flow_line_id=null) { // 获取access_token $token = self::getaccess_token(); // 设置请求的url $url = self::TASK_URL . '/iSFXGc4dL7kPHpo97sJx8jAiEiE/tasks'; // 设置请求头 $header =['x-acs-dingtalk-access-token'=>$token,'Content-Type'=>'application/json']; // 设置详情url $detailUrl = new \stdClass(); $detailUrl->pcUrl = $local_url; $detailUrl->appUrl = $local_url; // 设置通知配置 $notifyConfigs = new \stdClass(); $notifyConfigs->dingNotify = '1'; // 设置请求参数 $data = [ 'sourceId' => $approval_flow_line_id, 'subject' => $title, 'creatorId' => 'iSFXGc4dL7kPHpo97sJx8jAiEiE', 'executorIds' => $unionIds, 'description' => $title, 'detailUrl' => $detailUrl, 'isOnlyShowExecutor' => true, 'priority' => 40, 'notifyConfigs' => $notifyConfigs ]; // 发送post请求 return (new GuzzleHttpRequester())->post($url, $data, $header); } /** * 发送钉钉普通消息,仅仅通知使用,非代办消息 * @param $mobile * @param $message * @param $messageUrl * @return array */ public static function ding_send_message_normal($mobile, $title, $message, $messageUrl) { $ding_config = getConfByType('ding_talk'); $get_user = self::get_user_info($mobile); if ($get_user['errcode'] == 0) { $userId = $get_user['userid']; $accessToken = self::getaccess_token(); $url = self::SEEDMESSAGE_URL . '?access_token=' . $accessToken; $data = array( 'agent_id' => intval($ding_config['agent_id']), 'userid_list' => $userId, 'msg' => array( 'msgtype' => 'link', 'link' => array( 'picUrl' => '$iAEKAqNwbmcDBgTNAk', 'messageUrl' => $messageUrl, 'text' => $message, 'title' => $title, ) ) ); $return_res = (new GuzzleHttpRequester())->post($url, $data, null); if ($return_res['errcode'] == 0) { return ['code' => 0, 'msg' => '发送成功', 'data' => $return_res['task_id']]; } else { return ['code' => 1, 'msg' => $return_res['errmsg']]; } } else { return ['code' => 1, 'msg' => $get_user['errmsg']]; } } /** * 发送钉钉代办消息,会显示在钉钉代办里面 * @param $mobile * @param $message * @param $messageUrl * @return array */ public static function ding_send_message_do($mobile, $title, $message, $messageUrl) { // 获取access_token $token = self::getaccess_token(); // 设置请求的url $url = self::TASK_URL . '/iSFXGc4dL7kPHpo97sJx8jAiEiE/tasks'; // 设置请求头 $header =['x-acs-dingtalk-access-token'=>$token,'Content-Type'=>'application/json']; //根据收据获取unionid $userinfo = (new AdminUser())->select('unionId')->where('mobile','=',$mobile)->first()->toArray(); $user = self::get_user_info($mobile); if ($user['errcode'] == 0){ //如果不存在就更新unionid if (empty($userinfo['unionId'])){ $userinfo['unionId'] = $user['unionid']; $res = (new AdminUser())->where('mobile','=',$mobile)->update(['unionId'=>$user['unionid']]); } } $unionIds = array(); $unionIds[] = $userinfo['unionId']; // 设置详情url $detailUrl = new \stdClass(); $detailUrl->pcUrl = $messageUrl; $detailUrl->appUrl = $messageUrl; // 设置通知配置 $notifyConfigs = new \stdClass(); $notifyConfigs->dingNotify = '1'; // 设置请求参数 $data = [ 'subject' => $title, 'creatorId' => 'iSFXGc4dL7kPHpo97sJx8jAiEiE', 'executorIds' => $unionIds, 'description' => $message, 'detailUrl' => $detailUrl, 'isOnlyShowExecutor' => true, 'priority' => 40, 'notifyConfigs' => $notifyConfigs ]; // 发送post请求 return (new GuzzleHttpRequester())->post($url, $data, $header); } /** * {请求消息 * "file_hash": 数据哈希 * "file_data": 原数据, * "file_pubkey": 公钥, * "file_sign": 签名, * "file_time": 时间戳, * } * 应答消息 * 如果数据hash已经存在,返回: * { * 'error': '数据存在' * } * 如果数据hash不存在,返回: * { * 'blockHash': '0x9d4afaa7318d0a099bc74427cbe80527494b5e1c22500ef74d921f35bc77627d', * 'blockNumber': '0x11', * 'gasUsed': '0x201d2', * 'transactionHash': '0x80e2012e09e23aaa13df60add72cdf74b501a6a999060803d4e3c84360b69d8d', * 'contractname': '0x1f494c56c3ad1e6738f3500d19499cd3541160ea', * 'error': '0' * } */ public static function blockchainUpload($text) { // 设置请求的url $url = 'http://59.49.35.195:37400'; // 设置请求头 $header = ['Content-Type' => 'application/json']; #1.区块链公私钥生成 $crateParam = [ "key"=> 'shanxiluqiao2024', "account_password"=>'54953132d9162b52defef0cf7b790e3a',#用户自行设定的密码 ]; #应答消息 'prvkey': '私钥' 'address':地址, $crateRes= (new GuzzleHttpRequester())->post($url . '/api/p/medical/blockchain/crate', $crateParam, $header); #2.区块链私钥签名 $signParam = [ "prvkey"=> null,#私钥 "text"=>$text,#字符串 ]; $signParam['prvkey']=$crateRes['prvkey']; #应答消息 如果私钥正确 'sign': '签名' 反之 "error": '私钥格式不对' $signRes = (new GuzzleHttpRequester())->post($url . '/api/p/medical/blockchain/sign', $signParam, $header); #3.区块链公钥验签 $verifyParam = [ "sign"=>null,# 签名 "text"=>$text,#字符串 "address"=>null,#地址 ]; $verifyParam['sign']= $signRes['sign']; $verifyParam['address']=$crateRes['address']; #应答消息 如果公钥、签名格式正确 "status": '验证失败'/'验证一致' 反之格式错误 (new GuzzleHttpRequester())->post($url . '/api/p/medical/blockchain/verify', $verifyParam, $header); #4.区块链数据摘要 $hashParam = [ "text"=>$text,#字符串 ]; #请求消息 text 返回消息 "hash": 数据摘要 $hashRes= (new GuzzleHttpRequester())->post($url . '/api/p/medical/blockchain/hash', $hashParam, $header); #5数据上链 #数据上链 设置请求参数 $uploadParam = [ "file_hash"=> $hashRes['hash'],#数据哈希 "file_data"=> $text,#原数据 "file_pubkey"=> 'shanxiluqiao2024',#公钥 "file_sign"=> $signRes['sign'],#签名 "file_time"=> time(),#时间戳 ]; $res = (new GuzzleHttpRequester())->post($url . '/api/p/medical/blockchain/upload', $uploadParam, $header); // dump('请求最后一步'); return ['res'=>$res,'fileHash'=>$hashRes['hash']]; } /** * 请求消息 * "file_hash": 数据哈希 * 应答消息 * 如果数据hash不存在,返回: * 'error': '数据不存在' * 如果数据hash存在,返回: * { * "file_hash": 数据哈希 * "file_data": 原数据, * "file_pubkey": 公钥, * "file_sign": 签名, * "file_time": 时间戳, * 'blockHash': '0x9d4afaa7318d0a099bc74427cbe80527494b5e1c22500ef74d921f35bc77627d', * 'blockNumber': '0x11', * 'contractAddress': '0x1f494c56c3ad1e6738f3500d19499cd3541160ea', * 'gasUsed': '0x201d2', * 'transactionHash': '0x80e2012e09e23aaa13df60add72cdf74b501a6a999060803d4e3c84360b69d8d', * 'transactionIndex': '0x0' * } */ #数据查询 public static function blockchainDownload($file_hash) { // 设置请求的url $url = 'http://59.49.35.195:37400'. '/api/p/medical/blockchain/download'; // 设置请求头 $header = ['Content-Type' => 'application/json']; // 设置请求参数 $data = [ "file_hash"=>$file_hash,# 数据哈希 ]; // 发送post请求 return (new GuzzleHttpRequester())->post($url, $data, $header); } }