From e146a056f3aa1b68f64bbc5e261bf137b7723307 Mon Sep 17 00:00:00 2001 From: l1n6yun Date: Mon, 2 Sep 2024 14:00:28 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=94=AF=E4=BB=98=E5=AE=9D?= =?UTF-8?q?=E4=B8=AA=E4=BA=BA=E5=8D=8F=E8=AE=AE=E6=8E=A5=E5=8F=A3=20(#40)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Params/Modify/BusinessParams.php | 41 +++++ .../Agreement/Params/Modify/Request.php | 32 ++++ .../Agreement/Params/Query/BusinessParams.php | 79 +++++++++ .../Agreement/Params/Query/Request.php | 32 ++++ .../Agreement/Params/Sign/BusinessParams.php | 165 ++++++++++++++++++ .../Agreement/Params/Sign/Request.php | 46 +++++ .../Params/UnSign/BusinessParams.php | 101 +++++++++++ .../Agreement/Params/UnSign/Request.php | 32 ++++ test/AlipayApp/agreement_modify.php | 35 ++++ test/AlipayApp/agreement_query.php | 34 ++++ test/AlipayApp/agreement_sign.php | 50 ++++++ test/AlipayApp/agreement_unsign.php | 34 ++++ 12 files changed, 681 insertions(+) create mode 100644 src/AlipayApp/Agreement/Params/Modify/BusinessParams.php create mode 100644 src/AlipayApp/Agreement/Params/Modify/Request.php create mode 100644 src/AlipayApp/Agreement/Params/Query/BusinessParams.php create mode 100644 src/AlipayApp/Agreement/Params/Query/Request.php create mode 100644 src/AlipayApp/Agreement/Params/Sign/BusinessParams.php create mode 100644 src/AlipayApp/Agreement/Params/Sign/Request.php create mode 100644 src/AlipayApp/Agreement/Params/UnSign/BusinessParams.php create mode 100644 src/AlipayApp/Agreement/Params/UnSign/Request.php create mode 100644 test/AlipayApp/agreement_modify.php create mode 100644 test/AlipayApp/agreement_query.php create mode 100644 test/AlipayApp/agreement_sign.php create mode 100644 test/AlipayApp/agreement_unsign.php diff --git a/src/AlipayApp/Agreement/Params/Modify/BusinessParams.php b/src/AlipayApp/Agreement/Params/Modify/BusinessParams.php new file mode 100644 index 0000000..8b3ab10 --- /dev/null +++ b/src/AlipayApp/Agreement/Params/Modify/BusinessParams.php @@ -0,0 +1,41 @@ + $value) { + if (null === $value) { + unset($obj[$key]); + } + } + + return json_encode($obj); + } +} diff --git a/src/AlipayApp/Agreement/Params/Modify/Request.php b/src/AlipayApp/Agreement/Params/Modify/Request.php new file mode 100644 index 0000000..abbe718 --- /dev/null +++ b/src/AlipayApp/Agreement/Params/Modify/Request.php @@ -0,0 +1,32 @@ +businessParams = new BusinessParams(); + $this->_method = 'GET'; + } +} diff --git a/src/AlipayApp/Agreement/Params/Query/BusinessParams.php b/src/AlipayApp/Agreement/Params/Query/BusinessParams.php new file mode 100644 index 0000000..7bdb492 --- /dev/null +++ b/src/AlipayApp/Agreement/Params/Query/BusinessParams.php @@ -0,0 +1,79 @@ + $value) + { + if (null === $value) + { + unset($obj[$key]); + } + } + + return json_encode($obj); + } +} diff --git a/src/AlipayApp/Agreement/Params/Query/Request.php b/src/AlipayApp/Agreement/Params/Query/Request.php new file mode 100644 index 0000000..b4331bb --- /dev/null +++ b/src/AlipayApp/Agreement/Params/Query/Request.php @@ -0,0 +1,32 @@ +businessParams = new BusinessParams(); + $this->_method = 'GET'; + } +} diff --git a/src/AlipayApp/Agreement/Params/Sign/BusinessParams.php b/src/AlipayApp/Agreement/Params/Sign/BusinessParams.php new file mode 100644 index 0000000..6912bf7 --- /dev/null +++ b/src/AlipayApp/Agreement/Params/Sign/BusinessParams.php @@ -0,0 +1,165 @@ + 'ALIPAYAPP']; + + /** + * 周期管控规则参数period_rule_params,在签约周期扣款产品(如CYCLE_PAY_AUTH_P)时必传,在签约其他产品时无需传入。 周期扣款产品,会按照这里传入的参数提示用户,并对发起扣款的时间、金额、次数等做相应限制。 + * + * @var array + */ + public $period_rule_params; + + /** + * 销售产品码,商户签约的支付宝合同所对应的产品码。 + * + * @var string + */ + public $product_code = 'GENERAL_WITHHOLDING'; + + /** + * 用户在商户网站的登录账号,用于在签约页面展示,如果为空,则不展示 + * + * @var string + */ + public $external_logon_id; + + /** + * 协议签约场景,商户可根据 代扣产品常见场景值 选择符合自身的行业场景。 说明:当传入商户签约号 external_agreement_no 时,本参数必填,不能为默认值 DEFAULT|DEFAULT。 + * + * @var string + */ + public $sign_scene = 'INDUSTRY|DEFAULT_SCENE'; + + /** + * 商户签约号,代扣协议中标示用户的唯一签约号(确保在商户系统中唯一)。 格式规则:支持大写小写字母和数字,最长32位。 商户系统按需自定义传入,如果同一用户在同一产品码、同一签约场景下,签订了多份代扣协议,那么需要指定并传入该值。 + * + * @var string + */ + public $external_agreement_no; + + /** + * 签约第三方主体类型。对于三方协议,表示当前用户和哪一类的第三方主体进行签约。 默认为PARTNER。 + * + * @var string + */ + public $third_party_type; + + /** + * 当前用户签约请求的协议有效周期。 整形数字加上时间单位的协议有效期,从发起签约请求的时间开始算起。 目前支持的时间单位: 1. d:天 2. m:月 如果未传入,默认为长期有效。 + * + * @var string + */ + public $sign_validity_period; + + /** + * 芝麻授权信息,针对于信用代扣签约。json格式。 + * + * @var array + */ + public $zm_auth_params; + + /** + * 签约产品属性,json格式 + * + * @var array + */ + public $prod_params; + + /** + * 签约营销参数,此值为json格式;具体的key需与营销约定 + * + * @var string + */ + public $promo_params; + + /** + * 此参数用于传递子商户信息,无特殊需求时不用关注。目前商户代扣、海外代扣、淘旅行信用住产品支持传入该参数(在销售方案中“是否允许自定义子商户信息”需要选是)。 + * + * @var array + */ + public $sub_merchant; + + /** + * 设备信息参数,在使用设备维度签约代扣协议时,可以传这些信息 + * + * @var array + */ + public $device_params; + + /** + * 用户实名信息参数,包含:姓名、身份证号、签约指定uid。商户传入用户实名信息参数,支付宝会对比用户在支付宝端的实名信息。 + * + * @var array + */ + public $identity_params; + + /** + * 协议生效类型, 用于指定协议是立即生效还是等待商户通知再生效. 可空, 不填默认为立即生效. + * + * @var string + */ + public $agreement_effect_type; + + + /** + * 商户希望限制的签约用户的年龄范围,min表示可签该协议的用户年龄下限,max表示年龄上限。如{"min": "18","max": "30"}表示18=<年龄<=30的用户可以签约该协议。 + * + * @var string + */ + public $user_age_range; + + /** + * 签约有效时间限制,单位是秒,有效范围是0-86400,商户传入此字段会用商户传入的值否则使用支付宝侧默认值,在有效时间外进行签约,会进行安全拦截;(备注:此字段适用于需要开通安全防控的商户,且依赖商户传入生成签约时的时间戳字段timestamp) + * + * @var int + */ + public $effect_time; + + public function toString() + { + $obj = (array)$this; + $jsonParams = [ + 'zm_auth_params', + 'prod_params', + 'promo_params', + ]; + foreach ($jsonParams as $param) + { + if (null === $obj[$param]) + { + unset($obj[$param]); + } + else + { + $obj[$param] = json_encode($obj[$param]); + } + } + foreach ($obj as $key => $value) + { + if (null === $value) + { + unset($obj[$key]); + } + } + + return json_encode($obj); + } +} diff --git a/src/AlipayApp/Agreement/Params/Sign/Request.php b/src/AlipayApp/Agreement/Params/Sign/Request.php new file mode 100644 index 0000000..e513091 --- /dev/null +++ b/src/AlipayApp/Agreement/Params/Sign/Request.php @@ -0,0 +1,46 @@ +businessParams = new BusinessParams(); + $this->_method = 'GET'; + } +} diff --git a/src/AlipayApp/Agreement/Params/UnSign/BusinessParams.php b/src/AlipayApp/Agreement/Params/UnSign/BusinessParams.php new file mode 100644 index 0000000..ef40ed0 --- /dev/null +++ b/src/AlipayApp/Agreement/Params/UnSign/BusinessParams.php @@ -0,0 +1,101 @@ + $value) { + if (null === $value) { + unset($obj[$key]); + } + } + + return json_encode($obj); + } +} diff --git a/src/AlipayApp/Agreement/Params/UnSign/Request.php b/src/AlipayApp/Agreement/Params/UnSign/Request.php new file mode 100644 index 0000000..7102f30 --- /dev/null +++ b/src/AlipayApp/Agreement/Params/UnSign/Request.php @@ -0,0 +1,32 @@ +businessParams = new BusinessParams(); + $this->_method = 'GET'; + } +} diff --git a/test/AlipayApp/agreement_modify.php b/test/AlipayApp/agreement_modify.php new file mode 100644 index 0000000..30958f7 --- /dev/null +++ b/test/AlipayApp/agreement_modify.php @@ -0,0 +1,35 @@ +appID = $GLOBALS['PAY_CONFIG']['appid']; +//$params->sign_type = 'RSA2'; // 默认就是RSA2 +$params->appPrivateKey = $GLOBALS['PAY_CONFIG']['privateKey']; +// $params->appPrivateKeyFile = ''; // 证书文件,如果设置则这个优先使用 +$params->apiDomain = 'https://openapi.alipaydev.com/gateway.do'; // 设为沙箱环境,如正式环境请把这行注释 + +// SDK实例化,传入公共配置 +$pay = new \Yurun\PaySDK\AlipayApp\SDK($params); + +// 支付接口 +$request = new \Yurun\PaySDK\AlipayApp\Agreement\Params\Modify\Request(); +$request->businessParams->agreement_no = '20185909000458725113'; +$request->businessParams->deduct_time = date('Y-m-d', strtotime('+1 day')); +$request->businessParams->memo = '用户已购买半年包,需延期扣款时间'; + +// 调用接口 +$result = $pay->execute($request); + +var_dump('result:', $result); + +var_dump('success:', $pay->checkResult()); + +var_dump('error:', $pay->getError(), 'error_code:', $pay->getErrorCode()); diff --git a/test/AlipayApp/agreement_query.php b/test/AlipayApp/agreement_query.php new file mode 100644 index 0000000..3844cb4 --- /dev/null +++ b/test/AlipayApp/agreement_query.php @@ -0,0 +1,34 @@ +appID = $GLOBALS['PAY_CONFIG']['appid']; +//$params->sign_type = 'RSA2'; // 默认就是RSA2 +$params->appPrivateKey = $GLOBALS['PAY_CONFIG']['privateKey']; +// $params->appPrivateKeyFile = ''; // 证书文件,如果设置则这个优先使用 +$params->apiDomain = 'https://openapi.alipaydev.com/gateway.do'; // 设为沙箱环境,如正式环境请把这行注释 + +// SDK实例化,传入公共配置 +$pay = new \Yurun\PaySDK\AlipayApp\SDK($params); + +// 支付接口 +$request = new \Yurun\PaySDK\AlipayApp\Agreement\Params\Query\Request(); +$request->businessParams->alipay_open_id = '074a1CcTG1LelxKe4xQC0zgNdId0nxi95b5lsNpazWYoCo5'; +$request->businessParams->agreement_no = '20170322450983769228'; + +// 调用接口 +$result = $pay->execute($request); + +var_dump('result:', $result); + +var_dump('success:', $pay->checkResult()); + +var_dump('error:', $pay->getError(), 'error_code:', $pay->getErrorCode()); diff --git a/test/AlipayApp/agreement_sign.php b/test/AlipayApp/agreement_sign.php new file mode 100644 index 0000000..07d88ce --- /dev/null +++ b/test/AlipayApp/agreement_sign.php @@ -0,0 +1,50 @@ +appID = $GLOBALS['PAY_CONFIG']['appid']; +//$params->sign_type = 'RSA2'; // 默认就是RSA2 +$params->appPrivateKey = $GLOBALS['PAY_CONFIG']['privateKey']; +// $params->appPrivateKeyFile = ''; // 证书文件,如果设置则这个优先使用 +$params->apiDomain = 'https://openapi.alipaydev.com/gateway.do'; // 设为沙箱环境,如正式环境请把这行注释 + +// SDK实例化,传入公共配置 +$pay = new \Yurun\PaySDK\AlipayApp\SDK($params); + +// 支付接口 +$request = new \Yurun\PaySDK\AlipayApp\Agreement\Params\Sign\Request(); +$request->notify_url = $GLOBALS['PAY_CONFIG']['notify_url']; // 支付后通知地址(作为支付成功回调,这个可靠) +$request->businessParams->product_code = 'GENERAL_WITHHOLDING'; +$request->businessParams->personal_product_code = 'CYCLE_PAY_AUTH_P'; +$request->businessParams->sign_scene = 'INDUSTRY|DEFAULT_SCENE'; +$request->businessParams->external_agreement_no = 'test' . mt_rand(10000000, 99999999); // 商户签约号; +$request->businessParams->access_params = ['channel' => 'ALIPAYAPP']; +$request->businessParams->period_rule_params = [ + 'period_type' => "DAY", + 'period' => 30, + 'execute_time' => date('Y-m-d'), + 'single_amount' => "29.9", + 'total_amount' => "5000", + 'total_payments' => "999", +]; +$request->businessParams->external_logon_id = $params['mobile']; + +// 处理 +$pay->prepareExecute($request, $url, $data); + +$payUrl = 'alipays://platformapi/startapp?' . http_build_query([ + 'appId' => 60000157, + 'appClearTop' => 'false', + 'startMultApp' => 'YES', + 'sign_params' => http_build_query($data) + ]); + +echo $payUrl; diff --git a/test/AlipayApp/agreement_unsign.php b/test/AlipayApp/agreement_unsign.php new file mode 100644 index 0000000..b2dd4dc --- /dev/null +++ b/test/AlipayApp/agreement_unsign.php @@ -0,0 +1,34 @@ +appID = $GLOBALS['PAY_CONFIG']['appid']; +//$params->sign_type = 'RSA2'; // 默认就是RSA2 +$params->appPrivateKey = $GLOBALS['PAY_CONFIG']['privateKey']; +// $params->appPrivateKeyFile = ''; // 证书文件,如果设置则这个优先使用 +$params->apiDomain = 'https://openapi.alipaydev.com/gateway.do'; // 设为沙箱环境,如正式环境请把这行注释 + +// SDK实例化,传入公共配置 +$pay = new \Yurun\PaySDK\AlipayApp\SDK($params); + +// 支付接口 +$request = new \Yurun\PaySDK\AlipayApp\Agreement\Params\UnSign\Request(); +$request->businessParams->alipay_open_id = '074a1CcTG1LelxKe4xQC0zgNdId0nxi95b5lsNpazWYoCo5'; +$request->businessParams->agreement_no = '20170322450983769228'; + +// 调用接口 +$result = $pay->execute($request); + +var_dump('result:', $result); + +var_dump('success:', $pay->checkResult()); + +var_dump('error:', $pay->getError(), 'error_code:', $pay->getErrorCode());