first commit
This commit is contained in:
195
src/Commands/Account.php
Normal file
195
src/Commands/Account.php
Normal file
@@ -0,0 +1,195 @@
|
||||
<?php
|
||||
|
||||
namespace Leady\YeePay\Commands;
|
||||
|
||||
use Exception;
|
||||
use Yeepay\Yop\Sdk\Service\Account\AccountClientBuilder;
|
||||
use Yeepay\Yop\Sdk\Service\Account\Model\AccountinfosQueryRequest;
|
||||
use Yeepay\Yop\Sdk\Service\Account\Model\AutoWithdrawRuleQueryRequest;
|
||||
use Yeepay\Yop\Sdk\Service\Account\Model\PayOrderRequest;
|
||||
use Yeepay\Yop\Sdk\Service\Account\Model\TransferB2bOrderRequest;
|
||||
use Yeepay\Yop\Sdk\Service\Account\Model\TransferB2bQueryRequest;
|
||||
use Yeepay\Yop\Sdk\Service\Account\Model\WithdrawCardBindRequest;
|
||||
use Yeepay\Yop\Sdk\Service\Account\Model\WithdrawCardModifyRequest;
|
||||
use Yeepay\Yop\Sdk\Service\Account\Model\WithdrawCardQueryRequest;
|
||||
use Yeepay\Yop\Sdk\Service\Account\Model\WithdrawOrderRequest;
|
||||
|
||||
class Account extends InitConfig
|
||||
{
|
||||
|
||||
const MESSAGE = [
|
||||
'UA00008' => '产品校验异常,请核对或稍后再试',
|
||||
'UA00010' => '账户不存在或已注销',
|
||||
'UA00011' => '商户账户状态异常',
|
||||
'UA30001' => '系统异常',
|
||||
'UA30006' => '商户不存在或状态异常',
|
||||
'UA30009' => '商户关系异常',
|
||||
'UA30012' => '账户余额不足,核对后再试',
|
||||
'UA30013' => '订单已存在,请勿重复发起',
|
||||
'UA30014' => '商户未开通产品,不能发起该交易',
|
||||
'UA40001' => '金额格式不正确',
|
||||
'UA5007' => '单笔转账额度超限',
|
||||
'UA5008' => '字段长度超长',
|
||||
];
|
||||
|
||||
protected $client;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->client = AccountClientBuilder::builder($this->getSdkConfig())->build();
|
||||
}
|
||||
|
||||
public function transferQuery(string $requestNo)
|
||||
{
|
||||
$request = new TransferB2bQueryRequest();
|
||||
$request->setParentMerchantNo(config('yeepay.merchantNo'))
|
||||
->setRequestNo($requestNo);
|
||||
$response = $this->client->transferB2bQuery($request);
|
||||
$result = $response->getResult();
|
||||
if ($result['returnCode'] == 'UA00000') {
|
||||
return $this->success($result);
|
||||
} else {
|
||||
return $this->error(self::MESSAGE[$result['returnCode']]);
|
||||
}
|
||||
}
|
||||
|
||||
public function transfer(array $data)
|
||||
{
|
||||
$request = new TransferB2bOrderRequest();
|
||||
$request->setParentMerchantNo(config('yeepay.merchantNo'))
|
||||
->setRequestNo($data['requestNo'])
|
||||
->setFromMerchantNo(config('yeepay.merchantNo'))
|
||||
->setToMerchantNo($data['merchantNo'])
|
||||
->setOrderAmount($data['amount'])
|
||||
->setFeeChargeSide($data['chargeSide'])
|
||||
->setUsage($data['usage'])
|
||||
->setNotifyUrl($data['notifyUrl']);
|
||||
$response = $this->client->transferB2bOrder($request);
|
||||
$result = $response->getResult();
|
||||
if ($result['returnCode'] == 'UA00000') {
|
||||
return $this->success($result);
|
||||
} else {
|
||||
return $this->error(self::MESSAGE[$result['returnCode']]);
|
||||
}
|
||||
}
|
||||
|
||||
public function accountinfosQuery(string $merchantNo)
|
||||
{
|
||||
try {
|
||||
$request = new AccountinfosQueryRequest();
|
||||
$request->setMerchantNo($merchantNo);
|
||||
$response = $this->client->accountinfosQuery($request);
|
||||
$result = $response->getResult();
|
||||
return $this->success($result);
|
||||
} catch (Exception $e) {
|
||||
return $this->error($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function WithdrawCardBind(array $data)
|
||||
{
|
||||
$request = new WithdrawCardBindRequest();
|
||||
$request->setMerchantNo($data['merchantNo'])
|
||||
->setBankCardType($data['bankCardType'])
|
||||
->setAccountNo($data['accountNo'])
|
||||
->setBankCode($data['bankCode']);
|
||||
$response = $this->client->withdrawCardBind($request);
|
||||
$result = $response->getResult();
|
||||
if ($result['returnCode'] == 'UA00000') {
|
||||
return $this->success($result);
|
||||
} else {
|
||||
return $this->error($result['returnMsg']);
|
||||
}
|
||||
}
|
||||
|
||||
public function WithdrawCardModify(array $data)
|
||||
{
|
||||
$request = new WithdrawCardModifyRequest();
|
||||
$request->setMerchantNo($data['merchantNo'])
|
||||
->setBankCardOperateType('CANCELLED')
|
||||
->setBindId($data['bindId']);
|
||||
|
||||
$response = $this->client->withdrawCardModify($request);
|
||||
$result = $response->getResult();
|
||||
if ($result['returnCode'] == 'UA00000') {
|
||||
return $this->success($result);
|
||||
} else {
|
||||
return $this->error($result['returnMsg']);
|
||||
}
|
||||
}
|
||||
|
||||
public function CardQuery(string $merchantNo)
|
||||
{
|
||||
$request = new WithdrawCardQueryRequest();
|
||||
$request->setMerchantNo($merchantNo);
|
||||
$response = $this->client->withdrawCardQuery($request);
|
||||
$result = $response->getResult();
|
||||
if ($result['returnCode'] == 'UA00000') {
|
||||
return $this->success($result);
|
||||
} else {
|
||||
return $this->error($result['returnMsg']);
|
||||
}
|
||||
}
|
||||
|
||||
public function PayOrder(array $data)
|
||||
{
|
||||
$request = new PayOrderRequest();
|
||||
$request->setParentMerchantNo(config('yeepay.merchantNo'))
|
||||
->setMerchantNo(config('yeepay.merchantNo'))
|
||||
->setRequestNo($data['requestNo'])
|
||||
->setOrderAmount($data['amount'])
|
||||
->setFeeChargeSide('PAYEE')
|
||||
->setReceiveType('REAL_TIME')
|
||||
->setReceiverBankCode($data['receiverBankCode'])
|
||||
->setReceiverAccountNo($data['receiverAccountNo'])
|
||||
->setReceiverAccountName($data['receiverAccountName'])
|
||||
->setBankAccountType($data['bankAccountType'] ?? 'DEBIT_CARD')
|
||||
->setNotifyUrl($data['notifyUrl']);
|
||||
$response = $this->client->payOrder($request);
|
||||
$result = $response->getResult();
|
||||
if ($result['returnCode'] == 'UA00000') {
|
||||
return $this->success($result);
|
||||
} else {
|
||||
return $this->error($result['returnMsg']);
|
||||
}
|
||||
}
|
||||
|
||||
public function Withdraw(array $data)
|
||||
{
|
||||
$request = new WithdrawOrderRequest();
|
||||
$request->setParentMerchantNo(config('yeepay.merchantNo'))
|
||||
->setMerchantNo($data['merchantNo'])
|
||||
->setRequestNo($data['requestNo'])
|
||||
->setBankCardId($data['bankCardId'])
|
||||
->setReceiveType('TWO_HOUR')
|
||||
->setOrderAmount($data['amount'])
|
||||
->setNotifyUrl($data['notifyUrl']);
|
||||
$response = $this->client->withdrawOrder($request);
|
||||
$result = $response->getResult();
|
||||
if ($result['returnCode'] == 'UA00000') {
|
||||
return $this->success($result);
|
||||
} else {
|
||||
return $this->error($result['returnMsg']);
|
||||
}
|
||||
}
|
||||
|
||||
public function AutoWithdrawRule(string $merchantNo)
|
||||
{
|
||||
try{
|
||||
$request=new AutoWithdrawRuleQueryRequest();
|
||||
$request->setParentMerchantNo(config('yeepay.merchantNo'))
|
||||
->setMerchantNo($merchantNo);
|
||||
$response=$this->client->autoWithdrawRuleQuery($request);
|
||||
$result=$response->getResult();
|
||||
if ($result['returnCode'] == 'UA00000') {
|
||||
return $this->success($result);
|
||||
} else {
|
||||
return $this->error($result['returnMsg']);
|
||||
}
|
||||
}catch (Exception $e){
|
||||
return $this->error($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
88
src/Commands/Aggpay.php
Normal file
88
src/Commands/Aggpay.php
Normal file
@@ -0,0 +1,88 @@
|
||||
<?php
|
||||
|
||||
namespace Leady\YeePay\Commands;
|
||||
|
||||
use Exception;
|
||||
use Yeepay\Yop\Sdk\Service\Aggpay\AggpayClientBuilder;
|
||||
use Yeepay\Yop\Sdk\Service\Aggpay\Model\PrePayRequest;
|
||||
use Yeepay\Yop\Sdk\Service\Aggpay\Model\WechatConfigAdd0Request;
|
||||
use Yeepay\Yop\Sdk\Service\Aggpay\Model\WechatConfigQuery0Request;
|
||||
|
||||
class Aggpay extends InitConfig
|
||||
{
|
||||
|
||||
protected $client;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->client = AggpayClientBuilder::builder($this->getSdkConfig())->build();
|
||||
}
|
||||
|
||||
public function PrePay(array $data)
|
||||
{
|
||||
try {
|
||||
$request = new PrePayRequest();
|
||||
$request->setParentMerchantNo(config('yeepay.merchantNo'))
|
||||
->setMerchantNo(config('yeepay.merchantNo'))
|
||||
->setOrderId($data['orderId'] ?? '')
|
||||
->setOrderAmount($data['orderAmount'] ?? '')
|
||||
->setExpiredTime(now()->addMinutes(30)->toDateTimeString())
|
||||
->setNotifyUrl($data['notifyUrl'] ?? '')
|
||||
->setRedirectUrl($data['redirectUrl'] ?? '')
|
||||
->setMemo($data['memo'] ?? '')
|
||||
->setGoodsName($data['goodsName'] ?? '')
|
||||
->setPayWay($data['payWay'] ?? 'USER_SCAN')
|
||||
->setChannel($data['channel'] ?? '')
|
||||
->setUserIp($data['userIp'])
|
||||
->setFundProcessType($data['fundProcessType'] ?? 'REAL_TIME')
|
||||
->setAppId($data['appId'] ?? '')
|
||||
->setUserId($data['userId'] ?? '')
|
||||
->setScene('ONLINE');
|
||||
$response = $this->client->prePay($request);
|
||||
$result = $response->getResult();
|
||||
if ($result['code'] == '00000') {
|
||||
return $this->success($result);
|
||||
} else {
|
||||
return $this->error($result['returnMsg']);
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
return $this->error($e->getMessage());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public function WechatConfig(array $data)
|
||||
{
|
||||
$url = $this->getJson($data['url'] ?? '');
|
||||
$appId = $this->getJson($data['appId'] ?? '');
|
||||
|
||||
$request = new WechatConfigAdd0Request();
|
||||
$request->setParentMerchantNo(config('yeepay.merchantNo'))
|
||||
->setMerchantNo(config('yeepay.merchantNo'))
|
||||
->setTradeAuthDirList($url)
|
||||
->setAppIdList($appId);
|
||||
$response = $this->client->wechatConfigAdd_0($request);
|
||||
$result = $response->getResult();
|
||||
if ($result['code'] == '00000') {
|
||||
return $this->success($result);
|
||||
} else {
|
||||
return $this->error($result['returnMsg']);
|
||||
}
|
||||
}
|
||||
|
||||
public function WechatConfigQuery()
|
||||
{
|
||||
$request = new WechatConfigQuery0Request();
|
||||
$request->setParentMerchantNo(config('yeepay.merchantNo'))
|
||||
->setMerchantNo(config('yeepay.merchantNo'));
|
||||
$response = $this->client->wechatConfigQuery_0($request);
|
||||
$result = $response->getResult();
|
||||
if ($result['code'] == '00000') {
|
||||
return $this->success($result);
|
||||
} else {
|
||||
return $this->error($result['returnMsg']);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
33
src/Commands/Cashier.php
Normal file
33
src/Commands/Cashier.php
Normal file
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
namespace Leady\YeePay\Commands;
|
||||
|
||||
use Yeepay\Yop\Sdk\Service\Cashier\CashierClientBuilder;
|
||||
use Yeepay\Yop\Sdk\Service\Cashier\Model\PayLinkOrderRequest;
|
||||
|
||||
class Cashier extends InitConfig
|
||||
{
|
||||
protected $client;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->client = CashierClientBuilder::builder($this->getSdkConfig())->build();
|
||||
}
|
||||
|
||||
public function PayLinkOrder(array $data)
|
||||
{
|
||||
$request=new PayLinkOrderRequest();
|
||||
$request->setParentMerchantNo(config('yeepay.merchantNo'))
|
||||
->setMerchantNo(config('yeepay.merchantNo'))
|
||||
->setOrderId($data['orderId'] ?? '')
|
||||
->setAmount($data['orderAmount'] ?? '')
|
||||
->setExpiredTime(now()->addMinutes(30)->toDateTimeString())
|
||||
->setNotifyUrl($data['notifyUrl'] ?? '')
|
||||
->setGoodsName($data['goodsName'] ?? '');
|
||||
$response = $this->client->payLinkOrder($request);
|
||||
$result = $response->getResult();
|
||||
return $result;
|
||||
}
|
||||
|
||||
}
|
||||
96
src/Commands/Divide.php
Normal file
96
src/Commands/Divide.php
Normal file
@@ -0,0 +1,96 @@
|
||||
<?php
|
||||
|
||||
namespace Leady\YeePay\Commands;
|
||||
|
||||
use Yeepay\Yop\Sdk\Service\Divide\DivideClientBuilder;
|
||||
use Exception;
|
||||
use Yeepay\Yop\Sdk\Service\Divide\Model\ApplyRequest;
|
||||
use Yeepay\Yop\Sdk\Service\Divide\Model\BackRequest;
|
||||
use Yeepay\Yop\Sdk\Service\Divide\Model\CompleteRequest;
|
||||
|
||||
class Divide extends InitConfig
|
||||
{
|
||||
protected $client;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->client = DivideClientBuilder::builder($this->getSdkConfig())->build();
|
||||
}
|
||||
|
||||
/**
|
||||
* 申请分账
|
||||
*
|
||||
* @param array $data
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function apply(array $data)
|
||||
{
|
||||
try {
|
||||
$divideDetail = $this->getJson($data['divideDetail'] ?? '');
|
||||
|
||||
$request = new ApplyRequest();
|
||||
$request->setParentMerchantNo(config('yeepay.merchantNo'))
|
||||
->setMerchantNo(config('yeepay.merchantNo'))
|
||||
->setOrderId($data['trade_no'])
|
||||
->setUniqueOrderNo($data['uniqueOrderNo'])
|
||||
->setDivideRequestId($data['divideRequestId'])
|
||||
->setDivideDetail($divideDetail);
|
||||
$response = $this->client->apply($request);
|
||||
$result = $response->getResult();
|
||||
if ($result['code'] == 'OPR00000') {
|
||||
return $this->success($result);
|
||||
} else {
|
||||
return $this->error($result['message']);
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
return $this->error($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function complete(array $data)
|
||||
{
|
||||
try {
|
||||
$request = new CompleteRequest();
|
||||
$request->setParentMerchantNo(config('yeepay.merchantNo'))
|
||||
->setMerchantNo(config('yeepay.merchantNo'))
|
||||
->setOrderId($data['trade_no'])
|
||||
->setUniqueOrderNo($data['uniqueOrderNo'])
|
||||
->setDivideRequestId($data['divideRequestId']);
|
||||
$response = $this->client->complete($request);
|
||||
$result = $response->getResult();
|
||||
if ($result['code'] == 'OPR00000') {
|
||||
return $this->success($result);
|
||||
} else {
|
||||
return $this->error($result['message']);
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
return $this->error($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function back(array $data)
|
||||
{
|
||||
try {
|
||||
$divideBackDetail = $this->getJson($data['divideBackDetail'] ?? '');
|
||||
$request = new BackRequest();
|
||||
$request->setParentMerchantNo(config('yeepay.merchantNo'))
|
||||
->setMerchantNo(config('yeepay.merchantNo'))
|
||||
->setOrderId($data['trade_no'])
|
||||
->setUniqueOrderNo($data['uniqueOrderNo'])
|
||||
->setDivideRequestId($data['divideRequestId'])
|
||||
->setDivideBackRequestId($data['divideBackRequestId'])
|
||||
->setDivideBackDetail($divideBackDetail);
|
||||
$response = $this->client->back($request);
|
||||
$result = $response->getResult();
|
||||
if ($result['code'] == 'OPR00000') {
|
||||
return $this->success($result);
|
||||
} else {
|
||||
return $this->error($result['message']);
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
return $this->error($e->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
81
src/Commands/Frontcashier.php
Normal file
81
src/Commands/Frontcashier.php
Normal file
@@ -0,0 +1,81 @@
|
||||
<?php
|
||||
|
||||
namespace Leady\YeePay\Commands;
|
||||
|
||||
use Yeepay\Yop\Sdk\Service\Frontcashier\FrontcashierClientBuilder;
|
||||
use Yeepay\Yop\Sdk\Service\Frontcashier\Model\BindcardConfirm0Request;
|
||||
use Yeepay\Yop\Sdk\Service\Frontcashier\Model\BindcardRequestRequest;
|
||||
use Yeepay\Yop\Sdk\Service\Frontcashier\Model\BindcardResendsmsRequest;
|
||||
|
||||
class Frontcashier extends InitConfig
|
||||
{
|
||||
|
||||
protected $client;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->client = FrontcashierClientBuilder::builder($this->getSdkConfig())->build();
|
||||
}
|
||||
|
||||
public function bindCard(array $data)
|
||||
{
|
||||
$request = new BindcardRequestRequest();
|
||||
$request->setParentMerchantNo(config('yeepay.merchantNo'))
|
||||
->setMerchantFlowId($data['merchantFlowId'])
|
||||
->setMerchantNo($data['merchantNo'])
|
||||
->setUserNo($data['merchantNo'])
|
||||
->setUserType($data['userType'])
|
||||
->setBankCardNo($data['bankCardNo'])
|
||||
->setUserName($data['userName'])
|
||||
->setIdCardNo($data['idCardNo'])
|
||||
->setPhone($data['phone'])
|
||||
->setCardType($data['cardType'])
|
||||
->setAuthType($data['authType']);
|
||||
$response = $this->client->bindcardRequest($request);
|
||||
$result = $response->getResult();
|
||||
if ($result['returnCode'] == 'NOP00000') {
|
||||
return $this->success($result);
|
||||
} elseif ($result['returnCode'] == 'NOP04004') {
|
||||
$res = $this->reSendSms($data['merchantFlowId']);
|
||||
if ($res['code'] == 200) {
|
||||
return $this->success($result);
|
||||
} else {
|
||||
return $this->error($res['message']);
|
||||
}
|
||||
} else {
|
||||
return $this->error($result['message']);
|
||||
}
|
||||
}
|
||||
|
||||
public function reSendSms(string $merchantFlowId)
|
||||
{
|
||||
$request = new BindcardResendsmsRequest();
|
||||
$request->setParentMerchantNo(config('yeepay.merchantNo'))
|
||||
->setMerchantFlowId($merchantFlowId);
|
||||
$response = $this->client->bindcardResendsms($request);
|
||||
$result = $response->getResult();
|
||||
if ($result['code'] == 'NOP00000 ') {
|
||||
return $this->success($result);
|
||||
} else {
|
||||
return $this->error($result['message']);
|
||||
}
|
||||
}
|
||||
|
||||
public function bindcardConfirm(string $merchantFlowId, string $smsCode)
|
||||
{
|
||||
$request = new BindcardConfirm0Request();
|
||||
$request->setParentMerchantNo(config('yeepay.merchantNo'))
|
||||
->setMerchantFlowId($merchantFlowId)
|
||||
->setSmsCode($smsCode);
|
||||
$response = $this->client->bindcardConfirm_0($request);
|
||||
$result = $response->getResult();
|
||||
|
||||
if ($result['code'] == 'NOP00000') {
|
||||
return $this->success($result);
|
||||
} else {
|
||||
return $this->error($result['message']);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
94
src/Commands/InitConfig.php
Normal file
94
src/Commands/InitConfig.php
Normal file
@@ -0,0 +1,94 @@
|
||||
<?php
|
||||
|
||||
namespace Leady\YeePay\Commands;
|
||||
|
||||
use Yeepay\Yop\Sdk\Config\AppSdkConfig;
|
||||
|
||||
class InitConfig
|
||||
{
|
||||
|
||||
protected $params = [];
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->app_key = config('yeepay.appKey');
|
||||
if (config('yeepay.secretKey', '')) {
|
||||
$this->aes_secret_key = config('yeepay.secretKey');
|
||||
}
|
||||
if (config('yeepay.secretKey', '')) {
|
||||
$this->encrypt_key = config('yeepay.encryptKey');
|
||||
}
|
||||
$this->server_root = config('yeepay.serverRoot');
|
||||
$this->yos_server_root = config('yeepay.yosServerRoot');
|
||||
$this->yop_public_key = [
|
||||
[
|
||||
'store_type' => config('yeepay.storeType'),
|
||||
'cert_type' => config('yeepay.certType'),
|
||||
'value' => config('yeepay.yopPublicKey'),
|
||||
],
|
||||
];
|
||||
$this->isv_private_key = [
|
||||
[
|
||||
'store_type' => config('yeepay.storeType'),
|
||||
'cert_type' => config('yeepay.certType'),
|
||||
'value' => config('yeepay.isvPrivateKey'),
|
||||
],
|
||||
];
|
||||
$this->http_client = config('yeepay.httpClient');
|
||||
}
|
||||
|
||||
public function getParams()
|
||||
{
|
||||
return $this->params;
|
||||
}
|
||||
|
||||
public function getSdkConfig()
|
||||
{
|
||||
return new AppSdkConfig($this->params);
|
||||
}
|
||||
|
||||
public function result()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public function success($data)
|
||||
{
|
||||
return $this->message($data, 'SUCCESS', '成功', 200);
|
||||
}
|
||||
|
||||
public function error($message, $code = 400)
|
||||
{
|
||||
return $this->message([], 'ERROR', $message, $code);
|
||||
}
|
||||
|
||||
public function message($data, $state, $message, $code)
|
||||
{
|
||||
return [
|
||||
'code' => $code,
|
||||
'state' => $state,
|
||||
'message' => $message,
|
||||
'data' => $data,
|
||||
];
|
||||
}
|
||||
|
||||
public function getJson($value)
|
||||
{
|
||||
if (is_array($value)) {
|
||||
return json_encode($value, JSON_UNESCAPED_UNICODE);
|
||||
} else {
|
||||
return $value;
|
||||
}
|
||||
}
|
||||
|
||||
public function __set($name, $value)
|
||||
{
|
||||
$this->params[$name] = $value;
|
||||
}
|
||||
|
||||
public function __get($name)
|
||||
{
|
||||
return $this->params[$name] ?? '';
|
||||
}
|
||||
|
||||
}
|
||||
165
src/Commands/Mer.php
Normal file
165
src/Commands/Mer.php
Normal file
@@ -0,0 +1,165 @@
|
||||
<?php
|
||||
|
||||
namespace Leady\YeePay\Commands;
|
||||
|
||||
use Exception;
|
||||
use Yeepay\Yop\Sdk\Service\Mer\MerClientBuilder;
|
||||
use Yeepay\Yop\Sdk\Service\Mer\Model\MerchantDisposeUnfreezeRequest;
|
||||
use Yeepay\Yop\Sdk\Service\Mer\Model\NotifyRepeatRequest;
|
||||
use Yeepay\Yop\Sdk\Service\Mer\Model\ProductFeeModifyRequest;
|
||||
use Yeepay\Yop\Sdk\Service\Mer\Model\ProductFeeQueryRequest;
|
||||
use Yeepay\Yop\Sdk\Service\Mer\Model\RegisterContributeMerchantRequest;
|
||||
use Yeepay\Yop\Sdk\Service\Mer\Model\RegisterContributeMicroRequest;
|
||||
use Yeepay\Yop\Sdk\Service\Mer\Model\RegisterQueryRequest;
|
||||
|
||||
class Mer extends InitConfig
|
||||
{
|
||||
|
||||
protected $client;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->client = MerClientBuilder::builder($this->getSdkConfig())->build();
|
||||
}
|
||||
|
||||
public function RegisterContributeMerchant(array $data)
|
||||
{
|
||||
try {
|
||||
$role = $data['role'] ?? 'SETTLED_MERCHANT';
|
||||
$subjectInfo = $this->getJson($data['subjectInfo'] ?? '');
|
||||
$contactInfo = $this->getJson($data['contactInfo'] ?? '');
|
||||
$corporationInfo = $this->getJson($data['corporationInfo'] ?? '');
|
||||
$addressInfo = $this->getJson($data['addressInfo'] ?? '');
|
||||
$accountInfo = $this->getJson($data['accountInfo'] ?? '');
|
||||
$productInfo = $this->getJson($data['productInfo'] ?? '');
|
||||
$request = new RegisterContributeMerchantRequest();
|
||||
$request->setBusinessRole($role)
|
||||
->setRequestNo($data['requestNo'])
|
||||
->setMerchantSubjectInfo($subjectInfo)
|
||||
->setMerchantContactInfo($contactInfo)
|
||||
->setMerchantCorporationInfo($corporationInfo)
|
||||
->setBusinessAddressInfo($addressInfo)
|
||||
->setSettlementAccountInfo($accountInfo)
|
||||
->setProductInfo($productInfo)
|
||||
->setNotifyUrl($data['notifyUrl'] ?? '');
|
||||
$response = $this->client->registerContributeMerchant($request);
|
||||
$result = $response->getResult();
|
||||
if ($result['returnCode'] == 'NIG00000') {
|
||||
return $this->success($result);
|
||||
} else {
|
||||
return $this->error($result['returnMsg']);
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
return $this->error($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function RegisterContributeMicro(array $data)
|
||||
{
|
||||
try {
|
||||
$role = $data['role'] ?? 'SHARE_MERCHANT';
|
||||
$subjectInfo = $this->getJson($data['subjectInfo'] ?? '');
|
||||
$corporationInfo = $this->getJson($data['corporationInfo'] ?? '');
|
||||
$addressInfo = $this->getJson($data['addressInfo'] ?? '');
|
||||
$accountInfo = $this->getJson($data['accountInfo'] ?? '');
|
||||
$request = new RegisterContributeMicroRequest();
|
||||
$request->setRequestNo($data['requestNo'] ?? '')
|
||||
->setBusinessRole($role)
|
||||
->setMerchantSubjectInfo($subjectInfo)
|
||||
->setMerchantCorporationInfo($corporationInfo)
|
||||
->setBusinessAddressInfo($addressInfo)
|
||||
->setAccountInfo($accountInfo)
|
||||
->setNotifyUrl($data['notifyUrl'] ?? '');
|
||||
$response = $this->client->registerContributeMicro($request);
|
||||
$result = $response->getResult();
|
||||
if ($result['returnCode'] == 'NIG00000') {
|
||||
return $this->success($result);
|
||||
} else {
|
||||
return $this->error($result['returnMsg']);
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
return $this->error($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function NotifyRepeat(array $data)
|
||||
{
|
||||
$request = new NotifyRepeatRequest();
|
||||
$request->setRequestNo($data['requestNo'] ?? '')
|
||||
->setApplicationNo($data['applicationNo'] ?? '')
|
||||
->setType($data['type'] ?? '');
|
||||
$response = $this->client->notifyRepeat($request);
|
||||
$result = $response->getResult();
|
||||
if ($result['returnCode'] == 'NIG00000') {
|
||||
return $this->success($result);
|
||||
} else {
|
||||
return $this->error($result['returnMsg']);
|
||||
}
|
||||
}
|
||||
|
||||
public function RegisterQuery(string $requestNo)
|
||||
{
|
||||
try {
|
||||
$request = new RegisterQueryRequest();
|
||||
$request->setRequestNo($requestNo);
|
||||
$response = $this->client->registerQuery($request);
|
||||
$result = $response->getResult();
|
||||
if ($result['returnCode'] == 'NIG00000') {
|
||||
return $this->success($result);
|
||||
} else {
|
||||
return $this->error($result['returnMsg']);
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
return $this->error($e->getMessage());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public function FeeQuery(string $merchantNo)
|
||||
{
|
||||
$request = new ProductFeeQueryRequest();
|
||||
$request->setParentMerchantNo(config('yeepay.merchantNo'))
|
||||
->setMerchantNo($merchantNo);
|
||||
$response = $this->client->productFeeQuery($request);
|
||||
$result = $response->getResult();
|
||||
if ($result['returnCode'] == 'NIG00000') {
|
||||
return $this->success($result);
|
||||
} else {
|
||||
return $this->error($result['returnMsg']);
|
||||
}
|
||||
}
|
||||
|
||||
public function UnFreeze($data)
|
||||
{
|
||||
$request = new MerchantDisposeUnfreezeRequest();
|
||||
$request->setMerchantNo($data['merchantNo'])
|
||||
->setRequestNo($data['requestNo'])
|
||||
->setNotifyUrl($data['notifyUrl']);
|
||||
$response = $this->client->merchantDisposeUnfreeze($request);
|
||||
$result = $response->getResult();
|
||||
if ($result['returnCode'] == 'NIG00000') {
|
||||
return $this->success($result);
|
||||
} else {
|
||||
return $this->error($result['returnMsg']);
|
||||
}
|
||||
}
|
||||
|
||||
public function FeeModify(array $data)
|
||||
{
|
||||
|
||||
$productInfo = $this->getJson($data['productInfo'] ?? '');
|
||||
$request = new ProductFeeModifyRequest();
|
||||
$request->setParentMerchantNo(config('yeepay.merchantNo'))
|
||||
->setMerchantNo($data['merchantNo'])
|
||||
->setNotifyUrl($data['notifyUrl'])
|
||||
->setProductInfo($productInfo);
|
||||
$response = $this->client->productFeeModify($request);
|
||||
$result = $response->getResult();
|
||||
if ($result['returnCode'] == 'NIG00000') {
|
||||
return $this->success($result);
|
||||
} else {
|
||||
return $this->error($result['returnMsg']);
|
||||
}
|
||||
}
|
||||
}
|
||||
38
src/Commands/Nccashierapi.php
Normal file
38
src/Commands/Nccashierapi.php
Normal file
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
namespace Leady\YeePay\Commands;
|
||||
|
||||
use Yeepay\Yop\Sdk\Service\Nccashierapi\Model\ApiPayRequest;
|
||||
use Yeepay\Yop\Sdk\Service\Nccashierapi\NccashierapiClientBuilder;
|
||||
|
||||
class Nccashierapi extends InitConfig
|
||||
{
|
||||
|
||||
protected $client;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->client = NccashierapiClientBuilder::builder($this->getSdkConfig())->build();
|
||||
}
|
||||
|
||||
public function pay(array $data)
|
||||
{
|
||||
$request = new ApiPayRequest();
|
||||
$request->setToken($data['token']);
|
||||
$request->setPayTool($data['payTool']);
|
||||
$request->setPayType($data['payType']);
|
||||
$request->setUserIp($data['userIp']);
|
||||
$request->setAppId($data['appId']);
|
||||
$request->setOpenId($data['openId']);
|
||||
$request->setVersion('1.0');
|
||||
$response = $this->client->apiPay($request);
|
||||
$result = $response->getResult();
|
||||
if ($result['code'] == 'CAS00000') {
|
||||
return $this->success($result);
|
||||
} else {
|
||||
return $this->error($result['returnMsg']);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
33
src/Commands/Settle.php
Normal file
33
src/Commands/Settle.php
Normal file
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
namespace Leady\YeePay\Commands;
|
||||
|
||||
use Yeepay\Yop\Sdk\Service\Settle\Model\RecordsQueryRequest;
|
||||
use Yeepay\Yop\Sdk\Service\Settle\SettleClientBuilder;
|
||||
|
||||
class Settle extends InitConfig
|
||||
{
|
||||
protected $client;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->client = SettleClientBuilder::builder($this->getSdkConfig())->build();
|
||||
}
|
||||
|
||||
public function recordsQuery(string $merchantNo, string $start_at, string $end_at)
|
||||
{
|
||||
$request = new RecordsQueryRequest();
|
||||
$request->setParentMerchantNo(config('yeepay.merchantNo'))
|
||||
->setMerchantNo($merchantNo)
|
||||
->setSettleRequestBeginTime($start_at)
|
||||
->setSettleRequestEndTime($end_at);
|
||||
$response = $this->client->recordsQuery($request);
|
||||
$result = $response->getResult();
|
||||
if ($result['code'] == '000000') {
|
||||
return $this->success($result);
|
||||
} else {
|
||||
return $this->error($result['message']);
|
||||
}
|
||||
}
|
||||
}
|
||||
36
src/Commands/Std.php
Normal file
36
src/Commands/Std.php
Normal file
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
namespace Leady\YeePay\Commands;
|
||||
|
||||
use Yeepay\Yop\Sdk\Service\Std\Model\TradeOrderRequest;
|
||||
use Yeepay\Yop\Sdk\Service\Std\StdClientBuilder;
|
||||
|
||||
class Std extends InitConfig
|
||||
{
|
||||
|
||||
protected $client;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->client = StdClientBuilder::builder($this->getSdkConfig())->build();
|
||||
}
|
||||
|
||||
public function TradeOrder(array $data)
|
||||
{
|
||||
$goodsParam = $this->getJson($data['goodsParam'] ?? '');
|
||||
|
||||
$request = new TradeOrderRequest();
|
||||
$request->setParentMerchantNo(config('yeepay.merchantNo'))
|
||||
->setMerchantNo(config('yeepay.merchantNo'))
|
||||
->setOrderId($data['no'] ?? '')
|
||||
->setOrderAmount($data['amount'] ?? '')
|
||||
->setNotifyUrl($data['notifyUrl'])
|
||||
->setRedirectUrl($data['redirectUrl'])
|
||||
->setGoodsParamExt($goodsParam);
|
||||
$response = $this->client->tradeOrder($request);
|
||||
$result = $response->getResult();
|
||||
dd($result);
|
||||
}
|
||||
|
||||
}
|
||||
40
src/Commands/Sys.php
Normal file
40
src/Commands/Sys.php
Normal file
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
namespace Leady\YeePay\Commands;
|
||||
|
||||
use Exception;
|
||||
use Yeepay\Yop\Sdk\Service\Sys\Model\MerchantQualUploadRequest;
|
||||
use Yeepay\Yop\Sdk\Service\Sys\Model\TradeOrderRequest;
|
||||
use Yeepay\Yop\Sdk\Service\Sys\SysClientBuilder;
|
||||
|
||||
class Sys extends InitConfig
|
||||
{
|
||||
|
||||
protected $client;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->client = SysClientBuilder::builder($this->getSdkConfig())->build();
|
||||
}
|
||||
|
||||
public function MerchantQualUpload(string $filePath)
|
||||
{
|
||||
try {
|
||||
$request = new MerchantQualUploadRequest();
|
||||
$request->setMerQual(fopen($filePath, 'r'));
|
||||
$response = $this->client->merchantQualUpload($request);
|
||||
$result = $response->getResult();
|
||||
if ($result['returnCode'] == 'REG00000') {
|
||||
return $this->success(['merQualUrl' => $result['merQualUrl']]);
|
||||
} else {
|
||||
return $this->error($result['returnMsg']);
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
return $this->error($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
46
src/Commands/Trade.php
Normal file
46
src/Commands/Trade.php
Normal file
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
|
||||
namespace Leady\YeePay\Commands;
|
||||
|
||||
use Exception;
|
||||
use Yeepay\Yop\Sdk\Service\Trade\Model\OrderRequest;
|
||||
use Yeepay\Yop\Sdk\Service\Trade\TradeClientBuilder;
|
||||
|
||||
class Trade extends InitConfig
|
||||
{
|
||||
|
||||
protected $client;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->client = TradeClientBuilder::builder($this->getSdkConfig())->build();
|
||||
}
|
||||
|
||||
public function order(array $data)
|
||||
{
|
||||
try {
|
||||
$request = new OrderRequest();
|
||||
$request->setParentMerchantNo(config('yeepay.merchantNo'))
|
||||
->setMerchantNo(config('yeepay.merchantNo'))
|
||||
->setOrderId($data['order_id'])
|
||||
->setOrderAmount($data['amount'])
|
||||
->setGoodsName($data['goods_name'])
|
||||
->setFundProcessType($data['fundProcessType'] ?? 'REAL_TIME')
|
||||
->setExpiredTime($data['expiredTime'] ?? now()->addMinutes(30))
|
||||
->setNotifyUrl($data['notifyUrl']);
|
||||
$respnonse = $this->client->order($request);
|
||||
|
||||
$result = $respnonse->getResult();
|
||||
if ($result['code'] == 'OPR00000') {
|
||||
return $this->success($result);
|
||||
} else {
|
||||
return $this->error($result['message']);
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
return $this->error($e->getMessage());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
57
src/Commands/Yop.php
Normal file
57
src/Commands/Yop.php
Normal file
@@ -0,0 +1,57 @@
|
||||
<?php
|
||||
|
||||
namespace Leady\YeePay\Commands;
|
||||
|
||||
use Yeepay\Yop\Sdk\Auth\AuthorizationReqSupport;
|
||||
use Yeepay\Yop\Sdk\Auth\SignerFactory;
|
||||
use Yeepay\Yop\Sdk\Auth\SignOptions;
|
||||
use Yeepay\Yop\Sdk\Client\Support\ClientParamsSupport;
|
||||
use Yeepay\Yop\Sdk\Config\DefaultAppSdkConfigProvider;
|
||||
use Yeepay\Yop\Sdk\Http\ExecutionContext;
|
||||
use Yeepay\Yop\Sdk\Model\Transform\ResponseUnMarshalParams;
|
||||
use Yeepay\Yop\Sdk\Service\Common\Authority\MockAuthorityReqRegistry;
|
||||
|
||||
class Yop extends InitConfig
|
||||
{
|
||||
|
||||
protected $clientParams;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
|
||||
$appSdkConfigProvider = new DefaultAppSdkConfigProvider($this->getSdkConfig());
|
||||
$authorizationReqRegistry = new MockAuthorityReqRegistry();
|
||||
$this->clientParams = ClientParamsSupport::generateClientParams($appSdkConfigProvider);
|
||||
$this->clientParams->setAuthorizationReqRegistry($authorizationReqRegistry);
|
||||
|
||||
}
|
||||
|
||||
public function sign()
|
||||
{
|
||||
$authorizationReq = AuthorizationReqSupport::getAuthorizationReq('YOP-RSA2048-SHA256');
|
||||
$signer = SignerFactory::getSigner($authorizationReq->getSignerType());
|
||||
$signOptions = new SignOptions($authorizationReq->getDigestAlg(),
|
||||
$authorizationReq->getProtocolPrefix());
|
||||
$httpExecutionContext = new ExecutionContext();
|
||||
$httpExecutionContext->setSigner($signer)->setSignOptions($signOptions);
|
||||
$ResponseUnMarshalParams = new ResponseUnMarshalParams();
|
||||
$ResponseUnMarshalParams->setSigner($signer)->setSignOptions($signOptions)
|
||||
->setPublicKey($this->clientParams->getCredentialsProvider()->getYopPublicKey($authorizationReq->getCredentialType()));
|
||||
|
||||
}
|
||||
|
||||
public function signSim(string $string)
|
||||
{
|
||||
$private_key =config('yeepay.isvPrivateKey');
|
||||
$private_key = "-----BEGIN RSA PRIVATE KEY-----\n" .
|
||||
wordwrap($private_key, 64, "\n", true) .
|
||||
"\n-----END RSA PRIVATE KEY-----";
|
||||
$privateKey = openssl_pkey_get_private($private_key);// 提取私钥
|
||||
|
||||
openssl_sign($string, $encode_data, $privateKey, "SHA256");
|
||||
openssl_free_key($privateKey);
|
||||
$signToBase64 = Base64Url::encode($encode_data);
|
||||
$signToBase64 .= '$SHA256';
|
||||
}
|
||||
}
|
||||
13
src/Facade.php
Normal file
13
src/Facade.php
Normal file
@@ -0,0 +1,13 @@
|
||||
<?php
|
||||
|
||||
namespace Leady\YeePay;
|
||||
|
||||
use Illuminate\Support\Facades\Facade as LaravelFacade;
|
||||
|
||||
class Facade extends LaravelFacade
|
||||
{
|
||||
protected static function getFacadeAccessor()
|
||||
{
|
||||
return YeePay::class;
|
||||
}
|
||||
}
|
||||
29
src/ServiceProvider.php
Normal file
29
src/ServiceProvider.php
Normal file
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
namespace Leady\YeePay;
|
||||
|
||||
use Illuminate\Support\ServiceProvider as LaravelServiceProvider;
|
||||
|
||||
class ServiceProvider extends LaravelServiceProvider
|
||||
{
|
||||
|
||||
public function boot()
|
||||
{
|
||||
if ($this->app->runningInConsole()) {
|
||||
$this->publishes([__DIR__.'/../config/config.php' => config_path('yeepay.php')], 'yeepay');
|
||||
$this->loadMigrationsFrom(__DIR__.'/../database/migrations/');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 部署时加载
|
||||
* @Author:<Leady>
|
||||
* @Date:2020-11-20T12:30:20+0800
|
||||
* @return void
|
||||
*/
|
||||
public function register()
|
||||
{
|
||||
$this->mergeConfigFrom(__DIR__.'/../config/config.php', 'yeepay');
|
||||
}
|
||||
|
||||
}
|
||||
49
src/YeePay.php
Normal file
49
src/YeePay.php
Normal file
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
namespace Leady\YeePay;
|
||||
|
||||
use Exception;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
/**
|
||||
* Class YeePay
|
||||
* @package Leady\YeePay
|
||||
*/
|
||||
class YeePay
|
||||
{
|
||||
|
||||
/**
|
||||
* @param string $className
|
||||
* @return \Illuminate\Contracts\Foundation\Application|mixed
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function command(string $className)
|
||||
{
|
||||
$className = Str::studly($className);
|
||||
$class = 'Leady\\YeePay\\Commands\\'.$className;
|
||||
if (class_exists($class)) {
|
||||
return resolve($class);
|
||||
} else {
|
||||
throw new Exception('命令类['.$className.']不存在');
|
||||
}
|
||||
}
|
||||
|
||||
public function __call($name, $arguments)
|
||||
{
|
||||
if (Str::is('*_*', $name)) {
|
||||
$className = Str::before($name, '_');
|
||||
$functionName = Str::after($name, '_');
|
||||
$class = $this->command($className);
|
||||
if (count($arguments) == 2) {
|
||||
return $class->$functionName($arguments[0], $arguments[1]);
|
||||
} elseif (count($arguments) == 1) {
|
||||
return $class->$functionName($arguments[0]);
|
||||
} else {
|
||||
return $class->$functionName();
|
||||
}
|
||||
} else {
|
||||
$this->command($name);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
41
src/YopSign/AESEncrypter.php
Normal file
41
src/YopSign/AESEncrypter.php
Normal file
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
namespace Leady\YeePay\YopSign;
|
||||
|
||||
class AESEncrypter
|
||||
{
|
||||
|
||||
/**
|
||||
* 算法,另外还有192和256两种长度
|
||||
*/
|
||||
const CIPHER = MCRYPT_RIJNDAEL_128;
|
||||
/**
|
||||
* 模式
|
||||
*/
|
||||
const MODE = 'AES-128-ECB';
|
||||
|
||||
/**
|
||||
* 加密
|
||||
* @param string $str 需加密的字符串
|
||||
* @param string $key 密钥
|
||||
* @return type
|
||||
*/
|
||||
|
||||
static public function encode($str, $key)
|
||||
{
|
||||
|
||||
return base64_encode(openssl_encrypt($str, self::MODE, base64_decode($key), OPENSSL_RAW_DATA));
|
||||
}
|
||||
|
||||
/**
|
||||
* 解密
|
||||
* @param type $str
|
||||
* @param type $key
|
||||
* @return type
|
||||
*/
|
||||
static public function decode($str, $key)
|
||||
{
|
||||
return openssl_decrypt(base64_decode($str), self::MODE, base64_decode($key), OPENSSL_RAW_DATA);
|
||||
}
|
||||
|
||||
}
|
||||
29
src/YopSign/Base64Url.php
Normal file
29
src/YopSign/Base64Url.php
Normal file
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
namespace Leady\YeePay\YopSign;
|
||||
|
||||
class Base64Url
|
||||
{
|
||||
/**
|
||||
* @param string $data The data to encode
|
||||
* @param bool $use_padding If true, the "=" padding at end of the encoded value are kept, else it is removed
|
||||
*
|
||||
* @return string The data encoded
|
||||
*/
|
||||
public static function encode($data, $use_padding = false)
|
||||
{
|
||||
$encoded = strtr(base64_encode($data), '+/', '-_');
|
||||
|
||||
return true === $use_padding ? $encoded : rtrim($encoded, '=');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $data The data to decode
|
||||
*
|
||||
* @return string The data decoded
|
||||
*/
|
||||
public static function decode($data)
|
||||
{
|
||||
return base64_decode(strtr($data, '-_', '+/'));
|
||||
}
|
||||
}
|
||||
8
src/YopSign/YopConfig.php
Normal file
8
src/YopSign/YopConfig.php
Normal file
@@ -0,0 +1,8 @@
|
||||
<?php
|
||||
|
||||
namespace Leady\YeePay\YopSign;
|
||||
|
||||
class YopConfig
|
||||
{
|
||||
|
||||
}
|
||||
127
src/YopSign/YopSignUtils.php
Normal file
127
src/YopSign/YopSignUtils.php
Normal file
@@ -0,0 +1,127 @@
|
||||
<?php
|
||||
|
||||
namespace Leady\YeePay\YopSign;
|
||||
|
||||
class YopSignUtils
|
||||
{
|
||||
|
||||
/**
|
||||
* 签名生成算法
|
||||
* @param array $params API调用的请求参数集合的关联数组,不包含sign参数
|
||||
* @param array $ignoreParamNames 忽略的参数数组
|
||||
* @param String $secret 密钥
|
||||
* @param String $algName 加密算法
|
||||
* @return string 返回参数签名值
|
||||
*/
|
||||
public static function sign($params, $ignoreParamNames = '', $secret, $algName = 'sha256')
|
||||
{
|
||||
$str = ''; //待签名字符串
|
||||
$requestparams = $params;
|
||||
ksort($requestparams);
|
||||
foreach ($requestparams as $k => $v) {
|
||||
if (!in_array($k, $ignoreParamNames)) {
|
||||
if (!($v === null)) {
|
||||
$str .= "$k$v";
|
||||
}
|
||||
}
|
||||
}
|
||||
//将签名密钥拼接到签名字符串两头
|
||||
$str = $secret.$str.$secret;
|
||||
//通过指定算法生成sing
|
||||
$signValue = hash($algName, $str);
|
||||
|
||||
return $signValue;
|
||||
}
|
||||
|
||||
/**
|
||||
* 签名验证算法
|
||||
* @param array $result API调用的请求参数集合的关联数组,不包含sign参数
|
||||
* @param String $secret 密钥
|
||||
* @param String $algName 加密算法
|
||||
* @param String $sign 签名值
|
||||
* @return string 返回签名是否正确 0 - 如果两个字符串相等
|
||||
*/
|
||||
public static function isValidResult($result, $secret, $algName, $sign)
|
||||
{
|
||||
$newString = $secret.$result.$secret;
|
||||
|
||||
if (strcasecmp($sign, hash($algName, $newString)) == 0) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static function decrypt($source, $private_Key, $public_Key)
|
||||
{
|
||||
$private_key = "-----BEGIN RSA PRIVATE KEY-----\n".
|
||||
wordwrap($private_Key, 64, "\n", true).
|
||||
"\n-----END RSA PRIVATE KEY-----";
|
||||
|
||||
extension_loaded('openssl') or die('php需要openssl扩展支持');
|
||||
/* 提取私钥 */
|
||||
$privateKey = openssl_get_privatekey($private_key);
|
||||
($privateKey) or die('密钥不可用');
|
||||
//分解参数
|
||||
$args = explode('$', $source);
|
||||
|
||||
if (count($args) != 4) {
|
||||
die('source invalid : ');
|
||||
}
|
||||
$encryptedRandomKeyToBase64 = $args[0];
|
||||
$encryptedDataToBase64 = $args[1];
|
||||
$symmetricEncryptAlg = $args[2];
|
||||
$digestAlg = $args[3];
|
||||
//用私钥对随机密钥进行解密
|
||||
openssl_private_decrypt(Base64Url::decode($encryptedRandomKeyToBase64), $randomKey, $privateKey);
|
||||
openssl_free_key($privateKey);
|
||||
$encryptedData = openssl_decrypt(Base64Url::decode($encryptedDataToBase64), "AES-128-ECB", $randomKey,
|
||||
OPENSSL_RAW_DATA);
|
||||
//分解参数
|
||||
$signToBase64 = substr(strrchr($encryptedData, '$'), 1);
|
||||
$sourceData = substr($encryptedData, 0, strlen($encryptedData) - strlen($signToBase64) - 1);
|
||||
$public_key = "-----BEGIN PUBLIC KEY-----\n".
|
||||
wordwrap($public_Key, 64, "\n", true).
|
||||
"\n-----END PUBLIC KEY-----";
|
||||
$publicKey = openssl_pkey_get_public($public_key);
|
||||
$res = openssl_verify($sourceData, Base64Url::decode($signToBase64), $publicKey, $digestAlg); //验证
|
||||
openssl_free_key($publicKey);
|
||||
if ($res == 1) {
|
||||
return $sourceData;
|
||||
} else {
|
||||
die("verifySign fail!");
|
||||
}
|
||||
}
|
||||
|
||||
public static function signRsa($source, $private_Key)
|
||||
{
|
||||
$private_key = "-----BEGIN RSA PRIVATE KEY-----\n".
|
||||
wordwrap($private_Key, 64, "\n", true).
|
||||
"\n-----END RSA PRIVATE KEY-----";
|
||||
extension_loaded('openssl') or die('php需要openssl扩展支持');
|
||||
/* 提取私钥 */
|
||||
$privateKey = openssl_get_privatekey($private_key);
|
||||
($privateKey) or die('密钥不可用');
|
||||
openssl_sign($source, $encode_data, $privateKey, "SHA256");
|
||||
openssl_free_key($privateKey);
|
||||
$signToBase64 = Base64Url::encode($encode_data);
|
||||
$signToBase64 .= '$SHA256';
|
||||
|
||||
return $signToBase64;
|
||||
}
|
||||
|
||||
public static function getPrivateKey($filepath, $password)
|
||||
{
|
||||
$pkcs12 = file_get_contents($filepath);
|
||||
openssl_pkcs12_read($pkcs12, $certs, $password);
|
||||
$prikeyid = $certs['pkey']; //私钥
|
||||
$prikeyid = str_replace('-----BEGIN RSA PRIVATE KEY-----', '', $prikeyid);
|
||||
$prikeyid = str_replace('-----END RSA PRIVATE KEY-----', '', $prikeyid);
|
||||
$prikeyid = preg_replace("/(\r\n|\n|\r|\t)/i", '', $prikeyid);
|
||||
|
||||
return $prikeyid;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user