From be368f37486354540eeb8458ffc5665ae2be3b44 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B2=90?= Date: Mon, 16 Jun 2025 00:03:59 +0800 Subject: [PATCH] =?UTF-8?q?feat(channel):=20=E6=96=B0=E5=A2=9E=E5=8D=A1?= =?UTF-8?q?=E5=AF=86=E5=A4=84=E7=90=86=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 在 Jinjiaqi.php 中添加 common 方法支持通用卡密提交 - 新增 KamiPool.php 和 System.php 两个新渠道服务类 - 修改 KamiOrderChanelNotify.php 等文件以支持新渠道的回调处理 - 更新 Order.php 文件以适配新的卡密提交逻辑 --- app/channel/service/system/Jinjiaqi.php | 17 +- app/channel/service/system/KamiPool.php | 272 ++++++++++++++++++ app/channel/service/system/System.php | 242 ++++++++++++++++ app/openapi/controller/Test.php | 32 +++ .../controller/agisoAcprSupplierApi/Order.php | 21 +- app/openapi/controller/maSuDaApi/Order.php | 6 +- .../kami91order/KamiOrderChanelNotify.php | 8 +- .../KamiOrderStatusIncorrectSync.php | 8 +- .../kami91order/KamiOrderStatusSync.php | 4 +- 9 files changed, 591 insertions(+), 19 deletions(-) create mode 100644 app/channel/service/system/KamiPool.php create mode 100644 app/channel/service/system/System.php diff --git a/app/channel/service/system/Jinjiaqi.php b/app/channel/service/system/Jinjiaqi.php index 22c6487..4f9817a 100644 --- a/app/channel/service/system/Jinjiaqi.php +++ b/app/channel/service/system/Jinjiaqi.php @@ -21,6 +21,7 @@ class Jinjiaqi extends Core protected $aeskey = '383147446d6e4e6c'; protected $goodid = ''; + protected $AutoCash = true; # 沃尔玛卡卡密 public function walmart_cardbuy($param) @@ -134,6 +135,20 @@ class Jinjiaqi extends Core return $this->submit($param, $check); } + public function common($param) + { + $check = array + ( + 'num' => 'BuyNum', + 'account' => 'ChargeAccount', + ); + $this->AutoCash = false; + $this->api = 'api/Order/CreateGameOrder'; + return $this->submit($param, $check); + } + + + #快手币 public function ks($param) { @@ -302,7 +317,7 @@ class Jinjiaqi extends Core $request['UserOrderId'] = $param['order']; // $request['bill_time'] = date('YmdHis'); // $request['bill_id'] = $param['order'];i - if($request['ChargeAccount'] != "kami"){ + if($request['ChargeAccount'] != "kami" && $this->AutoCash){ $request['BuyNum'] = $request['BuyNum'] *$param['cash']; } diff --git a/app/channel/service/system/KamiPool.php b/app/channel/service/system/KamiPool.php new file mode 100644 index 0000000..7867e66 --- /dev/null +++ b/app/channel/service/system/KamiPool.php @@ -0,0 +1,272 @@ + 'account', + 'cash'=>'cash' + ); +// $this->api='api/buy'; + return $this->submit($param, $check); + } + + public function common($param) + { + $check = array + ( + 'account' => 'account', + 'cash'=>'cash' + ); + return $this->submit($param, $check); + } + + # 通知处理 主要返回状态 2是成功 3是失败 + public function notify($data) + { + $result = array(); + $result['cash'] = 1; + $result['status'] = 4; + #以上基本不要变 + + if(isset($data['query_status'])){ + if ($data['query_status'] == 200) { + $result['status'] = 2; + } else if($data['query_status'] == 500) { + $result['status'] = 3; + }else { + $result['status'] = 4; + } + }else{ + if ($data['state'] == 200) { + $result['status'] = 2; + } else if($data['state'] == 500) { + $result['status'] = 3; + }else { + $result['status'] = 4; + } + } + #以下处理逻辑可以自由 +// if(isset($data['cards'])&&$data['cards']&&is_array($data['cards'])){ +// +// $result['kami'] = array +// ( +// 'cardno' => isset($data['cards'][0]['card_no'])?$data['cards'][0]['card_no']:'', +// 'cardpwd' => $data['cards'][0]['card_password'], +// 'expired' => isset($data['cards'][0]['expired_at'])?$data['cards'][0]['expired_at']:'', +//// 'value' => $array['data']['count_money'], +// ); +// } + if(isset($data['kami'])&&$data['kami']){ + $result['kami']=$data['kami']; + } + $result['yes'] = 'ok'; //响应给上游的数据 + + $result['data'] = $data; + + return $result; + } + public function query($order){ + $request['customer_id'] = $this->mid; + $request['order_id'] = $order['merchant_order_id']; + $request['timestamp'] = time(); + $request['sign'] = $this->_sign($request); + $url = $this->host . 'api/order'; + $response = $this->curl('post', $url, $request); + + #记录日志 + $log['type'] = 'query_response'; + $log['data'] = $response; + $log['config'] = $this->data; + $this->log($log); + #记录借宿 + + $array = $this->json_decode($response,true); + + $result = array(); + $result['status'] = 4; + if ($array['code']=='ok' ) { + if($array['state'] ==200){ + $result['query_status'] = 200; + + $result['status'] = 2; + }elseif ($array['state'] == 500){ + $result['query_status'] = 500; + $result['status'] = 3; + } + + } + if(isset($array['data']['cards'])){ + $result['kami']=array( + 'cardno' => isset($array['data']['cards'][0]['card_no'])?$array['data']['cards'][0]['card_no']:'', + 'cardpwd' => $array['data']['cards'][0]['card_password'], + 'expired' => $array['data']['cards'][0]['expired_at'], + ); + } + return $result; + } + # 数据响应格式处理 + public function response($data) + { + $log['type'] = 'response'; + $log['data'] = $data; + $log['config'] = $this->data; + $this->log($log); + + #以上不要做任何变动 + + + + $array = $this->json_decode($data); //响应数据为json + #如果响应为XML格式 +// $array = (array) simplexml_load_string($data); + + if (!$array) { + $msg = 'error'; + } elseif (isset($array['code']) && $array['code']=='ok') { //修改判断逻辑为确定提交成功即可 + # 正确 + $msg = 'ok'; + #如有其他判断以下 +// if(isset($array['cards'])){ +// $array['kami'] = array +// ( +// 'cardno' => $array['cards'][0]['card_no'], +// 'cardpwd' => $array['cards'][0]['card_password'], +// 'expired' => $array['cards'][0]['expired_at'], +//// 'value' => $array['data']['count_money'], +// ); +// } + } else { + # 错误 + $msg = $array['message'] ?? 'error'; //前面message根据响应内容改成对应的错误提示 + } + + return array + ( + 'msg' => $msg, + 'data' => $data, + 'array' => $array, + ); + } + + # 查询余额接口 + public function account($day) + { + $request['customer_id'] = $this->mid; + $request['timestamp']=time(); + $request['sign'] = $this->_sign($request); + $url = $this->host . 'api/customer'; + $response = $this->curl('post', $url, $request); + $response = $this->response($response); + + $datas = $response['array']['data']; + if(is_array($datas) && isset($datas['balance']) && $datas['balance'] ){ + $datas['account'] = $datas['balance']; //此处为余额 + } + + return $datas; + } + + + # 提交数据 + 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']; //上面替换剩下的 + $mid = $this->data['merchant'] ?? -1; + $request['kami_group_id']=$this->getGid($param['cash']); //此方法为根据面值获取产品id,如无需可注释 + $KamiService = KamiService::instance(); + $randomKami = $KamiService->getData($param['cash'],$mid, 1, true, false, $request['kami_group_id']); + + if ($randomKami) { + + #解锁卡密 + + + + $randomKami_data = [ + 'is_kami' => 1, + 'is_KamiPool'=>1, + ]; + + $msg = 'yescard'; + if($randomKami['cnum'] && (!isset($randomKami['cpwd']) || !$randomKami['cpwd'] || $randomKami['cpwd'] == 'is_CDK') )#判断为cdk兑换码 + { + $randomKami_data['is_CDK']=1; + $randomKami_data['kami'] = array + ( + 'cardno' => $randomKami['cnum'], + 'cardpwd' => $randomKami['cpwd']??null, + 'expired' => $randomKami['expire_time']??null, + 'value' => $randomKami['value'], + ); + }else{ + $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, + ]; + $update = $KamiService->db()->where(array('id' => $randomKami['id']))->update(array( 'use_info' => '已被使用,订单:'.$param['order'])); + + $channel_order_id = 'KP_'.$randomKami['id']??$param['order']; + }else{ + $channel_order_id = 'KP_'.$param['order']; + $response = [ + 'msg' => 'error', + 'data' => '卡密获取失败', + 'array' => [], + ]; + } + +// var_dump($this->data);die; + #结束初步 + + + + #如果出现响应有上游订单号,可以如下 + + + $this->create($param['order'], $channel_order_id, $param['merchant_order'], $param['cash'], '', $request, $response, 1, $param['account']); + return $response['msg']; + } + + private function _sign($request) + { +// unset($request['cash']); + ksort($request); + $str=$this->token; + foreach($request as $k=>$v){ + $str.=$k.$v; + } + $str=strtolower(md5($str)); + return $str; + } +} \ No newline at end of file diff --git a/app/channel/service/system/System.php b/app/channel/service/system/System.php new file mode 100644 index 0000000..de5f4a0 --- /dev/null +++ b/app/channel/service/system/System.php @@ -0,0 +1,242 @@ + 'recharge_account', + 'cash'=>'quantity' + ); + $this->api='api/buy'; + return $this->submit($param, $check); + } + + + + public function jdhy_cardbuy($param){ + $check = array + ( + 'account' => 'recharge_account', + 'cash'=>'cash' + ); + $this->api='api/buy'; + return $this->submit($param, $check); + } + + # 通知处理 主要返回状态 2是成功 3是失败 + public function notify($data) + { + $result = array(); + $result['cash'] = 1; + $result['status'] = 4; + #以上基本不要变 + + if(isset($data['query_status'])){ + if ($data['query_status'] == 200) { + $result['status'] = 2; + } else if($data['query_status'] == 500) { + $result['status'] = 3; + }else { + $result['status'] = 4; + } + }else{ + if ($data['state'] == 200) { + $result['status'] = 2; + } else if($data['state'] == 500) { + $result['status'] = 3; + }else { + $result['status'] = 4; + } + } + #以下处理逻辑可以自由 +// if(isset($data['cards'])&&$data['cards']&&is_array($data['cards'])){ +// +// $result['kami'] = array +// ( +// 'cardno' => isset($data['cards'][0]['card_no'])?$data['cards'][0]['card_no']:'', +// 'cardpwd' => $data['cards'][0]['card_password'], +// 'expired' => isset($data['cards'][0]['expired_at'])?$data['cards'][0]['expired_at']:'', +//// 'value' => $array['data']['count_money'], +// ); +// } + if(isset($data['kami'])&&$data['kami']){ + $result['kami']=$data['kami']; + } + $result['yes'] = 'ok'; //响应给上游的数据 + + $result['data'] = $data; + + return $result; + } + public function query($order){ + $request['customer_id'] = $this->mid; + $request['order_id'] = $order['merchant_order_id']; + $request['timestamp'] = time(); + $request['sign'] = $this->_sign($request); + $url = $this->host . 'api/order'; + $response = $this->curl('post', $url, $request); + + #记录日志 + $log['type'] = 'query_response'; + $log['data'] = $response; + $log['config'] = $this->data; + $this->log($log); + #记录借宿 + + $array = $this->json_decode($response,true); + + $result = array(); + $result['status'] = 4; + if ($array['code']=='ok' ) { + if($array['state'] ==200){ + $result['query_status'] = 200; + + $result['status'] = 2; + }elseif ($array['state'] == 500){ + $result['query_status'] = 500; + $result['status'] = 3; + } + + } + if(isset($array['data']['cards'])){ + $result['kami']=array( + 'cardno' => isset($array['data']['cards'][0]['card_no'])?$array['data']['cards'][0]['card_no']:'', + 'cardpwd' => $array['data']['cards'][0]['card_password'], + 'expired' => $array['data']['cards'][0]['expired_at'], + ); + } + return $result; + } + # 数据响应格式处理 + public function response($data) + { + $log['type'] = 'response'; + $log['data'] = $data; + $log['config'] = $this->data; + $this->log($log); + + #以上不要做任何变动 + + + + $array = $this->json_decode($data); //响应数据为json + #如果响应为XML格式 +// $array = (array) simplexml_load_string($data); + + if (!$array) { + $msg = 'error'; + } elseif (isset($array['code']) && $array['code']=='ok') { //修改判断逻辑为确定提交成功即可 + # 正确 + $msg = 'ok'; + #如有其他判断以下 +// if(isset($array['cards'])){ +// $array['kami'] = array +// ( +// 'cardno' => $array['cards'][0]['card_no'], +// 'cardpwd' => $array['cards'][0]['card_password'], +// 'expired' => $array['cards'][0]['expired_at'], +//// 'value' => $array['data']['count_money'], +// ); +// } + } else { + # 错误 + $msg = $array['message'] ?? 'error'; //前面message根据响应内容改成对应的错误提示 + } + + return array + ( + 'msg' => $msg, + 'data' => $data, + 'array' => $array, + ); + } + + # 查询余额接口 + public function account($day) + { + $request['customer_id'] = $this->mid; + $request['timestamp']=time(); + $request['sign'] = $this->_sign($request); + $url = $this->host . 'api/customer'; + $response = $this->curl('post', $url, $request); + $response = $this->response($response); + + $datas = $response['array']['data']; + if(is_array($datas) && isset($datas['balance']) && $datas['balance'] ){ + $datas['account'] = $datas['balance']; //此处为余额 + } + + return $datas; + } + + + # 提交数据 + 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['customer_id']=$this->mid; + if(!isset($request['quantity'])){ + $request['quantity']=$param['cash'] ?? 1; + } + + $request['notify_url']=$this->getNotify($param['order'], 1); //回调方法默认不用改 + $request['outer_order_id']=$param['order']; //我方系统订单号 + $request['product_id']=$this->getGid($param['cash']); //此方法为根据面值获取产品id,如无需可注释 + $request['timestamp']=time(); +// unset($request['cash']); + $request['sign'] = $this->_sign($request); + $url = $this->host . $this->api; //组装地址 + + #该系统提交写法: + $this->curl('post', $url, $request);//为post请求,表格提交 + $this->curl('post', $url, $request,true); //为post请求,json提交 + http_post($url,$request); //如果上面不可用,可以用这个方法, thinkadmin自带方法 + http_get($url,$request); // get请求 + $this->http_send('POST',$url,$request);//额外封,实在不行可以用. + #只需保留一个方法 + + + $response = $this->curl('post', $url, $request); + $response = $this->response($response); + $channel_order_id = ''; + + #如果出现响应有上游订单号,可以如下 + if (isset($response["array"]['data']['order_id'])) { + $channel_order_id = $response["array"]['data']['order_id']; + } + + $this->create($param['order'], $channel_order_id, $param['merchant_order'], $param['cash'], $url, $request, $response, 1, $param['account']); + return $response['msg']; + } + + private function _sign($request) + { +// unset($request['cash']); + ksort($request); + $str=$this->token; + foreach($request as $k=>$v){ + $str.=$k.$v; + } + $str=strtolower(md5($str)); + return $str; + } +} \ No newline at end of file diff --git a/app/openapi/controller/Test.php b/app/openapi/controller/Test.php index 3528396..3ec78fa 100644 --- a/app/openapi/controller/Test.php +++ b/app/openapi/controller/Test.php @@ -230,6 +230,38 @@ class Test extends Core } + + public function test_suoding() + { + $data = Db::name('channel_kami')->where(['status'=>0,'use_mid'=>-1])->select()->toArray(); + foreach ($data as $vo) { + + $order = []; + $order['cash'] = $vo['value']; + $kami = []; + $kami['cardno'] = $vo['cnum']; + $kami['cardpwd'] = $vo['cpwd']; + $response = []; + $response['kami'] =$kami; + + + $response = json_encode($response); + $order['response']=$response; +// var_dump($order);die; + + $channelService = ChannelService::instance(); + + + $suoka = $channelService->call('lockCards', 9, $order); +// var_dump($suoka);die; + if ($suoka == 'ok' || $suoka == 'old_ok') { + Db::name('channel_kami')->where('id', $vo['id'])->update(['status' => 1,'use'=>1,'use_info'=>'二次锁定,等待二销']); +// Log::write('suoka_test', 'suoka_test', $vo['order']);#写入到日志里 + } + + } +// var_dump($data); + } public function jt() { diff --git a/app/openapi/controller/agisoAcprSupplierApi/Order.php b/app/openapi/controller/agisoAcprSupplierApi/Order.php index 53edb7b..c86105b 100644 --- a/app/openapi/controller/agisoAcprSupplierApi/Order.php +++ b/app/openapi/controller/agisoAcprSupplierApi/Order.php @@ -453,11 +453,22 @@ class Order extends Controller } if(isset($param['kami'])){ $cards=[]; - $cards[]=[ - 'cardNo' => $param['kami']['cardno'], - 'cardPwd' => $param['kami']['cardpwd'], - 'expireTime' => $param['kami']['expired'], - ]; + if(isset($param['kami']['cardno'])){ + if(!isset($param['kami']['cardpwd']) || !$param['kami']['cardpwd']){ + $cards[]=[ + 'cardNo' => $param['kami']['cardno'], +// 'cardPwd' => $param['kami']['cardpwd'], +// 'expireTime' => $param['kami']['expired'], + ]; + }else{ + $cards[]=[ + 'cardNo' => $param['kami']['cardno'], + 'cardPwd' => $param['kami']['cardpwd'], + 'expireTime' => $param['kami']['expired'], + ]; + } + } + $param_data['cards'] = $this->encryptWithAES(json_encode($cards), $secretKey); diff --git a/app/openapi/controller/maSuDaApi/Order.php b/app/openapi/controller/maSuDaApi/Order.php index 72fd4b8..5e01ee8 100644 --- a/app/openapi/controller/maSuDaApi/Order.php +++ b/app/openapi/controller/maSuDaApi/Order.php @@ -225,7 +225,7 @@ class Order extends Controller { #临时模板 $cardNo = $card['cardNo']; - $cardPwd = $card['cardPwd']; + $cardPwd = $card['cardPwd']??null; $expireTime = $card['expireTime']??''; $template = "== @@ -289,8 +289,8 @@ class Order extends Controller $cards=[ 'cardNo' => $param['kami']['cardno'], - 'cardPwd' => $param['kami']['cardpwd'], - 'expireTime' => $param['kami']['expired'], + 'cardPwd' => $param['kami']['cardpwd']??null, + 'expireTime' => $param['kami']['expired']??null, ]; $param_data['content']=$this->notify_template($param['pid'],$merchant['id'],$merchant_order_id,$cards); diff --git a/app/queue/command/kami91order/KamiOrderChanelNotify.php b/app/queue/command/kami91order/KamiOrderChanelNotify.php index 64e8f1f..ce9742a 100644 --- a/app/queue/command/kami91order/KamiOrderChanelNotify.php +++ b/app/queue/command/kami91order/KamiOrderChanelNotify.php @@ -71,7 +71,7 @@ class KamiOrderChanelNotify extends Command if(isset($response['kami'])) { $cardno = $response['kami']['cardno']; - $cardpwd = $response['kami']['cardpwd']; + $cardpwd = $response['kami']['cardpwd']??null; if(!isset($response['kami']['expired']) || !$response['kami']['expired'] ){ $expire_time = null; }else{ @@ -97,7 +97,7 @@ class KamiOrderChanelNotify extends Command }elseif(isset($vo['channel_callback_msg']) && str_contains($vo['channel_callback_msg'], "kami")){ $msg = json_decode($vo['channel_callback_msg'],true); $cardno = $msg['kami']['cardno']; - $cardpwd = $msg['kami']['cardpwd']; + $cardpwd = $msg['kami']['cardpwd']??null; if(!isset($msg['kami']['expired']) || !$msg['kami']['expired'] ){ $expire_time = null; }else{ @@ -126,8 +126,8 @@ class KamiOrderChanelNotify extends Command }else{ $kami = [ 'cardno' => $info['cardno'], - 'cardpwd' => $info['cardpwd'], - 'expire_time' => $info['expire_time'] + 'cardpwd' => $info['cardpwd']??null, + 'expire_time' => $info['expire_time']??null ]; $where = [ diff --git a/app/queue/command/kami91order/KamiOrderStatusIncorrectSync.php b/app/queue/command/kami91order/KamiOrderStatusIncorrectSync.php index 92eff21..242cf81 100644 --- a/app/queue/command/kami91order/KamiOrderStatusIncorrectSync.php +++ b/app/queue/command/kami91order/KamiOrderStatusIncorrectSync.php @@ -75,8 +75,8 @@ class KamiOrderStatusIncorrectSync extends Command if (isset($response['kami'])) { $upData = [ 'cardno' => $response['kami']['cardno'], - 'cardpwd' => $response['kami']['cardpwd'], - 'expire_time' => $response['kami']['expired'], + 'cardpwd' => $response['kami']['cardpwd']??null, + 'expire_time' => $response['kami']['expired']??null, ]; $upData['order_id'] = $order['order_id']; $upData['status'] = '7'; @@ -99,8 +99,8 @@ class KamiOrderStatusIncorrectSync extends Command if (isset($response['kami'])) { $upData = [ 'cardno' => $response['kami']['cardno'], - 'cardpwd' => $response['kami']['cardpwd'], - 'expire_time' => $response['kami']['expired'], + 'cardpwd' => $response['kami']['cardpwd']??null, + 'expire_time' => $response['kami']['expired']??null, ]; } } diff --git a/app/queue/command/kami91order/KamiOrderStatusSync.php b/app/queue/command/kami91order/KamiOrderStatusSync.php index cbd2ad1..0340e73 100644 --- a/app/queue/command/kami91order/KamiOrderStatusSync.php +++ b/app/queue/command/kami91order/KamiOrderStatusSync.php @@ -72,7 +72,7 @@ class KamiOrderStatusSync extends Command if (isset($response['kami'])) { $upData = [ 'cardno' => $response['kami']['cardno'], - 'cardpwd' => $response['kami']['cardpwd'], + 'cardpwd' => $response['kami']['cardpwd']??null, // 'expire_time' => $response['kami']['expired']??null, 'expire_time' =>null, ]; @@ -97,7 +97,7 @@ class KamiOrderStatusSync extends Command if (isset($response['kami'])) { $upData = [ 'cardno' => $response['kami']['cardno'], - 'cardpwd' => $response['kami']['cardpwd'], + 'cardpwd' => $response['kami']['cardpwd']??null, // 'expire_time' => $response['kami']['expired']??null, 'expire_time' =>null,