From e8da9439a4491772cccf24e1d174e9d274546180 Mon Sep 17 00:00:00 2001 From: weiz Date: Tue, 7 Nov 2023 14:04:12 +0800 Subject: [PATCH] fixed --- extend/.gitignore | 2 - .../junziqian/sdk/bean/Req2MapInterface.php | 52 +++++++++ .../sdk/bean/req/sign/ApplySignReq.php | 110 ++++++++++++++++++ .../sdk/bean/req/sign/ext/SequenceInfo.php | 31 +++++ .../sdk/bean/req/sign/ext/SignatoryReq.php | 88 ++++++++++++++ .../bean/req/user/OrganizationCreateReq.php | 75 ++++++++++++ .../req/user/OrganizationFaceCreateReq.php | 42 +++++++ extend/junziqian/sdk/util/Assert.php | 55 +++++++++ extend/junziqian/sdk/util/CommonUtil.php | 45 +++++++ extend/junziqian/sdk/util/RequestUtils.php | 106 +++++++++++++++++ extend/junziqian/sdk/util/ShaUtils.php | 56 +++++++++ .../util/exception/ResultInfoException.php | 30 +++++ .../sdk/util/http/HttpClientUtils.php | 89 ++++++++++++++ 13 files changed, 779 insertions(+), 2 deletions(-) delete mode 100644 extend/.gitignore create mode 100644 extend/junziqian/sdk/bean/Req2MapInterface.php create mode 100644 extend/junziqian/sdk/bean/req/sign/ApplySignReq.php create mode 100644 extend/junziqian/sdk/bean/req/sign/ext/SequenceInfo.php create mode 100644 extend/junziqian/sdk/bean/req/sign/ext/SignatoryReq.php create mode 100644 extend/junziqian/sdk/bean/req/user/OrganizationCreateReq.php create mode 100644 extend/junziqian/sdk/bean/req/user/OrganizationFaceCreateReq.php create mode 100644 extend/junziqian/sdk/util/Assert.php create mode 100644 extend/junziqian/sdk/util/CommonUtil.php create mode 100644 extend/junziqian/sdk/util/RequestUtils.php create mode 100644 extend/junziqian/sdk/util/ShaUtils.php create mode 100644 extend/junziqian/sdk/util/exception/ResultInfoException.php create mode 100644 extend/junziqian/sdk/util/http/HttpClientUtils.php diff --git a/extend/.gitignore b/extend/.gitignore deleted file mode 100644 index c96a04f0..00000000 --- a/extend/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -* -!.gitignore \ No newline at end of file diff --git a/extend/junziqian/sdk/bean/Req2MapInterface.php b/extend/junziqian/sdk/bean/Req2MapInterface.php new file mode 100644 index 00000000..c2857199 --- /dev/null +++ b/extend/junziqian/sdk/bean/Req2MapInterface.php @@ -0,0 +1,52 @@ + $value) { + if(is_null($value)){ + continue; + }else if($ignoreParams!=null&&in_array($key, $ignoreParams)){ + continue; + }else if(is_a($value,'CURLFile')){ + $array[$key] = $value;//文件直接处理 + }else if(is_array($value)){ + $array[$key] = CommonUtil::json_encode($value);//文件直接处理 + }else if(is_a($value,"com\junziqian\sdk\bean\Req2MapInterface")){ + $array[$key] = CommonUtil::json_encode($value);// + }else if(is_object($value)){ + //is_object 对数字、数组等都是返回false + $array[$key] = CommonUtil::json_encode($value);// + }else{ + if(is_string($value)&&""==$value){ + continue; + } + $array[$key] = $value;//文件直接处理 + } + } + return $array; + } +} \ No newline at end of file diff --git a/extend/junziqian/sdk/bean/req/sign/ApplySignReq.php b/extend/junziqian/sdk/bean/req/sign/ApplySignReq.php new file mode 100644 index 00000000..0c604f74 --- /dev/null +++ b/extend/junziqian/sdk/bean/req/sign/ApplySignReq.php @@ -0,0 +1,110 @@ +attachFiles!=null&&sizeof($this->attachFiles)>0){ + $i=0; + foreach($this->attachFiles as $value){ + $arr["attachFiles[".$i."]"]=$value; + $i = $i+1; + } + } + return $arr; + } + +} \ No newline at end of file diff --git a/extend/junziqian/sdk/bean/req/sign/ext/SequenceInfo.php b/extend/junziqian/sdk/bean/req/sign/ext/SequenceInfo.php new file mode 100644 index 00000000..6deb37e8 --- /dev/null +++ b/extend/junziqian/sdk/bean/req/sign/ext/SequenceInfo.php @@ -0,0 +1,31 @@ +businessNo = $businessNo; + $this->sequenceOrder = $sequenceOrder; + $this->totalNum = $totalNum; + } + +} \ No newline at end of file diff --git a/extend/junziqian/sdk/bean/req/sign/ext/SignatoryReq.php b/extend/junziqian/sdk/bean/req/sign/ext/SignatoryReq.php new file mode 100644 index 00000000..44cc7800 --- /dev/null +++ b/extend/junziqian/sdk/bean/req/sign/ext/SignatoryReq.php @@ -0,0 +1,88 @@ +serviceUrl = $serviceUrl; + $this->appkey = $appkey; + $this->appSecret = $appSecret; + $this->encryMethod = $encryMethod; + $this->tsType = $tsType; + if(!is_null($this->encryMethod)){ + $this->encryMethod=strtolower($this->encryMethod); + } + } + + /** + * @param $path + * @return object + */ + public function doPost($path,$req=null){ + Assert::notBlank($path,"path不能为空"); + $url=$this->serviceUrl.$path; + if($req==null){ + $req=Array(); + }else if(is_array($req)){ + // + }else if(is_a($req,"junziqian\sdk\bean\Req2MapInterface")){ + $req=$req->build(); + }else{ + throw new ResultInfoException("不支持的请求req"); + } + $req=$this->fillSign($req); + // Log::error([$url,json_encode($req)]); + //请求服务端sass + // halt($url,$req); + //print_r(CommonUtil::json_encode($req)); + $response= HttpClientUtils::getPost($url,$req); + $res=json_decode($response); + Assert::notNull($res,"不能转换为JSON:".$response); + return $res; + } + + /** + * 填充签名数据 + * @param $req array + */ + public function fillSign($req){ + /**默认加密方式:不输入使用sha256,其它可选择项md5,sha1,sha3-256*/ + $ts=time(); + if($this->tsType==1){ + $ts=$ts*1000; + } + $sign=null; + $nonce= md5($ts.""); + $signSrc="nonce".$nonce."ts".$ts."app_key".$this->appkey."app_secret".$this->appSecret; + if($this->encryMethod==null||$this->encryMethod=="sha256"){ + $sign=ShaUtils::getSha256($signSrc); + }else if($this->encryMethod=="sha1"){ + $sign=ShaUtils::getSha1($signSrc); + }else if($this->encryMethod=="md5"){ + $sign=md5($signSrc); + }else{ + throw new ResultInfoException($this->encryMethod.",必须为md5,sha1,sha256之一","PARAM_ERROR"); + } + $req['ts']=$ts; + $req['app_key']=$this->appkey; + $req['sign']=$sign; + $req['nonce']=$nonce;//这只是为了生成一个随机值 + if($this->encryMethod!=null){ + $req['encry_method']=$this->encryMethod;//为''也不能传 + } + return $req; + } +} \ No newline at end of file diff --git a/extend/junziqian/sdk/util/ShaUtils.php b/extend/junziqian/sdk/util/ShaUtils.php new file mode 100644 index 00000000..2ccee988 --- /dev/null +++ b/extend/junziqian/sdk/util/ShaUtils.php @@ -0,0 +1,56 @@ +resultCode; + } +} \ No newline at end of file diff --git a/extend/junziqian/sdk/util/http/HttpClientUtils.php b/extend/junziqian/sdk/util/http/HttpClientUtils.php new file mode 100644 index 00000000..46b529a8 --- /dev/null +++ b/extend/junziqian/sdk/util/http/HttpClientUtils.php @@ -0,0 +1,89 @@ + $v ) { + $headerArr[] = $n .':' . $v; + } + $ch = curl_init(); + curl_setopt($ch, CURLOPT_URL, $url); + curl_setopt($ch, CURLOPT_TIMEOUT, $timeout); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); + curl_setopt($ch, CURLOPT_HTTPHEADER, $headerArr); + curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE); + curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); + curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); + $temp = curl_exec($ch); + if(@file_put_contents($file, $temp) && !curl_error($ch)) { + return $file; + } else { + throw new ResultInfoException(curl_error($ch),"POST_ERROR"); + } + } else { + $params = array( + "http"=>array( + "method"=>"GET", + "header"=>"User-Agent:windows", + "timeout"=>$timeout) + ); + $context = stream_context_create($params); + if(@copy($url, $file, $context)) { + //$http_response_header + return $file; + } else { + return false; + } + } + } +} \ No newline at end of file