
- 添加 LinSuoKa 类实现临时锁卡功能 - 优化卡密订单关联逻辑,处理状态为 4 的订单- 新增 redis 记录订单详情,用于限单和退款处理 - 修改 Qiling 类中的签名生成逻辑 - 更新 Test 控制器中的 test_ts 方法,增加对不同订单表的处理
764 lines
23 KiB
PHP
764 lines
23 KiB
PHP
<?php
|
||
|
||
namespace app\channel\service\system;
|
||
use app\channel\service\KamiService;
|
||
use app\merchant\service\MerchantService;
|
||
use app\merchant\service\OrderService;
|
||
|
||
/**
|
||
* 骏网接口--汇元重构版本--换卡逻辑
|
||
* Class HyJk
|
||
*
|
||
* @package app\channel\service
|
||
*/
|
||
class HyJk extends Core
|
||
{
|
||
# 这几个可以后台设置
|
||
protected $host = '';
|
||
protected $mid = '';
|
||
protected $token = '';
|
||
protected $api = '';
|
||
protected $aeskey = '';
|
||
|
||
# 通用卡,只需后台设置卡种
|
||
public function cardbuy($param)
|
||
{
|
||
$check = array
|
||
(
|
||
'num' => 'product_num',
|
||
);
|
||
|
||
$this->api = 'UCard/UCardFetchSubmit.aspx';
|
||
return $this->submit($param, $check);
|
||
}
|
||
|
||
|
||
# 提单接口
|
||
private function submit($param, $check)
|
||
{
|
||
$param = $this->param($param, $check);
|
||
if (is_string($param) || (is_array($param) && $param['status'] == 1)) {
|
||
return $param;
|
||
}
|
||
|
||
|
||
$request = $param['detail'];
|
||
$request['agent_id'] = $this->mid;
|
||
$request['bill_id'] = $param['order'];
|
||
$request['bill_time'] = date('YmdHis');
|
||
$request['card_kind']= $this->getGid($param['cash']);
|
||
$request['product_code'] = $this->GoodId($param['cash']);
|
||
$request['time_stamp'] = date('YmdHis');
|
||
|
||
$request['sign'] = $this->_sign($request, array('agent_id', 'bill_id', 'bill_time', 'product_code', 'product_num', 'card_kind','time_stamp'));
|
||
$url = $this->host . $this->api;
|
||
|
||
|
||
|
||
|
||
$KamiService = KamiService::instance();
|
||
$kami_group_id = $this->product['cid'].'00'.$this->product['service_id'];
|
||
|
||
#通过后台其他参数确定参与换卡
|
||
|
||
# Secondary_sales_type二次销售类型1为全部支持二销,2为部分支持二销
|
||
|
||
$channel_other_data = $this->channel['other_data'];
|
||
$channel_other_data_array = json_decode($channel_other_data, true);
|
||
$randomKami = null;
|
||
if(is_array($channel_other_data_array) && isset($channel_other_data_array['Secondary_sales_type'])){
|
||
|
||
if($channel_other_data_array['Secondary_sales_type'] == 1) {
|
||
$randomKami = $KamiService->getData($param['cash'],-1, 1, true, false, $kami_group_id);
|
||
if(!$randomKami){
|
||
$randomKami = $KamiService->getData($param['cash'],-1, 1, true, false, '100'.$this->product['service_id']);
|
||
}
|
||
}elseif($channel_other_data_array['Secondary_sales_type'] == 2){
|
||
$Secondary_sales= $channel_other_data_array['Secondary_sales'] ?? false;
|
||
if($Secondary_sales && in_array($this->product['service_id'], $Secondary_sales)){
|
||
$randomKami = $KamiService->getData($param['cash'],-1, 1, true, false, $kami_group_id);
|
||
if(!$randomKami){
|
||
$randomKami = $KamiService->getData($param['cash'],-1, 1, true, false, '100'.$this->product['service_id']);
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
if ($randomKami) {
|
||
|
||
$randomKami_data = [
|
||
'is_kami' =>1,
|
||
];
|
||
|
||
$msg = 'yescard';
|
||
$randomKami_data['kami'] = array
|
||
(
|
||
'cardno'=>$randomKami['cnum'],
|
||
'cardpwd'=>$randomKami['cpwd'],
|
||
'expired'=>$randomKami['expire_time'],
|
||
'value'=>$randomKami['value'],
|
||
);
|
||
$response = [
|
||
'msg' => $msg,
|
||
'data' => $randomKami_data,
|
||
'array' => $randomKami_data,
|
||
];
|
||
|
||
} else {
|
||
$response = $this->curl('get', $url, $request);
|
||
$response = $this->response($response);
|
||
}
|
||
|
||
$channel_order_id = '';
|
||
if (isset($response['array']['jnet_bill_no'])) {
|
||
$channel_order_id = $response['array']['jnet_bill_no'];
|
||
}
|
||
|
||
if(isset($param['account'])){
|
||
|
||
}elseif(isset($response['kami']['cardno']) ){
|
||
$param['account'] = $response['kami']['cardno'];
|
||
}else{
|
||
$param['account'] = $request['card_kind'];
|
||
}
|
||
|
||
$this->create($param['order'], $channel_order_id, $param['merchant_order'], $param['cash'], $url, $request, $response, 1, $param['account']);
|
||
return $response['msg'];
|
||
}
|
||
|
||
#获取固定的产品编码
|
||
private function GoodId($cash)
|
||
{
|
||
|
||
$goodId = [
|
||
'10' => 'AAJWVVXKYK010FV',
|
||
'15' => 'AAJWVVXKYK015FV',
|
||
'20' => 'AAJWVVXKYK020FV',
|
||
'30' => 'AAJWVVXKYK030FV',
|
||
'50' => 'AAJWVVXKYK050FV',
|
||
'100' => 'AAJWVVXKYK100FV',
|
||
'120' => 'AAJWVVXKYK120FV',
|
||
'200' => 'AAJWVVXKYK200FV',
|
||
'500' => 'AAJWVVXKYK500FV',
|
||
'1000' => 'AAJWVVXKYK1K0FV'
|
||
];
|
||
return $goodId[$cash] ?? '';
|
||
|
||
}
|
||
|
||
|
||
|
||
# 数据响应格式处理
|
||
|
||
private function _sign($request, $param)
|
||
{
|
||
$signature_string = '';
|
||
foreach ($param as $k => $v) {
|
||
|
||
$signature_string .= $v . '=' . $request[$v] . '&';
|
||
|
||
}
|
||
|
||
$signature_string = substr($signature_string, 0, -1);
|
||
|
||
$signature_string .= '|||'.$this->token;
|
||
|
||
return md5($signature_string);
|
||
}
|
||
|
||
public function response($data)
|
||
{
|
||
$data = iconv('GBK', 'UTF-8', $data);
|
||
// $data = $this->charsetToUTF8($data);
|
||
$log['type'] = 'response';
|
||
$log['data'] = $data;
|
||
$log['config'] = $this->data;
|
||
$this->log($log);
|
||
|
||
$pairs = explode('&', $data);
|
||
|
||
$array = [];
|
||
foreach ($pairs as $pair) {
|
||
// 分割键和值
|
||
list($key, $value) = explode('=', $pair);
|
||
// 解码键和值
|
||
$array[urldecode($key)] = urldecode($value);
|
||
}
|
||
|
||
|
||
if (!$array) {
|
||
$msg = 'error';
|
||
} elseif (isset($array['ret_code']) && $array['ret_code'] == '0' || $array['ret_code'] == '999') {
|
||
# 正确
|
||
if(isset($array['card_no_data'])){
|
||
|
||
$msg = 'yescard';
|
||
$kami = $this->decrypt_3des($array['card_no_data']);
|
||
|
||
$kami = explode(',', $kami);
|
||
$array['kami'] = array
|
||
(
|
||
'cardno' => $kami[0],
|
||
'cardpwd' => $kami[1],
|
||
'expired' => $kami[2],
|
||
'value' => $array['par_price'],
|
||
);
|
||
|
||
}else{
|
||
$msg = 'ok';
|
||
}
|
||
|
||
} else {
|
||
# 错误
|
||
$msg = $array['ret_msg'] ?? 'error';
|
||
}
|
||
|
||
|
||
return array
|
||
(
|
||
'msg' => $msg,
|
||
'data' => $array,
|
||
'array' => $array,
|
||
);
|
||
}
|
||
|
||
public function decrypt_3des($encrypted_string,$aeskey = ''){
|
||
|
||
$cipher = "des-ede3"; // 3des-ebc 使用的是des-ede3算法
|
||
$mode = "ebc"; // 工作模式为ebc
|
||
|
||
$iv = ""; // EBC模式不需要IV,留空即可
|
||
$json = $this->channel['describe'];
|
||
$array = $this->json_decode($json);
|
||
if(!$aeskey){
|
||
if(isset($array['aeskey'])){
|
||
$this->aeskey = $array['aeskey'];
|
||
}
|
||
}else{
|
||
$this->aeskey = $aeskey;
|
||
}
|
||
// if(isset($array['aeskey'])){
|
||
// $this->aeskey = $array['aeskey'];
|
||
// }
|
||
// $this->aeskey =
|
||
|
||
return openssl_decrypt(hex2bin($encrypted_string), $cipher, $this->aeskey, $options=OPENSSL_RAW_DATA, $iv); // 输出解密后的字符串
|
||
}
|
||
|
||
#换卡查询接口
|
||
|
||
|
||
# 查询接口
|
||
|
||
public function lockCard($order)
|
||
{
|
||
#先查卡的余额对不对
|
||
// die;
|
||
|
||
|
||
$replaceCard = $this->replaceCard($order);
|
||
|
||
|
||
if(str_contains($replaceCard['msg'], '卡内有锁定金额')){
|
||
$this->token = $this->channel['token'];
|
||
$unLock_status = $this->UnlockCard($order,'换卡解锁');
|
||
if($unLock_status == 'ok'){
|
||
$replaceCard = $this->replaceCard($order);
|
||
if($replaceCard['msg'] != 'ok'){
|
||
$this->token = $this->channel['token'];
|
||
$Lock_status = $this->lockCards($order,'换卡失败锁定');
|
||
if($Lock_status != 'ok')$this->log(['order'=>$order['order_id'],'msg'=>'换卡失败重新锁定失败']);
|
||
return 'error';
|
||
}
|
||
}else{
|
||
$this->log(['order'=>$order['order_id'],'msg'=>'有锁定解锁失败']);
|
||
return 'error';
|
||
}
|
||
|
||
}
|
||
|
||
if($replaceCard['msg'] == 'ok'){
|
||
|
||
$KamiService = KamiService::instance();
|
||
|
||
$requestData = $this->json_decode($order['request']);
|
||
// $request['card_kind'] = ;
|
||
|
||
if($requestData['card_kind'] == '335'){
|
||
$upkami = $KamiService->upKami($replaceCard['array']['kami']['cardno'], $replaceCard['array']['kami']['cardpwd'], $replaceCard['array']['kami']['value'], $replaceCard['array']['kami']['expired'],1,$order['mid']);
|
||
}elseif ($requestData['card_kind'] == '357'){
|
||
$upkami = $KamiService->upKami($replaceCard['array']['kami']['cardno'], $replaceCard['array']['kami']['cardpwd'], $replaceCard['array']['kami']['value'], $replaceCard['array']['kami']['expired'],2,$order['mid']);
|
||
}
|
||
|
||
|
||
|
||
|
||
if($upkami){
|
||
return 'ok';
|
||
}else{
|
||
return 'old_ok';
|
||
}
|
||
|
||
}else{
|
||
return 'error';
|
||
}
|
||
|
||
|
||
|
||
|
||
}
|
||
|
||
public function UnlockCard($order,$desc = '')
|
||
{
|
||
$request = [
|
||
'agent_id' => $this->mid,
|
||
'account_type' => 2,
|
||
'lock_type' => 2,
|
||
];
|
||
|
||
$response = $this->json_decode($order['response']);
|
||
if(empty($response['kami'])){
|
||
return '未找到卡密';
|
||
}
|
||
|
||
$request['card_no'] = $response['kami']['cardno'];
|
||
$request['card_par_amt'] = $order['cash'].'.00';
|
||
$request['card_style'] = 1;
|
||
if($desc){
|
||
$request['desc'] = $desc;
|
||
}
|
||
|
||
$request['time_stamp'] = date('YmdHis');
|
||
$request['sign'] = $this->_sign($request, array('agent_id', 'account_type', 'card_no', 'card_par_amt', 'card_style', 'lock_type','time_stamp'));
|
||
|
||
$url = $this->host.'UCard/UCardLock.aspx';
|
||
|
||
$response = $this->curl('get',$url,$request);
|
||
|
||
$response = iconv('GBK', 'UTF-8', $response);
|
||
|
||
// ======================锁卡
|
||
|
||
|
||
// ret_code=***&ret_msg=***&agent_id=***&card_no=***&card_par_amt=***&sign=***
|
||
|
||
$pairs = explode('&', $response);
|
||
//
|
||
//// 将每个键值对分割并创建数组
|
||
$array = [];
|
||
//
|
||
foreach ($pairs as $pair) {
|
||
// 分割键和值
|
||
list($key, $value) = explode('=', $pair);
|
||
// 解码键和值
|
||
$array[urldecode($key)] = urldecode($value);
|
||
}
|
||
|
||
if (!$array) {
|
||
|
||
$msg = 'error';
|
||
} elseif (isset($array['ret_code']) && $array['ret_code'] == '0' ) {
|
||
# 正确
|
||
$msg = 'ok';
|
||
|
||
|
||
} elseif(isset($array['ret_msg']) && $array['ret_code'] == '1' && $array['ret_msg'] == '该卡已被解锁') {
|
||
$msg = 'old_ok';
|
||
|
||
}else{
|
||
# 错误
|
||
$msg = $array['ret_msg'] ?? 'error';
|
||
|
||
}
|
||
|
||
return $msg;
|
||
//
|
||
// if($msg=='ok' || $msg=='old_ok'){
|
||
//
|
||
//
|
||
// return $msg;
|
||
// }else{
|
||
//
|
||
// return 'error';
|
||
// }
|
||
|
||
//
|
||
//
|
||
// $url = $this->host . 'UCard/UCardLock.aspx';
|
||
// $request=$param;
|
||
// $request['agent_id']=$this->mid;
|
||
// $request['account_type']='2';
|
||
|
||
|
||
}
|
||
|
||
public function lockCards($order,$desc = '')
|
||
{
|
||
$request = [
|
||
'agent_id' => $this->mid,
|
||
'account_type' => 2,
|
||
'lock_type' => 1,
|
||
];
|
||
|
||
$response = $this->json_decode($order['response']);
|
||
if(empty($response['kami'])){
|
||
return '未找到卡密';
|
||
}
|
||
|
||
$request['card_no'] = $response['kami']['cardno'];
|
||
$request['card_par_amt'] = $order['cash'].'.00';
|
||
$request['card_style'] = 1;
|
||
if($desc){
|
||
$request['desc'] = $desc;
|
||
}
|
||
|
||
$request['time_stamp'] = date('YmdHis');
|
||
$request['sign'] = $this->_sign($request, array('agent_id', 'account_type', 'card_no', 'card_par_amt', 'card_style', 'lock_type','time_stamp'));
|
||
$url = $this->host.'UCard/UCardLock.aspx';
|
||
$response = http_get($url,$request);
|
||
$response = iconv('GBK', 'UTF-8', $response);
|
||
// var_dump($response);die;
|
||
// ======================锁卡
|
||
|
||
// var_dump($response);die;
|
||
// ret_code=***&ret_msg=***&agent_id=***&card_no=***&card_par_amt=***&sign=***
|
||
|
||
$pairs = explode('&', $response);
|
||
//
|
||
//// 将每个键值对分割并创建数组
|
||
$array = [];
|
||
//
|
||
foreach ($pairs as $pair) {
|
||
// 分割键和值
|
||
list($key, $value) = explode('=', $pair);
|
||
// 解码键和值
|
||
$array[urldecode($key)] = urldecode($value);
|
||
}
|
||
|
||
if (!$array) {
|
||
|
||
$msg = 'error';
|
||
} elseif (isset($array['ret_code']) && $array['ret_code'] == '0' ) {
|
||
# 正确
|
||
$msg = 'ok';
|
||
|
||
|
||
} elseif(isset($array['ret_msg']) && $array['ret_code'] == '1' && $array['ret_msg'] == '该卡已被锁定') {
|
||
$msg = 'old_ok';
|
||
|
||
}else{
|
||
# 错误
|
||
$msg = $array['ret_msg'] ?? 'error';
|
||
|
||
}
|
||
|
||
return $msg;
|
||
//
|
||
// if($msg=='ok' || $msg=='old_ok'){
|
||
//
|
||
//
|
||
// return $msg;
|
||
// }else{
|
||
//
|
||
// return 'error';
|
||
// }
|
||
|
||
//
|
||
//
|
||
// $url = $this->host . 'UCard/UCardLock.aspx';
|
||
// $request=$param;
|
||
// $request['agent_id']=$this->mid;
|
||
// $request['account_type']='2';
|
||
|
||
|
||
}
|
||
|
||
# 提交数据
|
||
|
||
public function replaceCard($order){
|
||
$request=[];
|
||
$request['agent_id'] = $this->mid;
|
||
$request['version'] = 1;
|
||
$request['bill_id'] = $order['order_id'].'_R';
|
||
$request['time_stamp'] = $request['bill_time'] = date('YmdHis');
|
||
$requestData = $this->json_decode($order['request']);
|
||
$request['card_kind'] = $requestData['card_kind'];
|
||
|
||
$request['card_style'] = 1;
|
||
$request['total_amt'] = $request['card_price'] = $order['cash'].'.00';
|
||
$response = $this->json_decode($order['response']);
|
||
if(empty($response['kami'])){
|
||
return '未找到卡密';
|
||
}
|
||
$kami_data = $response['kami']['cardno'].','. $response['kami']['cardpwd'].','.$request['card_price'];
|
||
$aeskey = '';
|
||
$json = $this->channel['other_data'];
|
||
$array = $this->json_decode($json);
|
||
if(is_array($array) && isset($array['replaceCard_aeskey'])){
|
||
if(isset($aeskey)){
|
||
$aeskey = $array['replaceCard_aeskey'];
|
||
}
|
||
}
|
||
|
||
if(is_array($array) && isset($array['replaceCard_token'])){
|
||
$this->token = $array['replaceCard_token'];
|
||
}
|
||
|
||
|
||
$request['card_data'] = $this->aes_encrypt($kami_data,$aeskey);
|
||
// var_dump($request);die;
|
||
|
||
$request['sign'] = $this->_sign($request, array('agent_id', 'bill_id', 'bill_time', 'card_data', 'card_kind', 'card_price','card_style','time_stamp','version'));
|
||
$url = $this->host . 'UCard/UCardExchargeSubmit.aspx';
|
||
// $test =$url.'?'.http_build_query($request);
|
||
// $test=$url.'?' ;
|
||
// var_dump($test);die;
|
||
|
||
|
||
$data = http_post($url,$request);
|
||
$data = iconv('GBK', 'UTF-8', $data);
|
||
$log['type'] = 'replaceCard_response';
|
||
$log['data'] = $data;
|
||
$log['config'] = $this->data;
|
||
$this->log($log);
|
||
// #"ret_code=0&ret_msg=成功&agent_id=2206307&bill_id=B202404050125748573224716&jnet_bill_no=&fee_amt=&total_amt=&card_data=&ext_param=&sign=82edf84b09b9455d8dae5f886dde91f6"
|
||
// $data= 'ret_code=0&ret_msg=成功&agent_id=2206307&bill_id=B202404050125748573224716_R&jnet_bill_no=144&fee_amt=0.00&total_amt=20.00&card_data=03623CFF34E2F24358299BD5464C49EDD8290D278101DC2CF1260FCEE6B2F87425AAB1E411619CBBCF5B523D6395619D5F14F084993FF15B&ext_param=&sign=95999c013384c7c3fc52c5c4f2eb3138';
|
||
// var_dump($data);die;
|
||
|
||
$pairs = explode('&', $data);
|
||
|
||
$array = [];
|
||
// 创建一个DateTime对象,初始化为2000年1月1日
|
||
|
||
foreach ($pairs as $pair) {
|
||
// 分割键和值
|
||
list($key, $value) = explode('=', $pair);
|
||
// 解码键和值
|
||
$array[urldecode($key)] = urldecode($value);
|
||
}
|
||
|
||
|
||
if (!$array) {
|
||
$msg = 'error';
|
||
} elseif (isset($array['ret_code']) && $array['ret_code'] == '0' || $array['ret_code'] == '999') {
|
||
# 正确
|
||
if(isset($array['card_data'])){
|
||
|
||
$msg = 'ok';
|
||
$kami = $this->decrypt_3des($array['card_data'],$aeskey);
|
||
|
||
$kami = explode(',', $kami);
|
||
|
||
$tempdate=substr($kami[3], 0, 4).'-'.substr($kami[3], 4, 2).'-'.substr($kami[3], 6, 2).' '.substr($kami[3], 8, 2).':'.substr($kami[3], 10, 2).':'.substr($kami[3], 12, 2);
|
||
$array['kami'] = array
|
||
(
|
||
'cardno' => $kami[0],
|
||
'cardpwd' => $kami[1],
|
||
'expired' => $tempdate,
|
||
'value' => $kami[2],
|
||
);
|
||
|
||
}else{
|
||
$msg = 'no_data';
|
||
}
|
||
|
||
} else {
|
||
# 错误
|
||
$msg = $array['ret_msg'] ?? 'error';
|
||
}
|
||
|
||
return array
|
||
(
|
||
'msg' => $msg,
|
||
'data' => $array,
|
||
'array' => $array,
|
||
);
|
||
|
||
|
||
|
||
}
|
||
|
||
private function aes_encrypt($data,$aeskey = '') {
|
||
|
||
$data = iconv('UTF-8', 'GBK', $data);
|
||
|
||
$json = $this->channel['describe'];
|
||
$array = $this->json_decode($json);
|
||
if(!$aeskey){
|
||
if(isset($array['aeskey'])){
|
||
$this->aeskey = $array['aeskey'];
|
||
}
|
||
}else{
|
||
$this->aeskey = $aeskey;
|
||
}
|
||
|
||
|
||
$encrypted = openssl_encrypt($data, 'des-ede3', $this->aeskey , OPENSSL_RAW_DATA);
|
||
|
||
return bin2hex($encrypted);
|
||
}
|
||
|
||
public function replaceCard_query($order_id)
|
||
{
|
||
|
||
$request['agent_id'] = $this->mid;
|
||
$request['bill_id'] = $order_id;
|
||
$request['time_stamp'] =date('YmdHis');
|
||
$aeskey = '';
|
||
$json = $this->channel['other_data'];
|
||
$array = $this->json_decode($json);
|
||
if(is_array($array) && isset($array['replaceCard_aeskey'])){
|
||
if(isset($aeskey)){
|
||
$aeskey = $array['replaceCard_aeskey'];
|
||
}
|
||
}
|
||
|
||
if(is_array($array) && isset($array['replaceCard_token'])){
|
||
$this->token = $array['replaceCard_token'];
|
||
}
|
||
|
||
$request['sign'] = $this->_sign($request, array('agent_id', 'bill_id', 'time_stamp'));
|
||
$url = $this->host . 'UCard/UCardExchargeQuery.aspx';
|
||
// var_dump($url);die;
|
||
$response = http_get($url, $request);
|
||
|
||
|
||
$response = iconv('GBK', 'UTF-8', $response);
|
||
// var_dump($response);die;
|
||
// ret_code=0&ret_msg=成功&agent_id=2206307&bill_id=B202404050125748573224716_R&jnet_bill_no=144&fee_amt=0.00&total_amt=20.00&card_data=03623CFF34E2F24358299BD5464C49EDD8290D278101DC2CF1260FCEE6B2F87425AAB1E411619CBBCF5B523D6395619D5F14F084993FF15B&ext_param=&sign=95999c013384c7c3fc52c5c4f2eb3138
|
||
// var_dump($response);die;
|
||
|
||
$log['type'] = 'replaceCard_query_response';
|
||
$log['data'] = $response;
|
||
$log['config'] = $this->data;
|
||
$this->log($log);
|
||
$pairs = explode('&', $response);
|
||
$array = [];
|
||
foreach ($pairs as $pair) {
|
||
// 分割键和值
|
||
list($key, $value) = explode('=', $pair);
|
||
// 解码键和值
|
||
$array[urldecode($key)] = urldecode($value);
|
||
}
|
||
|
||
|
||
|
||
// $result = array();
|
||
// $result['status'] = 4;
|
||
if (isset($array['ret_code']) && $array['ret_code'] == '0') {
|
||
if(isset($array['card_data'])){
|
||
$msg = 'yescard';
|
||
$kami = $this->decrypt_3des($array['card_data'],$aeskey);
|
||
$kami = explode(',', $kami);
|
||
$kamidata = [
|
||
'cardno' => $kami[0],
|
||
'cardpwd' => $kami[1],
|
||
'value'=>$kami[2],
|
||
'expired' => $kami[3],
|
||
|
||
];
|
||
$array['kami'] = $kamidata;
|
||
|
||
}else{
|
||
$msg = 'ok';
|
||
}
|
||
|
||
|
||
|
||
} else{
|
||
$msg = $array['ret_msg'] ?? 'error';
|
||
}
|
||
|
||
if (isset($array['jnet_bill_no']) && $array['jnet_bill_no']) {
|
||
# 流水号
|
||
// $result['status'] = 3;
|
||
$array['s_nubmer'] = $array['jnet_bill_no'] ;
|
||
}
|
||
|
||
|
||
|
||
return array
|
||
(
|
||
'msg' => $msg,
|
||
'data' => $array,
|
||
'array' => $array,
|
||
);
|
||
|
||
}
|
||
|
||
public function query($order)
|
||
{
|
||
$orderRequest = json_decode($order['request'], true);
|
||
$request['agent_id'] = $this->mid;
|
||
$request['bill_id'] = $order['order_id'];
|
||
$request['time_stamp'] =date('YmdHis');
|
||
|
||
$request['sign'] = $this->_sign($request, array('agent_id', 'bill_id', 'time_stamp'));
|
||
$url = $this->host . 'UCard/UCardFetchQuery.aspx';
|
||
$response = $this->curl('get', $url, $request);
|
||
$response = iconv('GBK', 'UTF-8', $response);
|
||
|
||
$log['type'] = 'query_response';
|
||
$log['data'] = $response;
|
||
$log['config'] = $this->data;
|
||
$this->log($log);
|
||
$pairs = explode('&', $response);
|
||
$array = [];
|
||
foreach ($pairs as $pair) {
|
||
// 分割键和值
|
||
list($key, $value) = explode('=', $pair);
|
||
// 解码键和值
|
||
$array[urldecode($key)] = urldecode($value);
|
||
}
|
||
|
||
|
||
|
||
$result = array();
|
||
// $result['status'] = 4;
|
||
if (isset($array['ret_code']) && $array['ret_code'] == '0') {
|
||
if(isset($array['card_no_data'])){
|
||
$kami = $this->decrypt_3des($array['card_no_data']);
|
||
$kami = explode(',', $kami);
|
||
$kamidata = [
|
||
'cardno' => $kami[0],
|
||
'cardpwd' => $kami[1],
|
||
'expired' => $kami[2],
|
||
|
||
];
|
||
|
||
$this->upOrderResponse($kamidata,$order['merchant_order_id'],$order['response']);
|
||
$result['status'] = 7;
|
||
$result['kami'] = $kamidata;
|
||
}else{
|
||
$result['status'] = 4;
|
||
}
|
||
|
||
} else{
|
||
$result['status'] = 3;
|
||
}
|
||
|
||
if (isset($array['jnet_bill_no']) && $array['jnet_bill_no']) {
|
||
# 流水号
|
||
// $result['status'] = 3;
|
||
//$data['s_nubmer'] = $result['s_nubmer'] = $data['result']['code'];
|
||
}
|
||
|
||
|
||
|
||
return $result;
|
||
|
||
}
|
||
|
||
public function upOrderResponse($kami,$merchant_order_id,$orderResponse)
|
||
{
|
||
$orderService = OrderService::instance();
|
||
|
||
$response = json_decode($orderResponse,true);
|
||
$response['kami'] = $kami;
|
||
$data = ['response' => json_encode($response)];
|
||
|
||
$orderService->db()->where(array('merchant_order_id' => $merchant_order_id))->update($data);
|
||
}
|
||
|
||
|
||
} |