efps-version
elf 1 year ago
parent 4c9082f698
commit e85fda2b90

@ -4,26 +4,20 @@ declare(strict_types=1);
namespace App\Command; namespace App\Command;
use App\Helper\Efps\Api;
use App\Helper\Signer;
use App\Helper\StringHelper; use App\Helper\StringHelper;
use App\Request\BindCardRequest; use App\Request\BindCardRequest;
use App\Request\PaymentQueryRequest; use App\Request\PaymentQueryRequest;
use App\Request\ProtocolPayConfirmRequest; use App\Request\ProtocolPayConfirmRequest;
use App\Request\ProtocolPayPreRequest; use App\Request\ProtocolPayPreRequest;
use App\Request\RefundQueryRequest; use App\Request\RefundQueryRequest;
use App\Request\RegisterRequest; use App\Request\UnBindCardRequest;
use App\Service\AppService;
use App\Service\MerchantService;
use App\Service\PaymentService;
use Hyperf\Command\Annotation\Command;
use Hyperf\Command\Command as HyperfCommand; use Hyperf\Command\Command as HyperfCommand;
use Hyperf\Contract\ContainerInterface; use Hyperf\Contract\ContainerInterface;
/** /**
* @Command * @Command
*/ */
class JinlingCommand extends HyperfCommand class MineCommand extends HyperfCommand
{ {
/** /**
* @var ContainerInterface * @var ContainerInterface
@ -36,13 +30,13 @@ class JinlingCommand extends HyperfCommand
{ {
$this->container = $container; $this->container = $container;
parent::__construct('jinling'); parent::__construct('mine');
} }
public function configure(): void public function configure(): void
{ {
parent::configure(); parent::configure();
$this->setDescription('廖金灵测试'); $this->setDescription('我的测试');
} }
public function handle(): void public function handle(): void
@ -53,125 +47,9 @@ class JinlingCommand extends HyperfCommand
// $this->confirmPay(); // $this->confirmPay();
// $this->refund(); // $this->refund();
// $this->refundQuery(); // $this->refundQuery();
$this->paymentQuery(); // $this->paymentQuery();
$this->unbindCard();
return; return;
/*$ret = Api::certifiedPayment([
'outTradeNo' => time() . rand(1000, 9999),
'userName' => 'abc',
'phoneNum' => '18760419185',
'bankCardNo' => '6214835911385365',
'certificatesNo' => '350824199001105476',
'payAmount' => 100,
]);
var_dump($ret);
return;*/
/*$ret = Api::unifiedPayment();
var_dump($ret);
return;*/
/*$params = [
'app_id' => '202304270000004',
'timestamp' => time(),
'nonce_str' => StringHelper::getRandomString(32),
'data' => json_encode([
'test' => 1,
]),
];
$sign = \App\Helper\Platform\Signer::sign($params, 'lSHKbuFngCXHN8Ue1s8QHAAzPvOL3u9O');
$params['sign'] = $sign;
var_dump($params);
$request = new RegisterRequest($params);
$params = $request->getData();
var_dump($params);
return;*/
/*$ret = Api::unifiedPayment();
var_dump($ret);
return;*/
/*$ret = Api::register([
'merId' => "T100", // 562238003185933
'backUrl' => 'http://www.baidu.com',
'certificateName' => '测试',
'lawyerCertType' => 0,
'lawyerCertNo' => '430481198104234557',
'lawyerCertPhotoFront' => 'http://5b0988e595225.cdn.sohucs.com/images/20191031/e6a31c2611f042bbbfd39297243437a7.png',
'lawyerCertPhotoBack' => 'http://5b0988e595225.cdn.sohucs.com/images/20191031/e6a31c2611f042bbbfd39297243437a7.png',
'certificateTo' => '20500211',
'contactPhone' => '18888888888',
'accountType' => 3,
'canDownType' => '01',
]);
var_dump($ret);
return;*/
$ret = Api::bindCard([
'mchtOrderNo' => time() . rand(1000, 9999),
'memberId' => 'T01',
'userName' => '饶丽秀',
'phoneNum' => '13817896134',
// 'bankCardNo' => '622908113000409396',
'bankCardNo' => '6212261402022689613',
'bankCardType' => 'debit',
'certificatesNo' => '350824199001045864',
]);
var_dump($ret);
return;
echo \App\Helper\Efps\Signer::sign('sss');
$sm3 = new \OneSm\Sm3();
// 字符串签名
echo $sm3->sign('abc') . PHP_EOL;
echo $sm3->sign(str_repeat("adfas哈哈哈", 100)) . PHP_EOL;
return;
/**
* @var PaymentService $paymentService
*/
$paymentService = $this->container->make(PaymentService::class);
$paymentService = $this->container->make(PaymentService::class);
$paramsJson = '{"return_code":"SUCCESS","nonce_str":"4a40481401bb47cc81411ab3a8181bad","timestamp":1682659313039,"sign":"5AD859576B783CB44D1FAA0E7DD4C463","order_no":"TR23042830042195760003775","out_order_no":"2023042813194700001","total_amount":2,"currency":"AUD","order_time":"20230428151948","pay_time":"20230428152021","exchange_rate":459899100,"cny_amount":9}';
$params = json_decode($paramsJson, true);
$ret = $paymentService->notify($params);
var_dump($ret);
return;
$this->buildPayPrams();
return;
/**
* @var MerchantService $merchantService
*/
$merchantService = $this->container->make(MerchantService::class);
/**
* @var AppService $appService
*/
$appService = $this->container->make(AppService::class);
$merchant = $merchantService->createMerchant([
'username' => 'elf',
'password' => '123456',
'email' => '360197197@qq.com',
'mobile' => '18760419185',
'ip' => '127.0.0.1',
]);
$appService->createApp($merchant);
}
public function buildPayPrams(): void
{
$params = [
'app_id' => '202304270000004',
'timestamp' => time(),
'nonce_str' => 'lSHKbuFngCXHN8Ue1s8QHAAzPvOL3u9O',
];
$data = [
'order_name' => '测试订单',
'currency' => 'CNY',
'amount' => '10',
'notify_url' => 'https://www.baidu.com',
'redirect_url' => 'https://www.google.com',
'out_order_no' => '1122',
'direct_pay' => 0,
'show_pc_pay_url' => 0,
];
$params['data'] = json_encode($data);
$sign = Signer::sign($params, 'lSHKbuFngCXHN8Ue1s8QHAAzPvOL3u9O');
$params['sign'] = $sign;
var_dump(json_encode($params));
} }
public function bindCard() public function bindCard()
@ -182,13 +60,12 @@ class JinlingCommand extends HyperfCommand
'nonce_str' => StringHelper::getRandomString(32), 'nonce_str' => StringHelper::getRandomString(32),
'data' => json_encode([ 'data' => json_encode([
'mchtOrderNo' => time() . rand(1000, 9999), 'mchtOrderNo' => time() . rand(1000, 9999),
'memberId' => 'T01', 'memberId' => 'ABC',
'userName' => '饶丽秀', 'userName' => '测试者',
'phoneNum' => '13817896134', 'phoneNum' => '18888888888',
// 'bankCardNo' => '622908113000409396', 'bankCardNo' => '62122610000000000',
'bankCardNo' => '6212261402022689613',
'bankCardType' => 'debit', 'bankCardType' => 'debit',
'certificatesNo' => '350824199001045864', 'certificatesNo' => '350000000000000000',
]), ]),
]; ];
$sign = \App\Helper\Platform\Signer::sign($params, 'lSHKbuFngCXHN8Ue1s8QHAAzPvOL3u9O'); $sign = \App\Helper\Platform\Signer::sign($params, 'lSHKbuFngCXHN8Ue1s8QHAAzPvOL3u9O');
@ -206,9 +83,9 @@ class JinlingCommand extends HyperfCommand
'timestamp' => time(), 'timestamp' => time(),
'nonce_str' => StringHelper::getRandomString(32), 'nonce_str' => StringHelper::getRandomString(32),
'data' => json_encode([ 'data' => json_encode([
'memberId' => 'T01', 'memberId' => 'ABC',
'smsNo' => 'QY202305292233394504122', 'smsNo' => 'QY888888888888888',
'smsCode' => '485608', 'smsCode' => '123456',
]), ]),
]; ];
$sign = \App\Helper\Platform\Signer::sign($params, 'lSHKbuFngCXHN8Ue1s8QHAAzPvOL3u9O'); $sign = \App\Helper\Platform\Signer::sign($params, 'lSHKbuFngCXHN8Ue1s8QHAAzPvOL3u9O');
@ -228,7 +105,7 @@ class JinlingCommand extends HyperfCommand
'data' => json_encode([ 'data' => json_encode([
'memberId' => 'T01', 'memberId' => 'T01',
'outTradeNo' => time() . rand(1000, 9999), 'outTradeNo' => time() . rand(1000, 9999),
'protocol' => 'p202305296288304915744', 'protocol' => 'p88888888888888888',
'payAmount' => 1, 'payAmount' => 1,
]), ]),
]; ];
@ -247,9 +124,9 @@ class JinlingCommand extends HyperfCommand
'timestamp' => time(), 'timestamp' => time(),
'nonce_str' => StringHelper::getRandomString(32), 'nonce_str' => StringHelper::getRandomString(32),
'data' => json_encode([ 'data' => json_encode([
'token' => '83f93a2b0a134d358dde920d9b7abca0', 'token' => 's3skls8d3402skfj23',
'protocol' => 'p202305296288304915744', 'protocol' => 'p88888888888888888',
'smsCode' => '466592', 'smsCode' => '123456',
]), ]),
]; ];
$sign = \App\Helper\Platform\Signer::sign($params, 'lSHKbuFngCXHN8Ue1s8QHAAzPvOL3u9O'); $sign = \App\Helper\Platform\Signer::sign($params, 'lSHKbuFngCXHN8Ue1s8QHAAzPvOL3u9O');
@ -268,10 +145,10 @@ class JinlingCommand extends HyperfCommand
'nonce_str' => StringHelper::getRandomString(32), 'nonce_str' => StringHelper::getRandomString(32),
'data' => json_encode([ 'data' => json_encode([
'outRefundNo' => time() . rand(1000, 9999), 'outRefundNo' => time() . rand(1000, 9999),
'remark' => '退款', 'remark' => 'xxx',
'amount' => 1, 'amount' => 88,
'refundAmount' => 1, 'refundAmount' => 88,
'outTradeNo' => '16853732799380', 'outTradeNo' => '123423423532',
]), ]),
]; ];
$sign = \App\Helper\Platform\Signer::sign($params, 'lSHKbuFngCXHN8Ue1s8QHAAzPvOL3u9O'); $sign = \App\Helper\Platform\Signer::sign($params, 'lSHKbuFngCXHN8Ue1s8QHAAzPvOL3u9O');
@ -289,7 +166,7 @@ class JinlingCommand extends HyperfCommand
'timestamp' => time(), 'timestamp' => time(),
'nonce_str' => StringHelper::getRandomString(32), 'nonce_str' => StringHelper::getRandomString(32),
'data' => json_encode([ 'data' => json_encode([
'outRefundNo' => '16853743952501', 'outRefundNo' => '237427342388',
]), ]),
]; ];
$sign = \App\Helper\Platform\Signer::sign($params, 'lSHKbuFngCXHN8Ue1s8QHAAzPvOL3u9O'); $sign = \App\Helper\Platform\Signer::sign($params, 'lSHKbuFngCXHN8Ue1s8QHAAzPvOL3u9O');
@ -307,7 +184,7 @@ class JinlingCommand extends HyperfCommand
'timestamp' => time(), 'timestamp' => time(),
'nonce_str' => StringHelper::getRandomString(32), 'nonce_str' => StringHelper::getRandomString(32),
'data' => json_encode([ 'data' => json_encode([
'outTradeNo' => '16853732799380', 'outTradeNo' => '3423423432',
]), ]),
]; ];
$sign = \App\Helper\Platform\Signer::sign($params, 'lSHKbuFngCXHN8Ue1s8QHAAzPvOL3u9O'); $sign = \App\Helper\Platform\Signer::sign($params, 'lSHKbuFngCXHN8Ue1s8QHAAzPvOL3u9O');
@ -317,4 +194,23 @@ class JinlingCommand extends HyperfCommand
$params = $request->getData(); $params = $request->getData();
var_dump($params); var_dump($params);
} }
public function unbindCard()
{
$params = [
'app_id' => '202304270000004',
'timestamp' => time(),
'nonce_str' => StringHelper::getRandomString(32),
'data' => json_encode([
'protocol' => 'p88888888888888888',
'memberId' => 'ABC',
]),
];
$sign = \App\Helper\Platform\Signer::sign($params, 'lSHKbuFngCXHN8Ue1s8QHAAzPvOL3u9O');
$params['sign'] = $sign;
var_dump($params);
$request = new UnBindCardRequest($params);
$params = $request->getData();
var_dump($params);
}
} }

