fixed
This commit is contained in:
parent
ec1b605077
commit
e8da9439a4
|
@ -1,2 +0,0 @@
|
|||
*
|
||||
!.gitignore
|
|
@ -0,0 +1,52 @@
|
|||
<?php
|
||||
namespace junziqian\sdk\bean;
|
||||
use junziqian\sdk\util\CommonUtil;
|
||||
|
||||
/**
|
||||
* Interface Req2MapInterface
|
||||
* @package com\junziqian\sdk\bean
|
||||
* @edit yfx 2019-10-29
|
||||
*/
|
||||
abstract class Req2MapInterface{
|
||||
/**
|
||||
* @return mixed object转array(第二层要看情况转,所以无法通用)
|
||||
*/
|
||||
public function build(){
|
||||
$arr= self::getObject2Array($this);
|
||||
return $arr;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 对象转为数组,如果已经是数组,则会清空数组
|
||||
* @param $obj
|
||||
* @param $immPramas array 直转不做处理的属性
|
||||
* @return array
|
||||
*/
|
||||
static function getObject2Array($obj,$ignoreParams=null){
|
||||
$_array = is_object($obj) ? get_object_vars($obj) : $obj;
|
||||
$array=array();
|
||||
foreach ($_array as $key => $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;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,110 @@
|
|||
<?php
|
||||
namespace junziqian\sdk\bean\req\sign;
|
||||
|
||||
use junziqian\sdk\bean\Req2MapInterface;
|
||||
use junziqian\sdk\util\CommonUtil;
|
||||
|
||||
/**
|
||||
* Class ApplySignReq 签约发起-合同
|
||||
* @package com\junziqian\sdk\bean\req\sign
|
||||
* @edit yfx 2019-10-29
|
||||
*/
|
||||
class ApplySignReq extends Req2MapInterface {
|
||||
|
||||
//@ApiModelProperty(value = "合同名称",required = true)
|
||||
public $contractName;
|
||||
|
||||
//@ApiModelProperty(value = "签收方",required = true)
|
||||
public $signatories;
|
||||
|
||||
//@ApiModelProperty(value = "是否需要服务端证书,云证书:非1不需要,默认;1需要")
|
||||
public $serverCa;
|
||||
/**处理方式*/
|
||||
//@ApiModelProperty(value = "处理方式:为空或0时默认为手签合同;1自动签约;2只保全;5部份自动签;6HASH只保全;7收集批量签")
|
||||
public $dealType;
|
||||
|
||||
//@ApiModelProperty(value = "dealType=6时必须传入,文件的sha512HexString值")
|
||||
public $hashValue;
|
||||
|
||||
/**-----------合同文件相关----------**/
|
||||
//@ApiModelProperty(value = "合同上传方式:0或null直接上传PDF;1url地址下载;2tmpl模版生成;3html文件上传")
|
||||
public $fileType;
|
||||
|
||||
//@ApiModelProperty(value = "dealType!=6,fileType=0或null,时必须传入,合同文件;请使用form表单上传文件")
|
||||
public $file;
|
||||
|
||||
//@ApiModelProperty(value = "dealType!=6,fileType=1,时必须传入,合同PDF文件的url地址")
|
||||
public $url;
|
||||
|
||||
//@ApiModelProperty(value = "dealType!=6,fileType=2,时必须传入,合同模版编号")
|
||||
public $templateNo;
|
||||
|
||||
//@ApiModelProperty(value = "dealType!=6,fileType=2,时必须传入,合同模版参数JSON字符串")
|
||||
public $templateParams;
|
||||
|
||||
//@ApiModelProperty(value = "dealType!=6,fileType=3,时必须传入,合同html文件")
|
||||
public $htmlContent;
|
||||
/**-----------合同文件相关 end----------**/
|
||||
|
||||
//@ApiModelProperty(value = "指定公章位置类型:0或null使用签字座标位置或不指定签字位置;1表单域定位(表单域如果上传为pdf时,需pdf自行定义好表单域,html及url及tmpl等需定义好input标签);2关键字定义")
|
||||
public $positionType;
|
||||
|
||||
//@ApiModelProperty(value = "验证方式为人脸时必传,人脸识别等级:默认等级(1-100之间整数),建议范围(60-79)")
|
||||
public $faceThreshold;
|
||||
|
||||
//@ApiModelProperty(value = "是否按顺序签字,非1为不按,1为按")
|
||||
public $orderFlag;
|
||||
|
||||
//@ApiModelProperty(value = "合同查看二维码0默认不1显示")
|
||||
public $qrCode;
|
||||
|
||||
//@ApiModelProperty(value = "不显示ebq的保全章:1 不显示但会签名,2不显示也不签名;0或其它-显示")
|
||||
public $noEbqSign;
|
||||
|
||||
//@ApiModelProperty(value = "合同金额")
|
||||
public $contractAmount;
|
||||
|
||||
//@ApiModelProperty(value = "备注")
|
||||
public $remark;
|
||||
|
||||
//@ApiModelProperty(value = " 前置记录,此记录会计录到签约日志中,并保全到日志保全和最终的证据保全中,最大字符不能超过2000字符串")
|
||||
public $preRecored;
|
||||
|
||||
//@ApiModelProperty(value = "多合同顺序签约Info")
|
||||
public $sequenceInfo;
|
||||
|
||||
//@ApiModelProperty(value = "合同附件,虽不限个数,但包括合同原文件,不能超过20MB")
|
||||
public $attachFiles;
|
||||
|
||||
//@ApiModelProperty(value = "是否使用视频签约:0或null不使用;1使用(使用时必须购买相应套餐)")
|
||||
public $ifWebRtc;
|
||||
|
||||
//@ApiModelProperty(value = "是否使用骑缝章:1使用;其它不使用")
|
||||
public $needQifengSign;
|
||||
|
||||
//@ApiModelProperty(value = "是否归档:0不归档;1归档(默认)")
|
||||
public $isArchive;
|
||||
|
||||
//@ApiModelProperty(value = "是否可以拒签:0或null不能拒签(默认);1可拒签")
|
||||
public $canRefuse;
|
||||
|
||||
//@ApiModelProperty(value = "是否不显示个人标准章边框:1不显示,其它显示边框(默认)")
|
||||
public $noBorderSign;
|
||||
|
||||
//回调地址
|
||||
public $notifyUrl;
|
||||
|
||||
//@Override
|
||||
public function build() {
|
||||
$arr= self::getObject2Array($this,array("attachFiles"));
|
||||
if($this->attachFiles!=null&&sizeof($this->attachFiles)>0){
|
||||
$i=0;
|
||||
foreach($this->attachFiles as $value){
|
||||
$arr["attachFiles[".$i."]"]=$value;
|
||||
$i = $i+1;
|
||||
}
|
||||
}
|
||||
return $arr;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,31 @@
|
|||
<?php
|
||||
namespace junziqian\sdk\bean\req\sign\ext;
|
||||
|
||||
/**
|
||||
* Class SequenceInfo 合同顺序信息
|
||||
* @package com\junziqian\sdk\bean\req\sign\ext
|
||||
* @edit yfx 2019-10-29
|
||||
*/
|
||||
class SequenceInfo{
|
||||
//@ApiModelProperty(value = "客户方合同的唯一编号",required = true)
|
||||
public $businessNo;
|
||||
|
||||
//@ApiModelProperty(value = "签约顺序号",required = true)
|
||||
public $sequenceOrder;
|
||||
|
||||
//@ApiModelProperty(value = "总份数",required = true)
|
||||
public $totalNum;
|
||||
|
||||
/**
|
||||
* SequenceInfo constructor.
|
||||
* @param $businessNo
|
||||
* @param $sequenceOrder
|
||||
* @param $totalNum
|
||||
*/
|
||||
public function __construct($businessNo, $sequenceOrder, $totalNum){
|
||||
$this->businessNo = $businessNo;
|
||||
$this->sequenceOrder = $sequenceOrder;
|
||||
$this->totalNum = $totalNum;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,88 @@
|
|||
<?php
|
||||
namespace junziqian\sdk\bean\req\sign\ext;
|
||||
|
||||
/**
|
||||
* Class SignatoryReq 签约方信息
|
||||
* @package com\junziqian\sdk\bean\req\sign\ext
|
||||
* @edit yfx 2019-10-29
|
||||
*/
|
||||
class SignatoryReq{
|
||||
//@ApiModelProperty(value = "签约方名称,不超过50个字符",required = true)
|
||||
public $fullName;
|
||||
|
||||
//@ApiModelProperty(value = "身份类型:1身份证,2护照,3台胞证,4港澳居民来往内地通行证,11营业执照,12统一社会信用代码",required = true)
|
||||
public $identityType;
|
||||
|
||||
//@ApiModelProperty(value = "证件号,不超过50个字符",required = true)
|
||||
public $identityCard;
|
||||
|
||||
//@ApiModelProperty(value = "手机号码(个人必传),11个字符")
|
||||
public $mobile;
|
||||
|
||||
//@ApiModelProperty(value = "邮箱,企业必传")
|
||||
public $email;
|
||||
|
||||
//@ApiModelProperty(value = "签字顺序:连续签(orderNum只是针对于当前合同),顺序签时需指定")
|
||||
public $orderNum;
|
||||
|
||||
//@ApiModelProperty(value = "签字位置座标信息:positionType=0时可以传入chapteJson")
|
||||
public $chapteJson;
|
||||
|
||||
//@ApiModelProperty(value = "签字位置-表单域名ID:positionType=1时必须传入")
|
||||
public $chapteName;
|
||||
|
||||
//@ApiModelProperty(value = "签字位置-按关键字签署,positionType=2时必须传入,关键字支持多个;以英文;分隔")
|
||||
public $searchKey;
|
||||
|
||||
//@ApiModelProperty(value = "签字位置-按关键字查询-扩展,positionType=2时可以传入,支持指定查询页数/关键字颜色/透明度.可参考相关说明")
|
||||
public $searchExtend;
|
||||
|
||||
//@ApiModelProperty(value = "签字位置-按关键字查询-结果转换的配置,positionType=2时可以传入,可配置查询结果的位置偏移.可参考后面说明")
|
||||
public $searchConvertExtend;
|
||||
|
||||
//@ApiModelProperty(value = "签约方需要手签时是否不先行验证手机或邮箱:1不验证,其它验证(默认)")
|
||||
public $noNeedVerify;
|
||||
|
||||
//@ApiModelProperty(value = " 是否使用自动签,0或null不使用,1自动(当且只当合同处理方式为部份自动或收集批量签时有效);有些场景必须serverCaAuto=1")
|
||||
public $serverCaAuto;
|
||||
|
||||
//@ApiModelProperty(value = "验证等级(传数组字符串):[2,3];2银行卡认证,10三要素认证,11人脸识别,12验证码验证")
|
||||
public $authLevel;
|
||||
|
||||
//@ApiModelProperty(value = "最小验证种类:默认为authLevel数组长度;必须小于authLevel长度且大于0(等于0时按authLevel数组长度计录);如authLevel=[2,3,10],authLevelRange=2表过只需要验证其中的两项即可")
|
||||
public $authLevelRange;
|
||||
|
||||
//@ApiModelProperty(value = "签字类型,标准图形章或公章:0标准图形章,1公章或手写,2公章手写或手写")
|
||||
public $signLevel;
|
||||
|
||||
//@ApiModelProperty(value = "强制添加现场:0或null:不强制添加现场,1:强制添加现场")
|
||||
public $forceEvidence;
|
||||
|
||||
//@ApiModelProperty(value = "买保险年数:1-3购买年限,基它不买;注需要有相应的套餐")
|
||||
public $insureYear;
|
||||
|
||||
//@ApiModelProperty(value = "强制阅读多少秒,单位1-300秒")
|
||||
public $readTime;
|
||||
|
||||
//@ApiModelProperty(value = "企业用户指定签章ID:此值需为商户上传的自定义公章ID,或商户创建的企业的自定义公章ID。自定义公章可通过sass或api上传")
|
||||
public $signId;
|
||||
|
||||
//@ApiModelProperty(value = "标准章时是否对个人或企业章图片打码:0不打,1打码")
|
||||
public $nameHideStatus;
|
||||
|
||||
//@ApiModelProperty(value = "h5人脸订单号,如使用过君子签提供的人脸认证服务可以上传其订单号")
|
||||
public $h5FaceOrderNo;
|
||||
|
||||
//@ApiModelProperty(value = "现场存证只能上传视频:1是,其它不是(默认)")
|
||||
public $onlyVideoEvidence;
|
||||
|
||||
//@ApiModelProperty(value = "现场存证自定义标题")
|
||||
public $evidenceTitle;
|
||||
|
||||
//@ApiModelProperty(value = "是否使用电子保管函:1使用0或其它不使用;使用时需有相应套餐")
|
||||
public $safeKeepLetterFlag;
|
||||
|
||||
//@ApiModelProperty(value = "api发起显示确认签字")
|
||||
public $apiAffirm;
|
||||
|
||||
}
|
|
@ -0,0 +1,75 @@
|
|||
<?php
|
||||
namespace junziqian\sdk\bean\req\user;
|
||||
|
||||
use junziqian\sdk\bean\Req2MapInterface;
|
||||
|
||||
/**
|
||||
* Class OrganizationCreateReq 组织创建及重传
|
||||
* @package com\junziqian\sdk\bean\req\user
|
||||
* @edit yfx 2019-10-29
|
||||
*/
|
||||
class OrganizationCreateReq extends Req2MapInterface{
|
||||
|
||||
//@ApiModelProperty(value = " 邮箱或手机号",required = true)
|
||||
public $emailOrMobile;
|
||||
|
||||
//@ApiModelProperty(value = " 名称",required = true)
|
||||
public $name;
|
||||
|
||||
//@ApiModelProperty(value = "组织类型 0企业,1事业单位",required = true,allowableValues = "0,1")
|
||||
public $organizationType;
|
||||
|
||||
//@ApiModelProperty(value = "证明类型:0多证,1多证合一",required = true,allowableValues = "0,1")
|
||||
public $identificationType;
|
||||
|
||||
//@ApiModelProperty(value = "组织注册编号,营业执照号或事业单位事证号或统一社会信用代码",required = true)
|
||||
public $organizationRegNo;
|
||||
|
||||
//@ApiModelProperty(value = "组织注册证件扫描件,营业执照或事业单位法人证书",required = true)
|
||||
public $organizationRegImg;
|
||||
|
||||
//@ApiModelProperty(value = "法人姓名",required = false)
|
||||
public $legalName;
|
||||
|
||||
//@ApiModelProperty(value = "法人身份证号",required = false)
|
||||
public $legalIdentityCard;
|
||||
|
||||
//@ApiModelProperty(value = "法人电话号码",required = false)
|
||||
public $legalMobile;
|
||||
|
||||
//@ApiModelProperty(value = "法人身份证正面",required = false)
|
||||
public $legalIdentityFrontImg;
|
||||
|
||||
//@ApiModelProperty(value = "法人身份证反面",required = false)
|
||||
public $legalIdentityBackImg;
|
||||
|
||||
//@ApiModelProperty(value = "公章签章图片",required = false)
|
||||
public $signImg;
|
||||
|
||||
//@ApiModelProperty(value = "法人住址",required = false)
|
||||
public $address;
|
||||
|
||||
//@ApiModelProperty(value = "企业授权人姓名",required = false)
|
||||
public $authorizeName;
|
||||
|
||||
//@ApiModelProperty(value = "企业授权人身份证号",required = false)
|
||||
public $authorizeCard;
|
||||
|
||||
//@ApiModelProperty(value = "企业授权人手机号",required = false)
|
||||
public $authorizeMobilePhone;
|
||||
|
||||
//@ApiModelProperty(value = "组织结构代码",required = false)
|
||||
public $organizationCode;
|
||||
|
||||
//@ApiModelProperty(value = "组织结构代码扫描件",required = false)
|
||||
public $organizationCodeImg;
|
||||
|
||||
//@ApiModelProperty(value = "税务登记扫描件,事业单位选填,普通企业必选",required = false)
|
||||
public $taxCertificateImg;
|
||||
|
||||
//@ApiModelProperty(value = "签约申请书扫描图",required = false)
|
||||
public $signApplication;
|
||||
|
||||
//回调地址
|
||||
public $notifyUrl;
|
||||
}
|
|
@ -0,0 +1,42 @@
|
|||
<?php
|
||||
|
||||
namespace junziqian\sdk\bean\req\user;
|
||||
|
||||
use junziqian\sdk\bean\Req2MapInterface;
|
||||
|
||||
class OrganizationFaceCreateReq extends Req2MapInterface
|
||||
{
|
||||
//@ApiModelProperty(value = "唯一流水号,自定义",required = true)
|
||||
public $orderNo;
|
||||
|
||||
//@ApiModelProperty(value = "唯一邮箱,自定义",required = true)
|
||||
public $email;
|
||||
|
||||
//@ApiModelProperty(value = "企业证件名称",required = true)
|
||||
public $enterpriseName;
|
||||
|
||||
//@ApiModelProperty(value = "统一社会信用号",required = true)
|
||||
public $identityNo;
|
||||
|
||||
//@ApiModelProperty(value = "法人名称",required = true)
|
||||
public $legalPersonName;
|
||||
|
||||
//@ApiModelProperty(value = "法人证件号",required = true)
|
||||
public $legalIdentityCard;
|
||||
|
||||
//@ApiModelProperty(value = "法人手机号",required = true)
|
||||
public $legalMobile;
|
||||
|
||||
//@ApiModelProperty(value = "验证人类型1代理人,不传则是法人")
|
||||
public $facePerType;
|
||||
|
||||
//@ApiModelProperty(value = "人脸验证代理人-名称",required = true)
|
||||
public $faceAgantIdenName;
|
||||
|
||||
//@ApiModelProperty(value = "人脸验证代理人-证件号",required = true)
|
||||
public $faceAgantIdenCard;
|
||||
|
||||
//@ApiModelProperty(value = "同步回调地址",required = true)
|
||||
public $backUrl;
|
||||
|
||||
}
|
|
@ -0,0 +1,55 @@
|
|||
<?php
|
||||
|
||||
namespace junziqian\sdk\util;
|
||||
|
||||
use junziqian\sdk\util\exception\ResultInfoException;
|
||||
|
||||
/**
|
||||
* Class Assert 断言工具,方便抛出异常,由统一异常处理工具类捕获异常直接返回
|
||||
* @package com\junziqian\sdk\util
|
||||
*/
|
||||
class Assert{
|
||||
/**
|
||||
* 判断为真
|
||||
* @param $flag bool 判断结果
|
||||
* @param $msg string 为空时异常信息
|
||||
*/
|
||||
static function isTrue($flag,$msg="值不为True"){
|
||||
if(!$flag){
|
||||
throw new ResultInfoException($msg,"PARAM_ERROR");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 断言为NULL
|
||||
* @param $flag
|
||||
* @param string $msg
|
||||
*/
|
||||
static function isNull($flag,$msg="值不为NULL"){
|
||||
if(!is_null($flag)){
|
||||
throw new ResultInfoException($msg,"PARAM_ERROR");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 断言不为空
|
||||
* @param $flag
|
||||
* @param string $msg
|
||||
*/
|
||||
static function notNull($flag,$msg="值为NULL"){
|
||||
if(is_null($flag)){
|
||||
throw new ResultInfoException($msg,"PARAM_ERROR");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 断方不为BLANK
|
||||
* @param $flag
|
||||
* @param string $msg
|
||||
*/
|
||||
static function notBlank($flag,$msg="值为BLANK"){
|
||||
if(is_null($flag)||trim($flag)==''||$flag=='null'){
|
||||
throw new ResultInfoException($msg,"PARAM_ERROR");
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,45 @@
|
|||
<?php
|
||||
namespace junziqian\sdk\util;
|
||||
|
||||
/**
|
||||
* Class CommonUtil 通用工具类
|
||||
* @package com\junziqian\sdk
|
||||
*/
|
||||
class CommonUtil{
|
||||
|
||||
/**
|
||||
* 使json_encode支持5.4.0以下
|
||||
* @param $value object|array 传入为对象
|
||||
* @return mixed|string
|
||||
*/
|
||||
static function json_encode($value){
|
||||
if (version_compare(PHP_VERSION,'5.4.0','<')){
|
||||
$str = json_encode($value);
|
||||
$str = preg_replace_callback("#\\\u([0-9a-f]{4})#i",
|
||||
function($matchs){
|
||||
return iconv('UCS-2BE', 'UTF-8', pack('H4', $matchs[1]));
|
||||
},
|
||||
$str
|
||||
);
|
||||
return $str;
|
||||
}else{
|
||||
return json_encode($value, JSON_UNESCAPED_UNICODE);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理无效params转数字null或0为'0'
|
||||
* @param null $str
|
||||
* @return string
|
||||
*/
|
||||
static function trim($str=null){
|
||||
if(is_null($str)){
|
||||
if(is_numeric($str)){
|
||||
return '0';
|
||||
}
|
||||
return '';
|
||||
}else{
|
||||
return trim($str.'');
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,106 @@
|
|||
<?php
|
||||
|
||||
|
||||
namespace junziqian\sdk\util;
|
||||
|
||||
use junziqian\sdk\util\exception\ResultInfoException;
|
||||
use junziqian\sdk\util\http\HttpClientUtils;
|
||||
use think\facade\Log;
|
||||
|
||||
/**
|
||||
* Class RequestUtils http请求
|
||||
* @package com\junziqian\sdk\bean
|
||||
* @edit yfx 2019-10-29
|
||||
*/
|
||||
class RequestUtils{
|
||||
/**请求地址*/
|
||||
private $serviceUrl;
|
||||
/**appkey*/
|
||||
private $appkey;
|
||||
/**secret*/
|
||||
private $appSecret;
|
||||
|
||||
|
||||
/**默认加密方式:不输入使用sha256,其它可选择项md5,sha1,sha3-256*/
|
||||
private $encryMethod;
|
||||
/**默认ts单位:1毫秒,2秒*/
|
||||
private $tsType;
|
||||
/**
|
||||
* RequestUtils constructor.
|
||||
* @param $serviceUrl
|
||||
* @param $appkey
|
||||
* @param $appSecret
|
||||
*/
|
||||
public function __construct($serviceUrl, $appkey, $appSecret,$encryMethod=null,$tsType=2){
|
||||
Assert::notBlank($serviceUrl,"serviceUrl不能为空");
|
||||
Assert::notBlank($appkey,"appkey不能为空");
|
||||
Assert::notBlank($appSecret,"appSecret不能为空");
|
||||
$this->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;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,56 @@
|
|||
<?php
|
||||
namespace junziqian\sdk\util;
|
||||
/**
|
||||
* 以下只针对utf-8字符串进行sha加密
|
||||
* Class ShaUtils
|
||||
* @package org\ebq\api\tool
|
||||
* @edit yfx 2019-10-29
|
||||
*/
|
||||
class ShaUtils {
|
||||
/*
|
||||
* 加密字符串sha1
|
||||
* $str 字符串
|
||||
*/
|
||||
static function getSha1($str) {
|
||||
return sha1 ( $str );
|
||||
}
|
||||
/*
|
||||
* 加密字符串sha256
|
||||
* $str 字符串
|
||||
*/
|
||||
static function getSha256($str) {
|
||||
return hash ( 'sha256', $str );
|
||||
}
|
||||
/*
|
||||
* 加密字符串sha512
|
||||
* $str 字符串
|
||||
*/
|
||||
static function getSha512($str) {
|
||||
return hash ( 'sha512', $str );
|
||||
}
|
||||
/*
|
||||
* 加密文件sha1
|
||||
* $filePath 文件路径
|
||||
*/
|
||||
static function getFileSha1($filePath) {
|
||||
return sha1_file ( $filePath );
|
||||
}
|
||||
|
||||
/*
|
||||
* 加密文件sha256
|
||||
* $filePath 文件路径
|
||||
*/
|
||||
static function getFileSha256($filePath) {
|
||||
$str = file_get_contents ( $filePath );
|
||||
return self::getSha256 ( $str );
|
||||
}
|
||||
|
||||
/*
|
||||
* 加密文件sha512
|
||||
* $filePath 文件路径
|
||||
*/
|
||||
static function getFileSha512($filePath) {
|
||||
$str = file_get_contents ( $filePath );
|
||||
return self::getSha512 ( $str );
|
||||
}
|
||||
}
|
|
@ -0,0 +1,30 @@
|
|||
<?php
|
||||
namespace junziqian\sdk\util\exception;
|
||||
/**
|
||||
* 异常信息类
|
||||
* Class ResultInfoException
|
||||
* @package com\junziqian\sdk\util\exception
|
||||
* @edit yfx 2019-10-29
|
||||
*/
|
||||
class ResultInfoException extends \RuntimeException {
|
||||
/**
|
||||
* @var string 异常码
|
||||
*/
|
||||
private $resultCode;
|
||||
|
||||
/**
|
||||
* ResultInfoException constructor.
|
||||
* @param string $message 异常信息
|
||||
* @param string $resultCode 异常码
|
||||
*/
|
||||
public function __construct($message = "",$resultCode="PARAM_ERROR"){
|
||||
parent::__construct($message, null, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string 异常吗
|
||||
*/
|
||||
public function getResultCode(){
|
||||
return $this->resultCode;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,89 @@
|
|||
<?php
|
||||
namespace junziqian\sdk\util\http;
|
||||
|
||||
use junziqian\sdk\util\exception\ResultInfoException;
|
||||
|
||||
/**
|
||||
* Class HttpClientUtils
|
||||
* @package com\junziqian\sdk\util\http
|
||||
* @edit yfx 2019-10-29
|
||||
*/
|
||||
class HttpClientUtils{
|
||||
/**
|
||||
* post请求
|
||||
* @param $url string
|
||||
* @param $req array
|
||||
* @return string
|
||||
*/
|
||||
public static function getPost($url,$req){
|
||||
//ini_set('user_agent','Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET CLR 2.0.50727; .NET CLR 3.0.04506.30; GreenBrowser)');
|
||||
$ch = curl_init();
|
||||
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); //验证curl对等证书(一般只要此项)
|
||||
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); //检查服务器SSL证书中是否存在一个公用名
|
||||
curl_setopt($ch, CURLOPT_SSLVERSION, 0); //传递一个包含SSL版本的长参数。
|
||||
curl_setopt($ch, CURLOPT_URL, $url);
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
|
||||
curl_setopt($ch, CURLOPT_POST, true);
|
||||
if(version_compare(PHP_VERSION, '5.6')&&!version_compare(PHP_VERSION, '7.0')){
|
||||
curl_setopt ( $ch, CURLOPT_SAFE_UPLOAD, false);
|
||||
}
|
||||
curl_setopt($ch, CURLOPT_POSTFIELDS, $req);
|
||||
$response = curl_exec($ch);
|
||||
if(!curl_error($ch)) {
|
||||
return $response;
|
||||
} else {
|
||||
throw new ResultInfoException(curl_error($ch),"POST_ERROR");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* http文件下载
|
||||
* @param $url 原文件地址
|
||||
* @param string $file 文件路径
|
||||
* @param int $timeout 超时设置,默认60秒
|
||||
* @return bool|mixed|string
|
||||
*/
|
||||
public static function httpcopy($url, $file="", $timeout=60) {
|
||||
$file = empty($file) ? pathinfo($url,PATHINFO_BASENAME) : $file;
|
||||
$dir = pathinfo($file,PATHINFO_DIRNAME);
|
||||
!is_dir($dir) && @mkdir($dir,0755,true);
|
||||
$url = str_replace(" ","%20",$url);
|
||||
if(function_exists('curl_init')) {
|
||||
|
||||
$headers['User-Agent'] = 'windows';
|
||||
$headerArr = array();
|
||||
foreach( $headers as $n => $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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue