From 7fff2e8043b3fce3c4581ee5aef790528873a439 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B2=90?= Date: Tue, 25 Mar 2025 17:38:51 +0800 Subject: [PATCH] =?UTF-8?q?feat(channel):=20=E6=B7=BB=E5=8A=A0=E4=BD=99?= =?UTF-8?q?=E5=88=9D=E7=A7=91=E6=8A=80=E6=B8=A0=E9=81=93=E6=94=AF=E6=8C=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 新增 Yuchu 类实现余初科技渠道的各种功能 - 添加话费直充、订单查询、余额查询等功能 - 实现订单状态通知处理 - 优化数据响应格式处理 --- app/channel/service/system/Yuchu.php | 212 +++++++++++++++++++++++++++ 1 file changed, 212 insertions(+) create mode 100644 app/channel/service/system/Yuchu.php diff --git a/app/channel/service/system/Yuchu.php b/app/channel/service/system/Yuchu.php new file mode 100644 index 0000000..e777ad2 --- /dev/null +++ b/app/channel/service/system/Yuchu.php @@ -0,0 +1,212 @@ + 'Account', + ); + + + $this->api='api/order/SubmitOrder'; + # 判断运营商的方法 + + return $this->submit($param, $check); + } + #dhcz 三网他,ydcz/dxcz/ltcz各个运营商类目,不识别 + + public function ydcz($param) + { + return $this->dhcz($param); + } + public function dxcz($param) + { + return $this->dhcz($param); + } + public function ltcz($param) + { + return $this->dhcz($param); + } + + # 通知处理 主要返回状态 2是成功 3是失败 + public function notify($data) + { + $result = array(); + $result['cash'] = 1; + $result['status'] = 4; + #以上基本不要变 + + + if ($data['OrderStatus'] == 2) { + $result['status'] = 2; + } else if($data['OrderStatus'] == 3) { + $result['status'] = 3; + }else { + $result['status'] = 4; + } + + + if (isset($data['OrderDesc']) && $data['OrderDesc']) { + # 流水号 + $data['s_number'] = $result['s_number'] = $data['OrderDesc']; + } + + $result['yes'] = 'ok'; //响应给上游的数据 + + $result['data'] = $data; + + return $result; + } + public function query($order){ + $request['AgentId'] = $this->mid; + if(isset($order['num']) && $order['num']>0){ + $order_id = $order['order_id'].'_'.$order['num']; + }else{ + $order_id = $order['order_id']; + } + $request['OutOrderId'] = $order_id; + $request['Timestamp'] = date('YmdHis') . sprintf('%03d', round(microtime(true) * 1000) % 1000); // 修正时间戳格式 + $request['Sign'] = $this->_sign($request); + $url = $this->host . 'api/order/QueryOrder'; + $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); + + $result = array(); + $result['status'] = 4; + if ($array['Code']=='00' ) { + #判断平台订单号和订单号是否匹配 + if(isset($order['channel_order_id']) && $order['channel_order_id']){ + if($order['channel_order_id'] != $array['Data']['OrderId']){ + $result['status'] = 4; + return $result; + } + if($array['Data']['OrderStatus'] !=2 && $array['Data']['OrderStatus'] !=3){ + $result['status'] = 4; + return $result; + }else{ + $result = $array['Data']; + $result['status'] = $result['OrderStatus']; + } + } + + + } + + 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 + + + if (!$array) { + $msg = 'error'; + } elseif (isset($array['Code']) && $array['Code']=='00') { //修改判断逻辑为确定提交成功即可 + # 正确 + $msg = 'ok'; + + } else { + # 错误 + $msg = $array['Msg'] ?? 'error'; //前面message根据响应内容改成对应的错误提示 + } + + return array + ( + 'msg' => $msg, + 'data' => $data, + 'array' => $array, + ); + } + + # 查询余额接口 + public function account($day) + { + $request['AgentId'] = $this->mid; + $request['Timestamp'] = date('YmdHis') . sprintf('%03d', round(microtime(true) * 1000) % 1000); // 修正时间戳格式 + $request['Sign'] = $this->_sign($request); + $url = $this->host . 'api/order/QueryAgentYuE'; + $response = $this->curl('post', $url, $request); + $response = $this->response($response); + + $datas = $response['array']['Data']; + if(is_array($datas) && isset($datas['SurplusYuE']) && $datas['SurplusYuE'] ){ + $datas['account'] = $datas['SurplusYuE']; //此处为余额 + } + + 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['AgentId']=$this->mid; + + $request['CallbackUrl']=$this->getNotify($param['order'], 1); //回调方法默认不用改 + $request['OutOrderId']=$param['order']; //我方系统订单号 + $request['ProductId']=$this->getGid($param['cash']); + $request['Timestamp'] = date('YmdHis') . sprintf('%03d', round(microtime(true) * 1000) % 1000); // 修正时间戳格式 + $request['Sign'] = $this->_sign($request); + $url = $this->host . $this->api; //组装地址 + + #该系统提交写法: + + $response = $this->curl('post', $url, $request); + $response = $this->response($response); + $channel_order_id = ''; + + #如果出现响应有上游订单号,可以如下 + if (isset($response["array"]['Data']['OrderId'])) { + $channel_order_id = $response["array"]['Data']['OrderId']; + } + + $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']); + $request['SignKey'] = $this->token; + ksort($request); + $str = ''; + foreach($request as $k=>$v){ + $str.=$k.'='.$v.'&'; + } + $str = rtrim($str,'&'); + return strtolower(md5($str)); + } +} \ No newline at end of file