@ -1,78 +0,0 @@
<?php
declare(strict_types=1);
namespace App\Helper\OmiPay;
use App\Helper\Log;
use App\Helper\OmiPay\Request\AbstractRequest;
use App\Helper\StringHelper;
use App\Helper\TimeHelper;
use Exception;
use GuzzleHttp\Client;
use Hyperf\Guzzle\CoroutineHandler;
use GuzzleHttp\HandlerStack;
abstract class AbstractApi
{
protected static $client;
protected static function getCommonParams() {
$params = [
'm_number' => Config::get('app_id'),
'timestamp' => TimeHelper::getMillisecond(),
'nonce_str' => StringHelper::getRandomString(32),
];
$params['sign'] = Signer::sign($params);
return $params;
}
public static function request(AbstractRequest $request) {
$params = self::getCommonParams();
$params = array_merge($params, $request->getParams());
try {
Log::info('url:' . $request->getUrl(), [], 'omipay');
$response = self::getClient()->post($request->getUrl(), [
'query' => $params
]);
Log::info('request:', $params, 'omipay');
$body = (string)$response->getBody();
Log::info('response:' . $body, [], 'omipay');
$result = json_decode($body, true);
if (empty($result)) {
$result = [
'return_code' => 'FAIL',
'error_code' => 'RESPONSE_ERROR',
'error_msg' => '返回数据异常',
];
}
return new Result($result);
} catch (Exception $e) {
Log::error('error:' . $e->getMessage(), [], 'omipay');
return new Result([
'return_code' => 'FAIL',
'error_code' => 'NETWORK_ERROR',
'error_msg' => '网络错误',
]);
}
}
protected static function getClient(): Client {
if (!self::$client) {
self::$client = new Client([
'base_uri' => Config::get('base_url'),
'handler' => HandlerStack::create(new CoroutineHandler()),
'headers' => [
'Content-Type' => 'application/json',
],
'timeout' => 5,
'swoole' => [
'timeout' => 10,
'socket_buffer_size' => 1024 * 1024 * 2,
],
]);
}
return self::$client;
}
}

