<?
namespace app\api\controller;
use app\common\controller\Api;
use app\common\library\Log;
use fast\Rsa;
use function GuzzleHttp\Psr7\str;
class JlBank extends Api
{
protected $noNeedLogin ='*';
protected $noNeedRight = '*';
protected $name=""; // 真实姓名
protected $card=""; // 银行卡号
protected $mobile=""; // 手机号
protected $userid=""; // 用户ID
protected $idcard=""; // 身份证号
protected $account=""; // 订单金额 / 退款金额
protected $smsMsg=""; // 短信验证码
protected $orderId=""; // 订单id 20到32位
protected $orderNo=""; // 订单号
protected $subOrderNo=""; // 子订单号
protected $accounts=""; // 订单金额
protected $isvNo="I00000000"; // 订单金额
protected $head = [
'encNo'=>'JL_RSA_RD',
'encType'=>'01',
'signNo'=>'RD_SHA256WithRSA_JL',
'signType'=>'01',
'sndNo'=>'RD',
];
public function __construct($name="银联五", $card="6212149999950000042" ,$mobile="13888888888" ,
$userid ="26677" ,$idcard="310115198903261113" ,$account="100",$smsMsg = "123456" ,
$orderId = "123456789123456789009",$orderNo = "O202109011102061250221962045678903" ,$subOrderNo="SO202109011102061250084200145678903")
{
$this->name = $name;
$this->card = $card;
$this->mobile = $mobile;
$this->userid = $userid;
$this->idcard = $idcard;
$this->smsMsg = $smsMsg;
$this->orderId = time().time();
$this->orderNo = $orderNo;
$this->subOrderNo = $subOrderNo;
$this->accounts = $account;
}
/*
* 绑卡
*/
public function bangka(){
$head = $this->head;
$params = [
'sgnAcctName' => $this->name, // 姓名
'sgnIdNo' => $this->idcard, // 身份证
'isvNo' => $this->isvNo, // 平台服务商编号
'cardNo' => $this->card, // 卡号
// 'isvTxNo' => "12345678912345601", // 平台服务商流水号
'outIdentifyCode' => $this->userid, // 用户id
'sgnMobNo' => $this->mobile, // 手机号
'validDate' => date('Ymd',time()),
];
// $body = json_encode($params);
$m1 = $this->public_key_encrypt(json_encode($params)); //公钥加密
$body = $m1;
$m2 = $this->getSign(base64_decode($m1)); //签名
$sign = $m2;
$data = array(
'head' => $head,
'body'=>$body,
'sign'=>$sign
);
// dump(json_encode($data));
// die;
$url = "https://bmptest.jlbank.com.cn:8888/api/custom/PRDAcctBindApply";
$res = $this->testPost($url,$data);
if ($res){
$msg = $this->jie($res['body']);
if ($msg['retCode'] == '0000'){
$this->success($msg['retMsg']);
}else{
$this->error($msg['retMsg']);
}
}else{
$this->error('请求失败',$res);
}
}
/**
* 绑卡短信
*/
public function bangka_send()
{
$head = $this->head;
$params = [
'isvNo' => $this->isvNo, // 平台服务商编号
'cardNo' => $this->card, // 卡号
// 'isvTxNo' => "12345678912345601", // 平台服务商流水号
'outIdentifyCode' => $this->userid, // 用户id
'sgnMobNo' => $this->mobile, // 手机号
];
// $body = json_encode($params);
$m1 = $this->public_key_encrypt(json_encode($params)); //公钥加密
$body = $m1;
$m2 = $this->getSign(base64_decode($m1,true)); //签名
$sign = $m2;
$data = array(
'head' => $head,
'body'=>$body,
'sign'=>$sign
);
$url = "https://bmptest.jlbank.com.cn:8888/api/custom/RDSendMsg";
$res = $this->testPost($url,$data);
if ($res){
$msg = $this->jie($res['body']);
if ($msg['retCode'] == '0000'){
$this->success($msg['retMsg']);
}else{
$this->error($msg['retMsg']);
}
}else{
$this->error('请求失败',$res);
}
}
/***
* 绑卡确认
*/
public function bangkaqr(){
$head = $this->head;
$params = [
'isvNo' => $this->isvNo, // 平台服务商编号
'cardNo' => $this->card, // 卡号
// 'isvTxNo' => "12345678912345601", //平台服务商流水号
'outIdentifyCode' => $this->userid, //用户ID
'sgnAcctName' => $this->name, // 姓名
'sgnIdNo' => $this->idcard, // 身份证
'sgnMobNo' => $this->mobile, //手机号
'validDate' => date('Ymd',time()),
'smsMsg' => $this->smsMsg // 短信码
];
// $body = json_encode($params);
$m1 = $this->public_key_encrypt(json_encode($params)); //公钥加密
$body = $m1;
$m2 = $this->getSign(base64_decode($m1)); //签名
$sign = $m2;
$data = array(
'head' => $head,
'body'=>$body,
'sign'=>$sign
);
$url = "https://bmptest.jlbank.com.cn:8888/api/custom/PRDAcctBindConfirm";
$res = $this->testPost($url,$data);
if ($res){
$msg = $this->jie($res['body']);
if ($msg['retCode'] == '0000'){
$this->success($msg['retMsg']);
}else{
$this->error($msg['retMsg']);
}
}else{
$this->error('请求失败',$res);
}
}
/***
* 解绑银行卡
*/
public function bangkajb(){
$head = $this->head;
$params = [
'isvNo' => $this->isvNo,
'cardNo' => $this->card, // 卡号
// 'isvTxNo' => "123456789123456", //平台服务商流水号
'outIdentifyCode' => $this->userid, // 用户id
];
// $body = json_encode($params);
$m1 = $this->public_key_encrypt(json_encode($params)); //公钥加密
$body = $m1;
$m2 = $this->getSign(base64_decode($m1)); //签名
$sign = $m2;
$data = array(
'head' => $head,
'body'=>$body,
'sign'=>$sign
);
$url = "https://bmptest.jlbank.com.cn:8888/api/custom/PAcctUnbind";
$res = $this->testPost($url,$data);
if ($res){
$msg = $this->jie($res['body']);
if ($msg['retCode'] == '0000'){
$this->success($msg['retMsg']);
}else{
$this->error($msg['retMsg']);
}
}else{
$this->error('请求失败',$res);
}
}
/**
* 预下单
*/
public function yuXiaDan(){
$head = $this->head;
$params = [
'isvNo' => $this->isvNo,
'outIdentifyCode' => $this->userid, // 用户id
"acctNo" => $this->card, // 卡号
'sgnAcctName' => $this->name, // 姓名
'sgnIdNo' => $this->idcard, // 身份证
'sgnMobNo' => $this->mobile, // 手机号
'orderInfo' => [
'tradeNo' => $this->orderId, // 商户母订单号
'orderType' => "COMMON", // 订单类型 普通订单/担保订单
'orderKind' => "E_SHOP",
'amount' => $this->accounts, // 金额
],
'subOrderInfo' => [ //子订单信息
'subMchtNo' => "M00072602" , //商户编号
'subTradeNo' => $this->orderId, //商户子订单号
'subOrderAmount' => $this->accounts, //子订单金额
'IsNeedRoyalty' => "N",
"platformRoyalty" => "0",
"merchantRoyalty" => "0",
'leasesInfo' => [
'lessorName' => "银联五",//租赁方名称
'lessorIdNo' => "210727199712054815", //租赁方证件号
'lessorAddr' => "开运安居小区", //租赁方地址
'lessorPhone' => "13596039426", //租赁方联系方式
'tenantName' => "润德", //承租方名称
'tenantIdNo' => "220181199904030303", //承租方证件号
'tenantAddr' => "开运安居小区", //承租方地址
'tenantPhone' => "17767749257", //承租方联系方式
'rent' => "10", //租金
'payMethod' => "wx", //支付方式
'purpose' => "家用", //住房用途
'leaseTerm' => "月", //租赁期限
],
],
];
// $body = json_encode($params);
$m1 = $this->public_key_encrypt(json_encode($params)); //公钥加密
$body = $m1;
$m2 = $this->getSign(base64_decode($m1)); //签名
$sign = $m2;
$data = array(
'head' => $head,
'body'=>$body,
'sign'=>$sign
);
$url = "https://bmptest.jlbank.com.cn:8888/api/group/RDStdOrderApply";
$res = $this->testPost($url,$data);
if ($res){
$msg = $this->jie($res['body']);
dump($msg);
die;
if ($msg['retCode'] == '0000'){
$this->success($msg['retMsg']);
}else{
$this->error($msg['retMsg'],'');
}
}else{
$this->error('请求失败',$res);
}
}
/**
* 支付短信
*/
public function pay_send()
{
$head = $this->head;
$params = [
'isvNo' => $this->isvNo, // 平台服务商编号
// 'isvTxNo' => "12345678912345601", // 平台服务商流水号
'outIdentifyCode' => $this->userid, // 用户id
'sgnMobNo' => $this->mobile, // 手机号
];
// $body = json_encode($params);
$m1 = $this->public_key_encrypt(json_encode($params)); //公钥加密
$body = $m1;
$m2 = $this->getSign(base64_decode($m1,true)); //签名
$sign = $m2;
$data = array(
'head' => $head,
'body'=>$body,
// 'sign'=>$sign
);
$url = "https://bmptest.jlbank.com.cn:8888/api/custom/RDPayToSMS";
$res = $this->testPost($url,$data);
if ($res){
$msg = $this->jie($res['body']);
if ($msg['retCode'] == '0000'){
$this->success($msg['retMsg']);
}else{
$this->error($msg['retMsg']);
}
}else{
$this->error('请求失败',$res);
}
}
/**
* 支付
*/
public function pay(){
$head = $this->head;
$params = [
'isvNo' => $this->isvNo,
'outIdentifyCode' => $this->userid, // 用户id
"signAgreeNo" => "", //签约协议号
"acctNo" => $this->card, // 卡号
'sgnAcctName' => $this->name, // 姓名
'sgnIdNo' => $this->idcard, // 身份证
'sgnMobNo' => $this->mobile, // 手机号
'smsMsg' => $this->smsMsg , // 短信码
'orderInfo' => [
"orderNo" => $this->orderNo, // 预下单返回的订单号
'tradeNo' => $this->orderId, // 商户母订单号
"tradeDate" => date('Ymd',time()),
"tradeTime" => date('His',time()),
'orderType' => "COMMON", // 订单类型 普通订单/担保订单
'orderKind' => "E_SHOP",
'amount' =>$this->accounts, // 金额
],
];
// $body = json_encode($params);
$m1 = $this->public_key_encrypt(json_encode($params)); //公钥加密
$body = $m1;
$m2 = $this->getSign(base64_decode($m1)); //签名
$sign = $m2;
$data = array(
'head' => $head,
'body'=>$body,
'sign'=>$sign
);
$url = "https://bmptest.jlbank.com.cn:8888/api/group/RDStdQuickGroupPay";
$res = $this->testPost($url,$data);
if ($res){
$msg = $this->jie($res['body']);
if ($msg['retCode'] == '0000'){
$this->success($msg['retMsg']);
}else{
$this->error($msg['retMsg']);
}
}else{
$this->error('请求失败',$res);
}
}
/**
* 退款申请
*/
public function refundApply(){
$head = $this->head;
$params = [
'isvId' => $this->isvNo,
'outIdentifyCode' => $this->userid, // 用户id
'phone' => $this->mobile ,
'refundTxnNo' => $this->orderId, //退款流水号20到32位字符串 自定义
];
// $body = json_encode($params);
//
$m1 = $this->public_key_encrypt(json_encode($params)); //公钥加密
$body = $m1;
$m2 = $this->getSign(base64_decode($m1)); //签名
$sign = $m2;
$data = array(
'head' => $head,
'body'=>$body,
'sign'=>$sign
);
$url = "https://bmptest.jlbank.com.cn:8888/api/group/RdOrderRefundApply";
$res = $this->testPost($url,$data);
if ($res){
$msg = $this->jie($res['body']);
if ($msg['retCode'] == '0000'){
$this->success($msg['retMsg']);
}else{
$this->error($msg['retMsg']);
}
}else{
$this->error('请求失败',$res);
}
}
/**
* 退款
*/
public function refund(){
$head = $this->head;
$params = [
'isvNo' => $this->isvNo,
'outIdentifyCode' => $this->userid, // 用户id
"refundType" => "SUBORDER_REFUND" , //退货类型
"orderNo" => $this->orderNo, // 预下单返回的订单号
'refundTxnNo' => $this->orderId, //退款流水号20到32位字符串 自定义
'authCode' => $this->smsMsg, //短信码
'subOrder' => [
'subOrderNo' => $this->subOrderNo, // 子订单号
'subOrderAmount' => $this->accounts, // 金额
],
'cardNo' => $this->card, //可填可不填,不填时默认退回到原绑定卡中,否则退回到这张卡中 ,银行卡号,可为他人他行卡,没有限制
'nameInCard' => $this->name, // cardNo所属人的开卡姓名
];
// $body = json_encode($params);
$m1 = $this->public_key_encrypt(json_encode($params)); //公钥加密
$body = $m1;
$m2 = $this->getSign(base64_decode($m1)); //签名
$sign = $m2;
$data = array(
'head' => $head,
'body'=>$body,
'sign'=>$sign
);
$url = "https://bmptest.jlbank.com.cn:8888/api/group/RdOrderRefund";
$res = $this->testPost($url,$data);
if ($res){
$msg = $this->jie($res['body']);
if ($msg['retCode'] == '0000'){
$this->success($msg['retMsg']);
}else{
$this->error($msg['retMsg']);
}
}else{
$this->error('请求失败',$res);
}
}
// 公钥加密
public function jia()
{
$str = input('str');
$res = $this->public_key_encrypt($str);
$this->success('',$res);
}
// 私钥解密
public function jie($str)
{
$res = $this->private_key_decrypt($str);
$res = json_decode($res,true);
if ($res['retCode'] == "0000"){
return $res;
}else{
(new Log())->log('error','吉林银行',$res);
return $res;
}
}
// 验签
public function qian()
{
$str = input('str');
$sign = input('sign');
$sign = str_replace("\\r\\n", "", $sign);
// $str = 'aaaa';
// $byte_arr = $this->scBytes($str);
//
// $sign = $this->getSign($str);
//
// var_dump($this->scBytes($str));
// var_dump($sign);
// var_dump($this->scBytes($sign));
// exit;
// $sign = [58, -119, -16, 84, -61, -50, -54, 123, -78, 125, 44, -54, -103, -90, 108, 65, 95, -110, -56, 18, -74, 109, -100, 40, 105, 122, 29, -19, -118, -74, -88, 10, 43, 105, -73, 103, -16, 59, 0, -43, 75, 17, -18, 40, -86, 38, -18, -104, 27, 99, -110, 11, 14, -107, -33, -10, 64, -41, -89, -45, 116, -34, 6, 90, 68, -23, 81, -106, 11, 62, -57, -59, 21, 8, -21, -39, 47, 105, 81, -60, -81, -78, -70, 46, -107, 113, 46, 110, 79, -51, 47, -53, 24, 109, -101, 95, -9, 63, -79, 92, -68, 2, -3, -121, -32, 34, -115, -26, 95, -30, 30, 15, 2, 14, 5, -19, -50, -20, -102, 25, -86, -109, -69, -97, 20, -66, -117, 74, 127, 110, 110, -63, -59, 87, -25, -44, -124, -40, 98, 90, 109, 31, -48, -103, 49, -95, -27, 54, -124, 46, 12, 14, -102, -84, 62, 90, 92, 82, -87, -107, 22, 24, 68, -34, -117, -37, -50, 73, -102, -3, -56, 83, -113, 27, -71, -115, -45, 16, 88, -48, -5, -69, 36, -61, -86, -50, 108, -98, 119, -51, 99, -29, 32, 85, 35, -42, -28, -98, -3, -73, 67, -122, 42, 27, -87, 63, -56, 118, 96, -74, -34, -15, 62, 124, -9, 125, 113, -72, -23, -70, -86, -106, -109, -24, -66, 83, -40, 10, 121, 43, -96, 64, -24, -111, -116, 13, 79, 19, 117, 23, -67, 96, -62, 45, -91, 61, -62, -80, -72, -18, -58, 10, 46, 42, 71, -55];
// $sign = base64_encode($this->toStr($sign));
$res = $this->verify($str,$sign);
dump($res);
die;
}
/*
* 签名
*/
public function getSign($data){
// // $p = openssl_pkey_get_private(file_get_contents("/www/wwwroot/rsyys.1qit.com_ys/application/cert/openssl_pri.key"));
// $p = openssl_pkey_get_private(file_get_contents("/www/wwwroot/rsyys.1qit.com_ys/application/cert/dui/pri.key"));
// openssl_sign($data, $signature, $p);
// openssl_free_key($p);
// // return ($signature);
// return base64_encode($signature);
$privatekey = openssl_get_privatekey(file_get_contents("/www/wwwroot/rsyys.1qit.com_ys/application/cert/dui/pri.key") );
$signedStr = '';
openssl_sign($data, $signedStr, $privatekey, OPENSSL_ALGO_SHA256);
openssl_free_key($privatekey);
$sign = $this->_base64url_encode($signedStr);
// $sign = chunk_split($sign,76,"\\r\\n");
// $sign = substr($sign,0,strlen($sign)-4);
return $sign;
}
public function _base64url_encode($data) {
// return rtrim(strtr(base64_encode($data), '+/', '-_'), '=');
return rtrim(base64_encode($data));
}
public function scBytes($str) {
$len = strlen($str);
$bytes = array();
for($i=0;$i<$len;$i++) {
if(ord($str[$i]) >= 128){
$byte = ord($str[$i]) - 256;
}else{
$byte = ord($str[$i]);
}
$bytes[] = $byte ;
}
return $bytes;
}
/*
* 公钥加密
*/
function public_key_encrypt($str)
{
$rsa_pub = file_get_contents("/www/wwwroot/sryys.1qit.com_ys/application/cert/jlpub.pem");
// $rsa_pub = file_get_contents("/www/wwwroot/sryys.1qit.com_ys/application/cert/dui/pub.pem");
$encrypted = '';
$pub_id = openssl_get_publickey($rsa_pub);
$key_len = openssl_pkey_get_details($pub_id)['bits'];
$part_len = $key_len / 8 - 11;
$parts = str_split($str, $part_len);
foreach ($parts as $part) {
$encrypted_temp = '';
openssl_public_encrypt($part, $encrypted_temp, $rsa_pub);
$encrypted .= $encrypted_temp;
}
return base64_encode($encrypted);
}
/**
* 私钥解密
*/
function private_key_decrypt($str)
{
$rsa_pri = file_get_contents("/www/wwwroot/rysys.1qit.com_ys/application/cert/dui/pri.key");
$str = str_replace(' ', '+', $str);
// openssl_private_decrypt(base64_decode($str), $data, $rsa_pr);
$decrypted = "";
$pri_id = openssl_get_privatekey($rsa_pri);
$key_len = openssl_pkey_get_details($pri_id)['bits'];
$part_len = $key_len / 8;
$base64_decoded = base64_decode($str);
$parts = str_split($base64_decoded, $part_len);
foreach ($parts as $part) {
$decrypted_temp = '';
openssl_private_decrypt($part, $decrypted_temp, $rsa_pri);
$decrypted .= $decrypted_temp;
}
return $decrypted;
}
/**
* 验签
*/
function verify($data, $sign)
{
// $p = openssl_pkey_get_public(file_get_contents("/www/wwwroot/rysys.1qit.com_ys/application/cert/dui/wyrsa.pem"));
// $verify = openssl_verify($data, base64_decode($sign), $p);
// openssl_free_key($p);
// return $verify;
$public_key = openssl_get_publickey( file_get_contents("/www/wwwroot/rysys.1qit.com_ys/application/cert/dui/wyrsa.pem") );
if(empty($public_key)){
return false;
}
$sign = base64_decode($sign);
$ok = openssl_verify( $data, $sign, $public_key, OPENSSL_ALGO_SHA256 ); //SHA256
openssl_free_key( $public_key );
if ($ok == 1) {
$result = true;
} elseif ($ok == 0) {
$result = false;
} else {
return 'openssl_error';
}
return $ok;
}
// $p = openssl_pkey_get_public(file_get_contents("/www/wwwroot/rayys.1qit.com_ys/application/cert/openssl_pub.key"));
// $p = openssl_pkey_get_public(file_get_contents("/www/wwwroot/ryays.1qit.com_ys/application/cert/jlpub.pem"));
public function getBytes($string) {
$bytes = array();
for($i = 0; $i < strlen($string); $i++){
$bytes[] = ord($string[$i]);
}
return $bytes;
}
public function toStr($bytes) {
$str = '';
foreach($bytes as $ch) {
$str .= chr($ch);
}
return $str;
}
public function testPost($url ,$params){
$data = json_encode($params);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
"Accept: application/json",
"Content-Type: application/json",
"charset: utf-8",
)
);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
$data = curl_exec($ch);
curl_close($ch);
return json_decode($data,true);
}
function ASCII($params = array()){
if(!empty($params)){
$p = ksort($params);
if($p){
$str = '';
foreach ($params as $k=>$val){
$str .= $k .'=' . $val . '&';
}
$strs = rtrim($str, '&');
return $strs;
}
}
return '参数错误';
}
}
?>
|