feat(openapi): 添加小程序接口处理功能

- 新增 MiniProgramsApi 控制器,实现小程序相关的接口处理
- 添加订单查询、运营商查询、产品获取、充值等接口方法
- 实现与快手 API 的交互,包括获取 access_token 等功能
- 优化账户余额查询接口,适配新的 API
- 增加渠道余额检查功能
This commit is contained in:
mzeros 2024-12-25 14:18:45 +08:00
parent 6e494e5b86
commit 99caf318c4
6 changed files with 322 additions and 19 deletions

View File

@ -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) private function submit($param, $check)
{ {

View File

@ -198,6 +198,7 @@ class Service extends Base
$url = 'http://cx.shouji.360.cn/phonearea.php?number=' . $mobile; $url = 'http://cx.shouji.360.cn/phonearea.php?number=' . $mobile;
$data = $this->curl('get', $url); $data = $this->curl('get', $url);
// var_dump($data);
if ($data) { if ($data) {
$data = json_decode($data, true); $data = json_decode($data, true);

View File

@ -486,6 +486,8 @@ class Coreks extends Controller
} }
/** /**
* 返回快手下单失败的消息 * 返回快手下单失败的消息
* @param integer $code * @param integer $code

View File

@ -0,0 +1,250 @@
<?php
namespace app\openapi\controller;
use app\core\Service;
use app\gateway\service\RedisService as redisObj;
use app\merchant\service\MerchatMappingProductService;
use think\exception\HttpResponseException;
/**
* 接口处理
* Class Kuaishou
* @package app\gateway\api
*/
class MiniProgramsApi extends Core
{
# 是否检测数据
protected $check = false;
# 查询接口 一般用于查询数据,同步执行
public function query()
{
$data = input();
$order = '';
$query_param = json_decode($data['param'],true);
$merchant_order = $query_param['orderId'];
$redis=new redisObj();
$data= $redis->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);
}
}

View File

@ -2,6 +2,7 @@
namespace app\openapi\controller; namespace app\openapi\controller;
use app\channel\service\ChannelService;
use think\facade\Db; use think\facade\Db;
class Port extends Core 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过期预警 #检测异常订单error过期预警

View File

@ -661,6 +661,15 @@
<style type="text/css"> <style type="text/css">
/*.layui-table-cell {*/
/* !*height: auto;*!*/
/* font-size: 14px;*/
/* !*padding: 0 5px;*!*/
/* !*overflow: visible;*!*/
/* !*text-overflow: inherit;*!*/
/* !*white-space: normal;*!*/
/* !*word-break: break-all;*!*/
/*}*/
/*.layTab{*/ /*.layTab{*/
/* width:auto;*/ /* width:auto;*/
/* ov*/ /* ov*/