@ -1,49 +0,0 @@
<?php
declare(strict_types=1);
namespace App\Helper\OmiPay;
use App\Helper\OmiPay\Request\GetExchangeRateRequest;
use App\Helper\OmiPay\Request\MakeJSAPIOrderRequest;
use App\Helper\OmiPay\Request\QueryRefundRequest;
use App\Helper\OmiPay\Request\RefundRequest;
class Api extends AbstractApi
{
public static function getExchangeRate($currency, $baseCurrency, $platform = 'WECHATPAY', $language = 'CHS') {
$request = new GetExchangeRateRequest();
$request->setCurrency($currency);
$request->setBaseCurrency($baseCurrency);
$request->setPlatform($platform);
$request->setLanguage($language);
return self::request($request);
}
public static function makeJSAPIOrder($orderName, $outOrderNo, $currency, $amount, $notifyUrl, $redirectUrl) {
$request = new MakeJSAPIOrderRequest();
$request->setOrderName($orderName);
$request->setCurrency($currency);
$request->setOutOrderNo($outOrderNo);
$request->setAmount($amount);
$request->setNotifyUrl($notifyUrl);
$request->setRedirectUrl($redirectUrl);
$request->setDirectPay(0);
$request->setShowPcPayUrl(0);
return self::request($request);
}
public static function refund($orderNo, $outRefundNo, $amount) {
$request = new RefundRequest();
$request->setOrderNo($orderNo);
$request->setOutRefundNo($outRefundNo);
$request->setAmount($amount);
return self::request($request);
}
public static function queryRefund($refundNo) {
$request = new QueryRefundRequest();
$request->setRefundNo($refundNo);
return self::request($request);
}
}

