From 99caf318c4b87edef0b45be43e14817131bec43d Mon Sep 17 00:00:00 2001 From: mzeros Date: Wed, 25 Dec 2024 14:18:45 +0800 Subject: [PATCH] =?UTF-8?q?feat(openapi):=20=E6=B7=BB=E5=8A=A0=E5=B0=8F?= =?UTF-8?q?=E7=A8=8B=E5=BA=8F=E6=8E=A5=E5=8F=A3=E5=A4=84=E7=90=86=E5=8A=9F?= =?UTF-8?q?=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 新增 MiniProgramsApi 控制器,实现小程序相关的接口处理 - 添加订单查询、运营商查询、产品获取、充值等接口方法 - 实现与快手 API 的交互,包括获取 access_token 等功能 - 优化账户余额查询接口,适配新的 API - 增加渠道余额检查功能 --- app/channel/service/system/Mykjapi.php | 38 ++-- app/core/Service.php | 1 + app/openapi/controller/Coreks.php | 2 + app/openapi/controller/MiniProgramsApi.php | 250 +++++++++++++++++++++ app/openapi/controller/Port.php | 41 ++++ app/order/view/order/index.html | 9 + 6 files changed, 322 insertions(+), 19 deletions(-) create mode 100644 app/openapi/controller/MiniProgramsApi.php diff --git a/app/channel/service/system/Mykjapi.php b/app/channel/service/system/Mykjapi.php index c2e36f4..72a108c 100644 --- a/app/channel/service/system/Mykjapi.php +++ b/app/channel/service/system/Mykjapi.php @@ -50,6 +50,25 @@ class Mykjapi extends Core } + # 查询余额接口 + public function account($day) + { + $request = [ + 'hashcode'=>$this->mid, + ]; + $request['sign'] = md5($this->mid.$this->token.date('Ymd',time())); + $url = $this->host . 'HrmApi/balance'; + $response = $this->curl('post', $url, $request,true); + $response = $this->response($response); + + $datas = $response['array']['errorRes']; + if(is_array($datas) && isset($datas['balance']) && $datas['balance'] ){ + $datas['account'] = $datas['balance']; + } + + return $datas; + } + @@ -89,25 +108,6 @@ class Mykjapi extends Core - # 查询余额接口 - public function account($day) - { -// $request['day'] = $day; -// $request['appid'] = $this->mid; -// $request['version'] = 'v4'; -// $request['product'] = 'query'; -// list($msec, $sec) = explode(' ', microtime()); -// $msectime = (float)sprintf('%.0f', (floatval($msec) + floatval($sec)) * 1000); -// $request['time'] = $msectime; -// $request['nonce'] = substr(sha1(microtime()), rand(10, 15)); -// $request['sign'] = $this->_sign($request); -// $url = $this->host . 'handle/accountByDay'; -// $response = $this->curl('post', $url, $request,true); -// $response = $this->response($response); -// -// return $response['array']['data']; - } - # 提交数据 private function submit($param, $check) { diff --git a/app/core/Service.php b/app/core/Service.php index ad489f0..ee9ecec 100644 --- a/app/core/Service.php +++ b/app/core/Service.php @@ -198,6 +198,7 @@ class Service extends Base $url = 'http://cx.shouji.360.cn/phonearea.php?number=' . $mobile; $data = $this->curl('get', $url); +// var_dump($data); if ($data) { $data = json_decode($data, true); diff --git a/app/openapi/controller/Coreks.php b/app/openapi/controller/Coreks.php index e80b84b..a7a8dff 100644 --- a/app/openapi/controller/Coreks.php +++ b/app/openapi/controller/Coreks.php @@ -486,6 +486,8 @@ class Coreks extends Controller } + + /** * 返回快手下单失败的消息 * @param integer $code diff --git a/app/openapi/controller/MiniProgramsApi.php b/app/openapi/controller/MiniProgramsApi.php new file mode 100644 index 0000000..28df8e2 --- /dev/null +++ b/app/openapi/controller/MiniProgramsApi.php @@ -0,0 +1,250 @@ +get('kuaishou_query'.$merchant_order); + + if($data){ + $data=is_array($data)?$data:json_decode($data,true); + }else{ + $data = $this->getOrder($order, $merchant_order); + + + + } + + if (!$data) { + $ksorderfk = array( + 'result' => '4012002', + 'error_msg' => '订单不存在' + ); + + throw new HttpResponseException(json($ksorderfk)); + } + + $date_str = $data['create_at']; + + $date_time = new \DateTime($date_str, new \DateTimeZone('Asia/Shanghai')); + $iso8601_date = $date_time->format('Y-m-d\TH:i:s\Z'); + + $result = array( + 'result' => '1', + 'error_msg' => '' + ); + $result['data'] = array( + "bizType" => '20', + 'createTime' =>$iso8601_date, + 'mobile' => $data['account'], + 'orderId' => $merchant_order, + + ); + + if ($data['status'] == '2') { + $result['data']['status'] = 'SUCCESS'; + } elseif ($data['status'] == '3') { + $result['data']['status'] = 'FAILED'; + $result['data']['failCode'] = '4013024'; + $result['data']['failMsg'] = '上游通道充值失败'; + } else { + $result['data']['status'] = 'ACCEPTED'; + } + + throw new HttpResponseException(json($result)); + } + + public function getIsp() + { + $data = input(); + if(!isset($data['mobile'])){ + $this->no(-100); + } + + $isp = Service::instance()->ispguishudi($data['mobile']); + $isp_array = [ + '移动'=>1, + '联通'=>2, + '电信'=>3 + ]; + + if(is_array($isp)){ + $response =$isp; + $response['mobile']=$data['mobile']; + $response['isp'] = $isp_array[$isp['sp']]; + $this->yes($response,'ok', 2000); + } + $this->no(-100); + + } + + public function getProduct() + { + $data = input(); + + $response = []; + $response[] = [ + 'isp' => 1, + 'name' => '移动', + 'product_key' => 'ydcz', + 'all_cash' => [ + [ + 'cash' => 100, + 'price' => '98.15', + ], + [ + 'cash' => 200, + 'price' => '196.30', + ], + [ + 'cash' => 300, + 'price' => '294.45', + ], + [ + 'cash' => 500, + 'price' => '492.60', + ], + [ + 'cash' => 50, + 'price' => '50.20', + ], + + ] + ]; + $response[] = [ + 'isp' => 2, + 'name' => '联通', + 'product_key' => 'ltcz', + 'all_cash' => [ + [ + 'cash' => 100, + 'price' => '98.15', + ], + [ + 'cash' => 200, + 'price' => '196.30', + ], + [ + 'cash' => 300, + 'price' => '294.45', + ] + ] + ]; + $response[] = [ + 'isp' => 3, + 'name' => '电信', + 'product_key' => 'dxcz', + 'all_cash' => [ + [ + 'cash' => 100, + 'price' => '98.15', + ], + [ + 'cash' => 200, + 'price' => '196.30', + ], + [ + 'cash' => 300, + 'price' => '294.45', + ] + ] + ]; + $this->yes($response,'ok', 2000); + + } + + # 提交接口 一般用于提交数据,异步执行 + public function charge() + { + + } + + public function test_charge(){ + $this->input_test(); + + + + $settingStatus = sysconf('settingStatus'); + if ($settingStatus == 1) { + $this->noKS(401003); + } + + + + $data = $this->channel($this->mid, $this->product); +// $data = $this->channel($this->mid, $this->product); + var_dump($data); + +// $this->yesks($data,'submit',$this->order); + + } + + # 提交接口 一般用于提交数据,异步执行 + public function dc_charge(): void + { + $this->charge(); + } + + + #code获取 + public function opencode(): void + { + $codeData =$this->request->get(); + + $code = $codeData['code']; +// var_dump($code); + #https://open.kuaishou.com/oauth2/authorize?app_id=ks711568745145555943&redirect_uri=https%3A%2F%2Fcz.njxshy.com%2Fopenapi%2Fkuaishou%2Fopencode&scope=merchant_shop,merchant_funds,merchant_item,merchant_order,merchant_promotion,merchant_user,merchant_refund,user_info,merchant_video,merchant_material,merchant_comment,merchant_logistics&response_type=code + + $url = 'https://openapi.kwaixiaodian.com/oauth2/access_token'; + + + $appid = 'ks711568745145555943'; + $grant_type = 'code'; + $app_secret = 'acvkSeobHEijweCAwhJ5Zw'; + $url = $url.'?app_id='.$appid.'&grant_type='.$grant_type.'&code='.$code.'&app_secret='.$app_secret; +// var_dump($url);die; + +// $response = $this->send_get($url); + $response = http_get($url); +// print_r($response);die; +// var_dump($response);die; + + $responseData = json_decode($response,true); + + $merchant = \app\merchant\service\MerchantService::instance(); + #注意修改 + $mid = '4'; + $update = array( + 'refresh_token' =>$responseData['refresh_token'] + ); + + + $merchant->db()->where(array('id' => $mid))->update($update); + + + } + + +} \ No newline at end of file diff --git a/app/openapi/controller/Port.php b/app/openapi/controller/Port.php index d580e5e..429d156 100644 --- a/app/openapi/controller/Port.php +++ b/app/openapi/controller/Port.php @@ -2,6 +2,7 @@ namespace app\openapi\controller; +use app\channel\service\ChannelService; use think\facade\Db; class Port extends Core @@ -33,6 +34,46 @@ class Port extends Core + } + + public function check_channel_balance() + { + $channel = DB::name('channel_list')->field("id,name,key")->where('status',1)->select(); + if($channel->isEmpty()){ + $this->yes('ok','暂无可用渠道'); + } + + $channelService = ChannelService::instance(); + $day = input('day'); + if (!$day) { + $day = date('Y-m-d', strtotime('-1 day')); + } + $tip_info=[]; + + foreach ($channel->toArray() as $vo){ + try{ + $account_data = $channelService->call('account', $vo['id'], $day); + + if (is_array($account_data) && isset($account_data['account'])) { + $balance = $account_data['account']; + if(1< $balance && $balance < 10000){ + $tip_info[] = $vo['name'].'余额不足,只剩下'.$balance; + } + + } + }catch (\Exception $e){ + + } + + } + if($tip_info && !empty($tip_info)){ + $errorMsg = implode("\n", $tip_info); + $this->no(0 ,$errorMsg); + } + + $this->yes('ok','暂时正常'); + + } #检测异常订单error过期预警 diff --git a/app/order/view/order/index.html b/app/order/view/order/index.html index 0fdb4fe..1c3906e 100644 --- a/app/order/view/order/index.html +++ b/app/order/view/order/index.html @@ -661,6 +661,15 @@