-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
tongjingcheng
committed
Dec 10, 2019
1 parent
013a545
commit 17e996e
Showing
10 changed files
with
389 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?php | ||
require "../../vendor/autoload.php"; | ||
|
||
use Kltong\Pay\Config\Channel; | ||
use Kltong\Pay\Client\Charge; | ||
use Kltong\Pay\Exception\PayException; | ||
|
||
$pre_card_config = new \Kltong\Pay\Config\PreCardConfig(); | ||
$pre_card_config->setDev(1)->setMerchantId('903310112340001') | ||
->setPkcs12(dirname(__FILE__) . DIRECTORY_SEPARATOR . '903310112340001-kltong.pfx') | ||
->setPkcsPassword('123456'); | ||
$data = [ | ||
'cardId'=>'8889990010000028810', | ||
'txAt'=>1, | ||
'reqSeq'=>date("mdHis").random_int(1,100000), | ||
'pin1'=>'580058', | ||
|
||
]; | ||
try{ | ||
$result = Charge::execute(Channel::PRECARD_CARDWITHPASS,$pre_card_config,$data); | ||
}catch (PayException $e){ | ||
exit($e->getMessage()); | ||
}catch(Exception $e){ | ||
exit($e->getMessage()); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
<?php | ||
namespace Kltong\Pay\Biz; | ||
|
||
use Kltong\Pay\Common\PreCardProcess; | ||
use Kltong\Pay\Request\CardPassContent; | ||
use Kltong\Pay\Utils\ArrayParams; | ||
use Kltong\Pay\Utils\RSA; | ||
|
||
/** | ||
* Class CardWithPassBiz | ||
* @package Kltong\Pay\Biz | ||
*/ | ||
class CardWithPassBiz extends PreCardProcess | ||
{ | ||
|
||
public $head; | ||
public $content; | ||
|
||
|
||
private function process_data(){ | ||
$cardPassContent = new CardPassContent(); | ||
$cardPassContent->merchantId = $this->pre_card_config->getMerchantId(); | ||
$cardPassContent->version = $this->pre_card_config->getVersion(); | ||
$cardPassContent->signType = $this->pre_card_config->getSignType(); | ||
$this->cardPassContent = $cardPassContent; | ||
} | ||
|
||
private function process_content(){ | ||
$this->cardPassContent->cardId = $this->pre_card_data['cardId']; | ||
$this->cardPassContent->pin1 = $this->pre_card_data['pin1']; | ||
$this->cardPassContent->txAt = $this->pre_card_data['txAt']; | ||
$this->cardPassContent->reqDt = date("Ymd"); | ||
$this->cardPassContent->reqTm = date("His"); | ||
$this->cardPassContent->reqSeq = $this->pre_card_data['reqSeq']; | ||
|
||
} | ||
|
||
public function process(){ | ||
$this->process_data(); | ||
$this->process_content(); | ||
//处理加答前参数 | ||
$string = ArrayParams::get_sign_string($this->cardPassContent->toArray()); | ||
$sign = RSA::getSign($string,file_get_contents($this->pre_card_config->getPkcs12()),$this->pre_card_config->getPkcsPassword()); | ||
$this->cardPassContent->sign = $sign ; | ||
|
||
$head = ""; | ||
$content = ''; | ||
$content = array( | ||
'cardId'=>$this->cardPassContent->cardId, | ||
'txAt'=>$this->cardPassContent->txAt, | ||
'reqDt'=>$this->cardPassContent->reqDt, | ||
'reqTm'=>$this->cardPassContent->reqTm, | ||
'reqSeq'=>$this->cardPassContent->reqSeq, | ||
'pin1'=>$this->cardPassContent->pin1, | ||
); | ||
$newContent = array(); | ||
foreach ($content as $k=>$val){ | ||
if(!empty($val)){ | ||
$newContent[$k]=$val; | ||
} | ||
} | ||
$head = $this->get_header(); | ||
$requet_data = array( | ||
'head'=>$head, | ||
'content'=> $newContent | ||
); | ||
return $requet_data; | ||
|
||
} | ||
|
||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
<?php | ||
namespace Kltong\Pay\Common; | ||
|
||
use GuzzleHttp\Client; | ||
use Kltong\Pay\Config\PreCardConfig; | ||
use Kltong\Pay\Exception\PayException; | ||
|
||
class PreCardProcess implements BaseStrategy | ||
{ | ||
/** | ||
* 商户配置 | ||
* @var PreCardConfig|null | ||
*/ | ||
public $pre_card_config = null; | ||
|
||
public $pre_card_data = array(); | ||
|
||
public $cardPassContent = array(); | ||
/** | ||
* 请求参数 | ||
* @var array | ||
*/ | ||
public $requestData = array(); | ||
|
||
|
||
public function __construct(PreCardConfig $config) | ||
{ | ||
if(empty($config->merchantId)){ | ||
throw new PayException("未设置商户号"); | ||
} | ||
if(empty($config->pkcs12)){ | ||
throw new PayException("未设置证书"); | ||
} | ||
if(empty($config->pkcsPassword)){ | ||
throw new PayException("未设置证书密码"); | ||
} | ||
$this->pre_card_config = $config; | ||
} | ||
|
||
/** | ||
* @inheritDoc | ||
*/ | ||
public function handle(array $data) | ||
{ | ||
$this->pre_card_data = $data; | ||
$data = $this->process(); | ||
if($this->pre_card_config->getDev() =="1"){ | ||
$url = 'https://ipay.chinasmartpay.cn/openapi/LianxinCard/pay'; | ||
}else{ | ||
$url = 'https://openapi.openepay.com/openapi/LianxinCard/pay'; | ||
} | ||
|
||
$client = new Client([ | ||
'timeout' => '10.0' | ||
]); | ||
$response = $client->request('POST', $url, ['timeout'=>5,'verify'=>false,'json'=>$data]); | ||
if ($response->getStatusCode() != '200') { | ||
throw new PayException('网络发生错误,请稍后再试curl返回码:' . $response->getReasonPhrase()); | ||
} | ||
$body = $response->getBody(); | ||
// 格式化为数组 | ||
$retData = json_decode($body,true); | ||
if (isset($retData['responseCode']) && $retData['responseCode']!= 'SUCCESS') { | ||
throw new PayException('支付失败:' . $retData['responseMsg']); | ||
} | ||
return $retData; | ||
|
||
|
||
} | ||
|
||
|
||
public function get_header(){ | ||
return array( | ||
'version'=>$this->cardPassContent->version, | ||
'merchantId'=>$this->cardPassContent->merchantId, | ||
'signType'=>$this->cardPassContent->signType, | ||
'sign' => $this->cardPassContent->sign | ||
); | ||
} | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
<?php | ||
namespace Kltong\Pay; | ||
namespace Kltong\Pay\Config; | ||
|
||
/** | ||
* 常量 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,130 @@ | ||
<?php | ||
namespace Kltong\Pay\Config; | ||
|
||
/** | ||
* 商户信信配置 | ||
* Class PreCardConfig | ||
* @package Kltong\Pay\Config | ||
*/ | ||
class PreCardConfig | ||
{ | ||
public $merchantId; | ||
public $pkcs12; | ||
public $pkcsPassword; | ||
public $signType = 2; | ||
public $dev = 1; | ||
public $version = '1.0'; | ||
|
||
/** | ||
* @return mixed | ||
*/ | ||
public function getMerchantId() | ||
{ | ||
return $this->merchantId; | ||
} | ||
|
||
/** | ||
* @param $merchantId | ||
* @return $this | ||
*/ | ||
public function setMerchantId($merchantId) | ||
{ | ||
$this->merchantId = $merchantId; | ||
return $this; | ||
} | ||
|
||
/** | ||
* @return mixed | ||
*/ | ||
public function getPkcs12() | ||
{ | ||
return $this->pkcs12; | ||
} | ||
|
||
/** | ||
* @param $pkcs12 | ||
* @return $this | ||
*/ | ||
public function setPkcs12($pkcs12) | ||
{ | ||
$this->pkcs12 = $pkcs12; | ||
return $this; | ||
} | ||
|
||
/** | ||
* @return mixed | ||
*/ | ||
public function getPkcsPassword() | ||
{ | ||
return $this->pkcsPassword; | ||
} | ||
|
||
/** | ||
* @param $pkcsPassword | ||
* @return $this | ||
*/ | ||
public function setPkcsPassword($pkcsPassword) | ||
{ | ||
$this->pkcsPassword = $pkcsPassword; | ||
return $this; | ||
} | ||
|
||
/** | ||
* @return int | ||
*/ | ||
public function getSignType() | ||
{ | ||
return $this->signType; | ||
} | ||
|
||
/** | ||
* @param $signType | ||
* @return $this | ||
*/ | ||
public function setSignType($signType) | ||
{ | ||
if(empty($signType)){ | ||
return $this; | ||
} | ||
$this->signType = $signType == 1 ? 1 :2; | ||
return $this; | ||
} | ||
|
||
/** | ||
* @return int | ||
*/ | ||
public function getDev() | ||
{ | ||
return $this->dev; | ||
} | ||
|
||
/** | ||
* @param $dev | ||
* @return $this | ||
*/ | ||
public function setDev($dev) | ||
{ | ||
$this->dev = $dev == 1 ? 1 :2; | ||
return $this; | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getVersion() | ||
{ | ||
return $this->version; | ||
} | ||
|
||
/** | ||
* @param $version | ||
* @return $this | ||
*/ | ||
public function setVersion($version) | ||
{ | ||
$this->version = $version; | ||
return $this; | ||
} | ||
|
||
|
||
} |
Oops, something went wrong.