@ -1,21 +0,0 @@
<?php
declare(strict_types=1);
namespace App\Helper\OmiPay;
use App\Helper\StringHelper;
use App\Helper\TimeHelper;
class Config
{
private static $params = [
'app_id' => '30042195760',
'secret_key' => 'cea6f34bea8640dea91fd8b7a926a9a5',
'base_url' => 'https://www.omipay.com.cn',
];
public static function get($key) {
return self::$params[$key] ?: null;
}
}

@ -1,34 +0,0 @@
<?php
declare(strict_types=1);
namespace App\Helper\OmiPay\Request;
use App\Helper\OmiPay\Config;
abstract class AbstractRequest
{
protected $uri;
protected $method;
protected $_params = [];
public function getUrl() {
return Config::get('base_url') . $this->uri;
}
public function getParams() {
return $this->_params;
}
public function __get($name)
{
return $this->_params[$name];
}
public function __set($name, $value)
{
$this->_params[$name] = $value;
}
}

@ -1,26 +0,0 @@
<?php
declare(strict_types=1);
namespace App\Helper\OmiPay\Request;
class GetExchangeRateRequest extends AbstractRequest
{
protected $uri = '/omipay/api/v2/GetExchangeRate';
public function setCurrency($currency) {
$this->currency = $currency;
}
public function setBaseCurrency($baseCurrency) {
$this->base_currency = $baseCurrency;
}
public function setPlatform($platform) {
$this->platform = $platform;
}
public function setLanguage($language) {
$this->language = $language;
}
}

@ -1,50 +0,0 @@
<?php
declare(strict_types=1);
namespace App\Helper\OmiPay\Request;
class MakeJSAPIOrderRequest extends AbstractRequest
{
protected $uri = '/omipay/api/v2/MakeJSAPIOrder';
public function setOrderName($orderName) {
$this->order_name = $orderName;
}
public function setOutOrderNo($outOrderNo) {
$this->out_order_no = $outOrderNo;
}
public function setCurrency($currency) {
$this->currency = $currency;
}
public function setAmount($amount) {
$this->amount = $amount;
}
public function setNotifyUrl($notifyUrl) {
$this->notify_url = $notifyUrl;
}
public function setRedirectUrl($redirectUrl) {
$this->redirect_url = $redirectUrl;
}
public function setDirectPay($directPay) {
$this->direct_pay = $directPay;
}
public function setShowPcPayUrl($showPcPayUrl) {
$this->show_pc_pay_url = $showPcPayUrl;
}
public function setONumber($oNumber) {
$this->o_number = $oNumber;
}
public function setPosNo($posNo) {
$this->pos_no = $posNo;
}
}

@ -1,14 +0,0 @@
<?php
declare(strict_types=1);
namespace App\Helper\OmiPay\Request;
class QueryOrderRequest extends AbstractRequest
{
protected $uri = '/omipay/api/v2/QueryOrder';
public function setOrderNo($orderNo) {
$this->order_no = $orderNo;
}
}

@ -1,14 +0,0 @@
<?php
declare(strict_types=1);
namespace App\Helper\OmiPay\Request;
class QueryRefundRequest extends AbstractRequest
{
protected $uri = '/omipay/api/v2/QueryRefund';
public function setRefundNo($refundNo) {
$this->refund_no = $refundNo;
}
}

@ -1,22 +0,0 @@
<?php
declare(strict_types=1);
namespace App\Helper\OmiPay\Request;
class RefundRequest extends AbstractRequest
{
protected $uri = '/omipay/api/v2/Refund';
public function setOrderNo($orderNo) {
$this->order_no = $orderNo;
}
public function setOutRefundNo($outRefundNo) {
$this->out_refund_no = $outRefundNo;
}
public function setAmount($amount) {
$this->amount = $amount;
}
}

@ -1,36 +0,0 @@
<?php
declare(strict_types=1);
namespace App\Helper\OmiPay;
class Result
{
private $data;
public function __construct($data)
{
$this->data = $data;
}
public function isSuccess() {
return $this->data['return_code'] == 'SUCCESS';
}
public function get($key) {
return $this->data[$key] ?? null;
}
public function toArray()
{
$data = [];
if ($this->isSuccess()) {
$data['is_success'] = true;
$data['pay_url'] = $this->get('casherUrl');
} else {
$data['error_code'] = $this->get('returnCode');
$data['error_msg'] = $this->get('returnMsg');
}
return $data;
}
}

@ -1,23 +0,0 @@
<?php
declare(strict_types=1);
namespace App\Helper\OmiPay;
class Signer
{
public static function sign($params) {
$mNumber = $params['m_number'] ?? '';
$mNumber = $mNumber ? $mNumber : Config::get('app_id');
$signString = $mNumber . '&'
. $params['timestamp'] . '&'
. $params['nonce_str'] . '&'
. Config::get('secret_key');
return strtoupper(md5($signString));
}
public static function verify($params) {
$sign = $params['sign'] ?? '';
return $sign == self::sign($params);
}
}
Loading…
Cancel
Save